[hibernate-commits] Hibernate SVN: r10598 - branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Tue Oct 17 17:37:43 EDT 2006
Author: steve.ebersole at jboss.com
Date: 2006-10-17 17:37:42 -0400 (Tue, 17 Oct 2006)
New Revision: 10598
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java
Log:
test in case of versioning + batching
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java 2006-10-17 21:30:03 UTC (rev 10597)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java 2006-10-17 21:37:42 UTC (rev 10598)
@@ -4,13 +4,11 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.hibernate.JDBCException;
import org.hibernate.Session;
import org.hibernate.StaleObjectStateException;
-import org.hibernate.Transaction;
-import org.hibernate.JDBCException;
+import org.hibernate.StaleStateException;
import org.hibernate.dialect.SQLServerDialect;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.Environment;
import org.hibernate.test.TestCase;
/**
@@ -29,11 +27,6 @@
return new String[] { "optlock/Document.hbm.xml" };
}
- protected void configure(Configuration cfg) {
- super.configure( cfg );
- cfg.setProperty( Environment.BATCH_VERSIONED_DATA, "false" );
- }
-
public static Test suite() {
return new TestSuite(OptimisticLockTest.class);
}
@@ -53,25 +46,24 @@
public void testOptimisticLockAllDelete() {
testDeleteOptimisticLockFailure( "LockAll" );
}
-
private void testUpdateOptimisticLockFailure(String entityName) {
- Session s = openSession();
- Transaction t = s.beginTransaction();
+ Session mainSession = openSession();
+ mainSession.beginTransaction();
Document doc = new Document();
doc.setTitle( "Hibernate in Action" );
doc.setAuthor( "Bauer et al" );
doc.setSummary( "Very boring book about persistence" );
doc.setText( "blah blah yada yada yada" );
doc.setPubDate( new PublicationDate( 2004 ) );
- s.save( entityName, doc );
- t.commit();
- s.close();
+ mainSession.save( entityName, doc );
+ mainSession.getTransaction().commit();
+ mainSession.close();
- s = openSession();
- t = s.beginTransaction();
- doc = ( Document ) s.get( entityName, doc.getId() );
+ mainSession = openSession();
+ mainSession.beginTransaction();
+ doc = ( Document ) mainSession.get( entityName, doc.getId() );
- Session otherSession = openSession();
+ Session otherSession = getSessions().openSession();
otherSession.beginTransaction();
Document otherDoc = ( Document ) otherSession.get( entityName, doc.getId() );
otherDoc.setSummary( "A modern classic" );
@@ -80,12 +72,15 @@
try {
doc.setSummary( "A machiavelian achievement of epic proportions" );
- s.flush();
+ mainSession.flush();
fail( "expecting opt lock failure" );
}
catch ( StaleObjectStateException expected ) {
// expected result...
}
+ catch( StaleStateException expected ) {
+ // expected result (if using versioned batching)...
+ }
catch( JDBCException e ) {
// SQLServer will report this condition via a SQLException
// when using its SNAPSHOT transaction isolation...
@@ -94,60 +89,63 @@
}
else {
// it seems to "lose track" of the transaction as well...
- t.rollback();
- t = s.beginTransaction();
+ mainSession.getTransaction().rollback();
+ mainSession.beginTransaction();
}
}
- s.clear();
- t.commit();
- s.close();
+ mainSession.clear();
+ mainSession.getTransaction().commit();
+ mainSession.close();
- s = openSession();
- t = s.beginTransaction();
- doc = ( Document ) s.load( entityName, doc.getId() );
- s.delete( entityName, doc );
- t.commit();
- s.close();
+ mainSession = openSession();
+ mainSession.beginTransaction();
+ doc = ( Document ) mainSession.load( entityName, doc.getId() );
+ mainSession.delete( entityName, doc );
+ mainSession.getTransaction().commit();
+ mainSession.close();
}
private void testDeleteOptimisticLockFailure(String entityName) {
- Session s = openSession();
- Transaction t = s.beginTransaction();
+ Session mainSession = openSession();
+ mainSession.beginTransaction();
Document doc = new Document();
doc.setTitle( "Hibernate in Action" );
doc.setAuthor( "Bauer et al" );
doc.setSummary( "Very boring book about persistence" );
doc.setText( "blah blah yada yada yada" );
doc.setPubDate( new PublicationDate( 2004 ) );
- s.save( entityName, doc );
- s.flush();
+ mainSession.save( entityName, doc );
+ mainSession.flush();
doc.setSummary( "A modern classic" );
- s.flush();
+ mainSession.flush();
doc.getPubDate().setMonth( new Integer( 3 ) );
- s.flush();
- t.commit();
- s.close();
+ mainSession.flush();
+ mainSession.getTransaction().commit();
+ mainSession.close();
- s = openSession();
- t = s.beginTransaction();
- doc = ( Document ) s.get( entityName, doc.getId() );
+ mainSession = openSession();
+ mainSession.beginTransaction();
+ doc = ( Document ) mainSession.get( entityName, doc.getId() );
- Session other = openSession();
- Transaction othert = other.beginTransaction();
- Document otherDoc = ( Document ) other.get( entityName, doc.getId() );
+ Session otherSession = openSession();
+ otherSession.beginTransaction();
+ Document otherDoc = ( Document ) otherSession.get( entityName, doc.getId() );
otherDoc.setSummary( "my other summary" );
- other.flush();
- othert.commit();
- other.close();
+ otherSession.flush();
+ otherSession.getTransaction().commit();
+ otherSession.close();
try {
- s.delete( doc );
- s.flush();
+ mainSession.delete( doc );
+ mainSession.flush();
fail( "expecting opt lock failure" );
}
catch ( StaleObjectStateException e ) {
// expected
}
+ catch( StaleStateException expected ) {
+ // expected result (if using versioned batching)...
+ }
catch( JDBCException e ) {
// SQLServer will report this condition via a SQLException
// when using its SNAPSHOT transaction isolation...
@@ -156,20 +154,20 @@
}
else {
// it seems to "lose track" of the transaction as well...
- t.rollback();
- t = s.beginTransaction();
+ mainSession.getTransaction().rollback();
+ mainSession.beginTransaction();
}
}
- s.clear();
- t.commit();
- s.close();
+ mainSession.clear();
+ mainSession.getTransaction().commit();
+ mainSession.close();
- s = openSession();
- t = s.beginTransaction();
- doc = ( Document ) s.load( entityName, doc.getId() );
- s.delete( entityName, doc );
- t.commit();
- s.close();
+ mainSession = openSession();
+ mainSession.beginTransaction();
+ doc = ( Document ) mainSession.load( entityName, doc.getId() );
+ mainSession.delete( entityName, doc );
+ mainSession.getTransaction().commit();
+ mainSession.close();
}
}
More information about the hibernate-commits
mailing list