【Java开源代码栏目提醒】:网学会员在Java开源代码频道为大家收集整理了TimestampGeneratedValuesWithCachingTest.java提供大家参考,希望对大家有所帮助!
// $Id: TimestampGeneratedValuesWithCachingTest.java 9014 2006-01-10 23:04:27Z steveebersole $
package org.hibernate.test.generated;
import java.sql.SQLWarning;
import java.sql.Statement;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.dialect.SybaseDialect;
import org.hibernate.dialect.Dialect;
import junit.framework.TestSuite;
import junit.framework.Test;
/**
* Implementation of TimestampGeneratedValuesWithCachingTest.
*
* @author Steve Ebersole
*/
public class TimestampGeneratedValuesWithCachingTest extends AbstractGeneratedPropertyTest {
public TimestampGeneratedValuesWithCachingTest(String x) {
super( x );
}
public boolean appliesTo(Dialect dialect) {
// this test is specific to Sybase/SQLServer as it is testing support
// for their TIMESTAMP datatype...
return ( dialect instanceof SybaseDialect );
}
protected void afterSessionFactoryBuilt() throws Exception {
// alter the table column to be of type TIMESTAMP, instead of the normal
// BINARY/VARBINARY type-mapping.
Session s = openSession();
Statement stmnt = s.connection().createStatement();
stmnt.execute( "alter table gen_prop drop column lastModified" );
SQLWarning warning = stmnt.getWarnings();
if ( warning != null ) {
stmnt.clearWarnings();
throw new HibernateException( "could not drop lastModified column : " + warning );
}
stmnt.execute( "alter table gen_prop add lastModified TIMESTAMP NOT NULL" );
warning = stmnt.getWarnings();
if ( warning != null ) {
stmnt.clearWarnings();
throw new HibernateException( "could not re-create lastModified column as TIMESTAMP type : " + warning );
}
stmnt.close();
s.close();
}
public static Test suite() {
return new TestSuite( TimestampGeneratedValuesWithCachingTest.class );
}
}