[hibernate-commits] Hibernate SVN: r11527 - in trunk/Hibernate3: test/org/hibernate/test/jpa/lock and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue May 15 16:16:50 EDT 2007


Author: epbernard
Date: 2007-05-15 16:16:50 -0400 (Tue, 15 May 2007)
New Revision: 11527

Modified:
   trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java
   trunk/Hibernate3/test/org/hibernate/test/jpa/lock/JPALockTest.java
Log:
HHH-2613 support LockMode.FORCE on non-versioned entity

Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java	2007-05-15 20:15:58 UTC (rev 11526)
+++ trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java	2007-05-15 20:16:50 UTC (rev 11527)
@@ -1314,7 +1314,7 @@
 		lockers.put( LockMode.READ, generateLocker( LockMode.READ ) );
 		lockers.put( LockMode.UPGRADE, generateLocker( LockMode.UPGRADE ) );
 		lockers.put( LockMode.UPGRADE_NOWAIT, generateLocker( LockMode.UPGRADE_NOWAIT ) );
-		//lockers.put( LockMode.FORCE, generateLocker( LockMode.FORCE ) );
+		lockers.put( LockMode.FORCE, generateLocker( LockMode.FORCE ) );
 	}
 
 	protected LockingStrategy generateLocker(LockMode lockMode) {

Modified: trunk/Hibernate3/test/org/hibernate/test/jpa/lock/JPALockTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/jpa/lock/JPALockTest.java	2007-05-15 20:15:58 UTC (rev 11526)
+++ trunk/Hibernate3/test/org/hibernate/test/jpa/lock/JPALockTest.java	2007-05-15 20:16:50 UTC (rev 11527)
@@ -8,6 +8,7 @@
 import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
 import org.hibernate.test.jpa.AbstractJPATest;
 import org.hibernate.test.jpa.Item;
+import org.hibernate.test.jpa.MyEntity;
 
 /**
  * Tests specifically relating to section 3.3.5.3 [Lock Modes] of the
@@ -45,7 +46,7 @@
 	 * is permissible.
 	 * <p/>
 	 * The persistence implementation is not required to support calling lock(entity, LockMode-Type.READ)
-	 *  on a non-versioned object. When it cannot support such a lock call, it must throw the
+	 * on a non-versioned object. When it cannot support such a lock call, it must throw the
 	 * PersistenceException. When supported, whether for versioned or non-versioned objects, LockMode-Type.READ
 	 * must always prevent the phenomena P1 and P2. Applications that call lock(entity, LockModeType.READ)
 	 * on non-versioned objects will not be portable.
@@ -53,11 +54,11 @@
 	 * Odd as it may sound, EJB3 LockModeType.READ actually maps to the Hibernate LockMode.UPGRADE
 	 */
 	public void testLockModeTypeRead() {
-		if ( ! readCommittedIsolationMaintained( "ejb3 lock tests" ) ) {
+		if ( !readCommittedIsolationMaintained( "ejb3 lock tests" ) ) {
 			return;
 		}
-		if(getDialect().doesReadCommittedCauseWritersToBlockReaders()) {
-			reportSkip("deadlock", "jpa read locking");
+		if ( getDialect().doesReadCommittedCauseWritersToBlockReaders() ) {
+			reportSkip( "deadlock", "jpa read locking" );
 			return;
 		}
 
@@ -76,20 +77,20 @@
 		// perform the isolated update
 		s1 = getSessions().openSession();
 		t1 = s1.beginTransaction();
-		item = ( Item ) s1.get( Item.class, itemId );
+		item = (Item) s1.get( Item.class, itemId );
 		s1.lock( item, LockMode.UPGRADE );
 		item.setName( "updated" );
 		s1.flush();
 
 		Session s2 = getSessions().openSession();
 		Transaction t2 = s2.beginTransaction();
-		Item item2 = ( Item ) s2.get( Item.class, itemId );
+		Item item2 = (Item) s2.get( Item.class, itemId );
 		assertEquals( "isolation not maintained", initialName, item2.getName() );
 
 		t1.commit();
 		s1.close();
 
-		item2 = ( Item ) s2.get( Item.class, itemId );
+		item2 = (Item) s2.get( Item.class, itemId );
 		assertEquals( "repeatable read not maintained", initialName, item2.getName() );
 		t2.commit();
 		s2.close();
@@ -124,11 +125,11 @@
 	 * a new Hibernate LockMode was added to support this behavior: {@link org.hibernate.LockMode#FORCE}.
 	 */
 	public void testLockModeTypeWrite() {
-		if ( ! readCommittedIsolationMaintained( "ejb3 lock tests" ) ) {
+		if ( !readCommittedIsolationMaintained( "ejb3 lock tests" ) ) {
 			return;
 		}
-		if(getDialect().doesReadCommittedCauseWritersToBlockReaders()) {
-			reportSkip("deadlock", "jpa write locking");
+		if ( getDialect().doesReadCommittedCauseWritersToBlockReaders() ) {
+			reportSkip( "deadlock", "jpa write locking" );
 			return;
 		}
 		final String initialName = "lock test";
@@ -138,6 +139,9 @@
 		Item item = new Item();
 		item.setName( initialName );
 		s1.save( item );
+		MyEntity myEntity = new MyEntity();
+		myEntity.setName( "Test" );
+		s1.save( myEntity );
 		t1.commit();
 		s1.close();
 
@@ -146,16 +150,20 @@
 
 		s1 = getSessions().openSession();
 		t1 = s1.beginTransaction();
-		item = ( Item ) s1.get( Item.class, itemId );
+		item = (Item) s1.get( Item.class, itemId );
 		s1.lock( item, LockMode.FORCE );
 		assertEquals( "no forced version increment", initialVersion + 1, item.getVersion() );
 
+		myEntity = (MyEntity) s1.get( MyEntity.class, myEntity.getId() );
+		s1.lock( myEntity, LockMode.FORCE );
+		assertTrue( "LockMode.FORCE on a unversioned entity should degrade nicely to UPGRADE", true );
+
 		s1.lock( item, LockMode.FORCE );
 		assertEquals( "subsequent LockMode.FORCE did not no-op", initialVersion + 1, item.getVersion() );
 
 		Session s2 = getSessions().openSession();
 		Transaction t2 = s2.beginTransaction();
-		Item item2 = ( Item ) s2.get( Item.class, itemId );
+		Item item2 = (Item) s2.get( Item.class, itemId );
 		assertEquals( "isolation not maintained", initialName, item2.getName() );
 
 		item.setName( "updated-1" );
@@ -171,7 +179,7 @@
 			t2.commit();
 			fail( "optimisitc lock should have failed" );
 		}
-		catch( Throwable ignore ) {
+		catch (Throwable ignore) {
 			// expected behavior
 			t2.rollback();
 		}
@@ -182,6 +190,7 @@
 		s1 = getSessions().openSession();
 		t1 = s1.beginTransaction();
 		s1.delete( item );
+		s1.delete( myEntity );
 		t1.commit();
 		s1.close();
 	}




More information about the hibernate-commits mailing list