[hibernate-commits] Hibernate SVN: r15167 - core/branches/Branch_3_3/core/src/main/java/org/hibernate/context.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Sep 9 17:27:12 EDT 2008


Author: steve.ebersole at jboss.com
Date: 2008-09-09 17:27:11 -0400 (Tue, 09 Sep 2008)
New Revision: 15167

Modified:
   core/branches/Branch_3_3/core/src/main/java/org/hibernate/context/JTASessionContext.java
Log:
HHH-3472 : WebSphere + JTASessionContext

Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/context/JTASessionContext.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/context/JTASessionContext.java	2008-09-09 19:22:59 UTC (rev 15166)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/context/JTASessionContext.java	2008-09-09 21:27:11 UTC (rev 15167)
@@ -101,13 +101,17 @@
 			throw new HibernateException( "Problem locating/validating JTA transaction", t );
 		}
 
-		Session currentSession = ( Session ) currentSessionMap.get( txn );
+		final Object txnIdentifier = factory.getSettings().getTransactionManagerLookup() == null
+				? txn
+				: factory.getSettings().getTransactionManagerLookup().getTransactionIdentifier( txn );
 
+		Session currentSession = ( Session ) currentSessionMap.get( txnIdentifier );
+
 		if ( currentSession == null ) {
 			currentSession = buildOrObtainSession();
 
 			try {
-				txn.registerSynchronization( buildCleanupSynch( txn ) );
+				txn.registerSynchronization( buildCleanupSynch( txnIdentifier ) );
 			}
 			catch ( Throwable t ) {
 				try {
@@ -119,17 +123,21 @@
 				throw new HibernateException( "Unable to register cleanup Synchronization with TransactionManager" );
 			}
 
-			Object txnIdentifier = factory.getSettings().getTransactionManagerLookup() == null
-					? txn
-					: factory.getSettings().getTransactionManagerLookup().getTransactionIdentifier( txn );
 			currentSessionMap.put( txnIdentifier, currentSession );
 		}
 
 		return currentSession;
 	}
 
-	private CleanupSynch buildCleanupSynch(Transaction txn) {
-		return new CleanupSynch( txn, this );
+	/**
+	 * Builds a {@link CleanupSynch} capable of cleaning up the the current session map as an after transaction
+	 * callback.
+	 *
+	 * @param transactionIdentifier The transaction identifier under which the current session is registered.
+	 * @return The cleanup synch.
+	 */
+	private CleanupSynch buildCleanupSynch(Object transactionIdentifier) {
+		return new CleanupSynch( transactionIdentifier, this );
 	}
 
 	/**
@@ -180,11 +188,11 @@
 	 * JTA transaction synch used for cleanup of the internal session map.
 	 */
 	protected static class CleanupSynch implements Synchronization {
-		private Transaction txn;
+		private Object transactionIdentifier;
 		private JTASessionContext context;
 
-		public CleanupSynch(Transaction txn, JTASessionContext context) {
-			this.txn = txn;
+		public CleanupSynch(Object transactionIdentifier, JTASessionContext context) {
+			this.transactionIdentifier = transactionIdentifier;
 			this.context = context;
 		}
 
@@ -198,7 +206,7 @@
 		 * {@inheritDoc}
 		 */
 		public void afterCompletion(int i) {
-			context.currentSessionMap.remove( txn );
+			context.currentSessionMap.remove( transactionIdentifier );
 		}
 	}
 }




More information about the hibernate-commits mailing list