Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/hibernate/test/generatedkeys/seqidentity/SequenceIdentityTest.java


1   package org.hibernate.test.generatedkeys.seqidentity;
2   
3   import org.hibernate.test.DatabaseSpecificTestCase;
4   import org.hibernate.Session;
5   import org.hibernate.cfg.Configuration;
6   import org.hibernate.dialect.Oracle9Dialect;
7   import org.hibernate.dialect.Dialect;
8   import org.hibernate.dialect.DataDirectOracle9Dialect;
9   import junit.framework.Test;
10  import junit.framework.TestSuite;
11  
12  /**
13   * @author Steve Ebersole
14   */
15  public class SequenceIdentityTest extends DatabaseSpecificTestCase {
16    public SequenceIdentityTest(String x) {
17      super( x );
18    }
19  
20    protected void configure(Configuration cfg) {
21      super.configure( cfg );
22    }
23  
24    public boolean appliesTo(Dialect dialect) {
25      // the DataDirect driver for Oracle known to not support
26      // JDBC3 getGeneratedKeys...
27      return ( dialect instanceof Oracle9Dialect ) && ( ! ( dialect instanceof DataDirectOracle9Dialect ) ) ;
28    }
29  
30    protected String[] getMappings() {
31      return new String[] {
32          "generatedkeys/seqidentity/MyEntity.hbm.xml"
33      };
34    }
35  
36    public static Test suite() {
37      return new TestSuite( SequenceIdentityTest.class );
38    }
39  
40    public void testSequenceIdentityGenerator() {
41      Session session = openSession();
42      session.beginTransaction();
43  
44      MyEntity e = new MyEntity( "entity-1" );
45      session.save( e );
46  
47      // this insert should happen immediately!
48      assertEquals( "id not generated through forced insertion", new Long(1), e.getId() );
49  
50      session.delete( e );
51      session.getTransaction().commit();
52      session.close();
53    }
54  }