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

Quick Search    Search Deep

Source code: org/hibernate/test/generated/TimestampGeneratedValuesWithCachingTest.java


1   // $Id: TimestampGeneratedValuesWithCachingTest.java 9014 2006-01-10 23:04:27Z steveebersole $
2   package org.hibernate.test.generated;
3   
4   import java.sql.SQLWarning;
5   import java.sql.Statement;
6   
7   import org.hibernate.HibernateException;
8   import org.hibernate.Session;
9   import org.hibernate.dialect.SybaseDialect;
10  import org.hibernate.dialect.Dialect;
11  
12  import junit.framework.TestSuite;
13  import junit.framework.Test;
14  
15  /**
16   * Implementation of TimestampGeneratedValuesWithCachingTest.
17   *
18   * @author Steve Ebersole
19   */
20  public class TimestampGeneratedValuesWithCachingTest extends AbstractGeneratedPropertyTest {
21  
22    public TimestampGeneratedValuesWithCachingTest(String x) {
23      super( x );
24    }
25  
26    public boolean appliesTo(Dialect dialect) {
27      // this test is specific to Sybase/SQLServer as it is testing support
28      // for their TIMESTAMP datatype...
29      return ( dialect instanceof SybaseDialect );
30    }
31  
32    protected void afterSessionFactoryBuilt() throws Exception {
33      // alter the table column to be of type TIMESTAMP, instead of the normal
34      // BINARY/VARBINARY type-mapping.
35      Session s = openSession();
36      Statement stmnt = s.connection().createStatement();
37      stmnt.execute( "alter table gen_prop drop column lastModified" );
38      SQLWarning warning = stmnt.getWarnings();
39      if ( warning != null ) {
40        stmnt.clearWarnings();
41        throw new HibernateException( "could not drop lastModified column : " + warning );
42      }
43      stmnt.execute( "alter table gen_prop add lastModified TIMESTAMP NOT NULL" );
44      warning = stmnt.getWarnings();
45      if ( warning != null ) {
46        stmnt.clearWarnings();
47        throw new HibernateException( "could not re-create lastModified column as TIMESTAMP type : " + warning );
48      }
49      stmnt.close();
50      s.close();
51    }
52  
53    public static Test suite() {
54      return new TestSuite( TimestampGeneratedValuesWithCachingTest.class );
55    }
56  }