HHH-3472 : WebSphere + JTASessionContext

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@15168 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2008-09-09 21:27:28 +00:00
parent a0c14fe192
commit 7b3e4824e8
1 changed files with 19 additions and 11 deletions

View File

@ -101,13 +101,17 @@ public class JTASessionContext implements CurrentSessionContext {
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 @@ public class JTASessionContext implements CurrentSessionContext {
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 @@ public class JTASessionContext implements CurrentSessionContext {
* 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 @@ public class JTASessionContext implements CurrentSessionContext {
* {@inheritDoc}
*/
public void afterCompletion(int i) {
context.currentSessionMap.remove( txn );
context.currentSessionMap.remove( transactionIdentifier );
}
}
}