HHH-6164 - Prefer regsitering JTA syncs via TransactionManager

This commit is contained in:
Steve Ebersole 2011-04-29 09:54:51 -05:00
parent 5f607c6b9f
commit 627b4ea6a1
17 changed files with 7 additions and 115 deletions

View File

@ -48,6 +48,8 @@ public abstract class AbstractJtaPlatform
private boolean cacheUserTransaction; private boolean cacheUserTransaction;
private ServiceRegistryImplementor serviceRegistry; private ServiceRegistryImplementor serviceRegistry;
private final JtaSynchronizationStrategy tmSynchronizationStrategy = new TransactionManagerBasedSynchronizationStrategy( this );
@Override @Override
public void injectServices(ServiceRegistryImplementor serviceRegistry) { public void injectServices(ServiceRegistryImplementor serviceRegistry) {
this.serviceRegistry = serviceRegistry; this.serviceRegistry = serviceRegistry;
@ -116,7 +118,9 @@ public abstract class AbstractJtaPlatform
return transaction; return transaction;
} }
protected abstract JtaSynchronizationStrategy getSynchronizationStrategy(); protected JtaSynchronizationStrategy getSynchronizationStrategy() {
return tmSynchronizationStrategy;
}
@Override @Override
public void registerSynchronization(Synchronization synchronization) { public void registerSynchronization(Synchronization synchronization) {

View File

@ -35,13 +35,6 @@ import org.hibernate.service.jta.platform.spi.JtaPlatformException;
public class BitronixJtaPlatform extends AbstractJtaPlatform { public class BitronixJtaPlatform extends AbstractJtaPlatform {
private static final String TM_CLASS_NAME = "bitronix.tm.TransactionManagerServices"; private static final String TM_CLASS_NAME = "bitronix.tm.TransactionManagerServices";
private final JtaSynchronizationStrategy synchronizationStrategy = new TransactionManagerBasedSynchronizationStrategy( this );
@Override
protected JtaSynchronizationStrategy getSynchronizationStrategy() {
return synchronizationStrategy;
}
@Override @Override
protected TransactionManager locateTransactionManager() { protected TransactionManager locateTransactionManager() {
try { try {

View File

@ -33,8 +33,6 @@ public class BorlandEnterpriseServerJtaPlatform extends AbstractJtaPlatform {
protected static final String TM_NAME = "java:pm/TransactionManager"; protected static final String TM_NAME = "java:pm/TransactionManager";
protected static final String UT_NAME = "java:comp/UserTransaction"; protected static final String UT_NAME = "java:comp/UserTransaction";
private final JtaSynchronizationStrategy synchronizationStrategy = new TransactionManagerBasedSynchronizationStrategy( this );
@Override @Override
protected TransactionManager locateTransactionManager() { protected TransactionManager locateTransactionManager() {
return (TransactionManager) jndiService().locate( TM_NAME ); return (TransactionManager) jndiService().locate( TM_NAME );
@ -44,9 +42,4 @@ public class BorlandEnterpriseServerJtaPlatform extends AbstractJtaPlatform {
protected UserTransaction locateUserTransaction() { protected UserTransaction locateUserTransaction() {
return (UserTransaction) jndiService().locate( UT_NAME ); return (UserTransaction) jndiService().locate( UT_NAME );
} }
@Override
protected JtaSynchronizationStrategy getSynchronizationStrategy() {
return synchronizationStrategy;
}
} }

View File

@ -24,7 +24,6 @@
package org.hibernate.service.jta.platform.internal; package org.hibernate.service.jta.platform.internal;
import javax.transaction.TransactionManager; import javax.transaction.TransactionManager;
import javax.transaction.TransactionSynchronizationRegistry;
import javax.transaction.UserTransaction; import javax.transaction.UserTransaction;
/** /**
@ -32,12 +31,10 @@ import javax.transaction.UserTransaction;
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class JBossAppServerPlatform extends AbstractJtaPlatform implements SynchronizationRegistryAccess { public class JBossAppServerJtaPlatform extends AbstractJtaPlatform {
public static final String TM_NAME = "java:/TransactionManager"; public static final String TM_NAME = "java:/TransactionManager";
public static final String UT_NAME = "UserTransaction"; public static final String UT_NAME = "UserTransaction";
public static final String REG_NAME = "java:comp/TransactionSynchronizationRegistry";
private final JtaSynchronizationStrategy synchronizationStrategy = new SynchronizationRegistryBasedSynchronizationStrategy( this );
@Override @Override
protected TransactionManager locateTransactionManager() { protected TransactionManager locateTransactionManager() {
return (TransactionManager) jndiService().locate( TM_NAME ); return (TransactionManager) jndiService().locate( TM_NAME );
@ -47,14 +44,4 @@ public class JBossAppServerPlatform extends AbstractJtaPlatform implements Synch
protected UserTransaction locateUserTransaction() { protected UserTransaction locateUserTransaction() {
return (UserTransaction) jndiService().locate( UT_NAME ); return (UserTransaction) jndiService().locate( UT_NAME );
} }
@Override
protected JtaSynchronizationStrategy getSynchronizationStrategy() {
return synchronizationStrategy;
}
@Override
public TransactionSynchronizationRegistry getSynchronizationRegistry() {
return (TransactionSynchronizationRegistry) jndiService().locate( REG_NAME );
}
} }

View File

@ -40,8 +40,6 @@ public class JBossStandAloneJtaPlatform extends AbstractJtaPlatform {
private static final String JBOSS_TM_CLASS_NAME = "com.arjuna.ats.jta.TransactionManager"; private static final String JBOSS_TM_CLASS_NAME = "com.arjuna.ats.jta.TransactionManager";
private static final String JBOSS_UT_CLASS_NAME = "com.arjuna.ats.jta.UserTransaction"; private static final String JBOSS_UT_CLASS_NAME = "com.arjuna.ats.jta.UserTransaction";
private final JtaSynchronizationStrategy synchronizationStrategy = new TransactionManagerBasedSynchronizationStrategy( this );
@Override @Override
protected TransactionManager locateTransactionManager() { protected TransactionManager locateTransactionManager() {
try { try {
@ -67,9 +65,4 @@ public class JBossStandAloneJtaPlatform extends AbstractJtaPlatform {
throw new JtaPlatformException( "Could not obtain JBoss Transactions user transaction instance", e ); throw new JtaPlatformException( "Could not obtain JBoss Transactions user transaction instance", e );
} }
} }
@Override
protected JtaSynchronizationStrategy getSynchronizationStrategy() {
return synchronizationStrategy;
}
} }

View File

@ -37,8 +37,6 @@ public class JOTMJtaPlatform extends AbstractJtaPlatform {
public static final String TM_CLASS_NAME = "org.objectweb.jotm.Current"; public static final String TM_CLASS_NAME = "org.objectweb.jotm.Current";
public static final String UT_NAME = "java:comp/UserTransaction"; public static final String UT_NAME = "java:comp/UserTransaction";
private final JtaSynchronizationStrategy synchronizationStrategy = new TransactionManagerBasedSynchronizationStrategy( this );
@Override @Override
protected TransactionManager locateTransactionManager() { protected TransactionManager locateTransactionManager() {
try { try {
@ -55,9 +53,4 @@ public class JOTMJtaPlatform extends AbstractJtaPlatform {
protected UserTransaction locateUserTransaction() { protected UserTransaction locateUserTransaction() {
return (UserTransaction) jndiService().locate( UT_NAME ); return (UserTransaction) jndiService().locate( UT_NAME );
} }
@Override
protected JtaSynchronizationStrategy getSynchronizationStrategy() {
return synchronizationStrategy;
}
} }

View File

@ -37,8 +37,6 @@ public class JOnASJtaPlatform extends AbstractJtaPlatform {
public static final String UT_NAME = "java:comp/UserTransaction"; public static final String UT_NAME = "java:comp/UserTransaction";
private static final String TM_CLASS_NAME = "org.objectweb.jonas_tm.Current"; private static final String TM_CLASS_NAME = "org.objectweb.jonas_tm.Current";
private final JtaSynchronizationStrategy synchronizationStrategy = new TransactionManagerBasedSynchronizationStrategy( this );
@Override @Override
protected TransactionManager locateTransactionManager() { protected TransactionManager locateTransactionManager() {
try { try {
@ -55,9 +53,4 @@ public class JOnASJtaPlatform extends AbstractJtaPlatform {
protected UserTransaction locateUserTransaction() { protected UserTransaction locateUserTransaction() {
return (UserTransaction) jndiService().locate( UT_NAME ); return (UserTransaction) jndiService().locate( UT_NAME );
} }
@Override
protected JtaSynchronizationStrategy getSynchronizationStrategy() {
return synchronizationStrategy;
}
} }

View File

@ -36,8 +36,6 @@ public class JRun4JtaPlatform extends AbstractJtaPlatform {
public static final String TM_NAME = "java:/TransactionManager"; public static final String TM_NAME = "java:/TransactionManager";
public static final String UT_NAME = "java:comp/UserTransaction"; public static final String UT_NAME = "java:comp/UserTransaction";
private final JtaSynchronizationStrategy synchronizationStrategy = new TransactionManagerBasedSynchronizationStrategy( this );
@Override @Override
protected TransactionManager locateTransactionManager() { protected TransactionManager locateTransactionManager() {
return (TransactionManager) jndiService().locate( TM_NAME ); return (TransactionManager) jndiService().locate( TM_NAME );
@ -47,9 +45,4 @@ public class JRun4JtaPlatform extends AbstractJtaPlatform {
protected UserTransaction locateUserTransaction() { protected UserTransaction locateUserTransaction() {
return (UserTransaction) jndiService().locate( UT_NAME ); return (UserTransaction) jndiService().locate( UT_NAME );
} }
@Override
protected JtaSynchronizationStrategy getSynchronizationStrategy() {
return synchronizationStrategy;
}
} }

View File

@ -122,7 +122,7 @@ public class JtaPlatformInitiator implements BasicServiceInitiator<JtaPlatform>
} }
if ( "org.hibernate.transaction.JBossTransactionManagerLookup".equals( tmlImplName ) ) { if ( "org.hibernate.transaction.JBossTransactionManagerLookup".equals( tmlImplName ) ) {
return new JBossAppServerPlatform(); return new JBossAppServerJtaPlatform();
} }
if ( "org.hibernate.transaction.JBossTSStandaloneTransactionManagerLookup".equals( tmlImplName ) ) { if ( "org.hibernate.transaction.JBossTSStandaloneTransactionManagerLookup".equals( tmlImplName ) ) {

View File

@ -36,8 +36,6 @@ public class OC4JJtaPlatform extends AbstractJtaPlatform {
public static final String TM_NAME = "java:comp/pm/TransactionManager"; public static final String TM_NAME = "java:comp/pm/TransactionManager";
public static final String UT_NAME = "java:comp/UserTransaction"; public static final String UT_NAME = "java:comp/UserTransaction";
private final JtaSynchronizationStrategy synchronizationStrategy = new TransactionManagerBasedSynchronizationStrategy( this );
@Override @Override
protected TransactionManager locateTransactionManager() { protected TransactionManager locateTransactionManager() {
return (TransactionManager) jndiService().locate( TM_NAME ); return (TransactionManager) jndiService().locate( TM_NAME );
@ -47,9 +45,4 @@ public class OC4JJtaPlatform extends AbstractJtaPlatform {
protected UserTransaction locateUserTransaction() { protected UserTransaction locateUserTransaction() {
return (UserTransaction) jndiService().locate( UT_NAME ); return (UserTransaction) jndiService().locate( UT_NAME );
} }
@Override
protected JtaSynchronizationStrategy getSynchronizationStrategy() {
return synchronizationStrategy;
}
} }

View File

@ -36,8 +36,6 @@ public class OrionJtaPlatform extends AbstractJtaPlatform {
public static final String TM_NAME = "java:comp/UserTransaction"; public static final String TM_NAME = "java:comp/UserTransaction";
public static final String UT_NAME = "java:comp/UserTransaction"; public static final String UT_NAME = "java:comp/UserTransaction";
private final JtaSynchronizationStrategy synchronizationStrategy = new TransactionManagerBasedSynchronizationStrategy( this );
@Override @Override
protected TransactionManager locateTransactionManager() { protected TransactionManager locateTransactionManager() {
return (TransactionManager) jndiService().locate( TM_NAME ); return (TransactionManager) jndiService().locate( TM_NAME );
@ -47,9 +45,4 @@ public class OrionJtaPlatform extends AbstractJtaPlatform {
protected UserTransaction locateUserTransaction() { protected UserTransaction locateUserTransaction() {
return (UserTransaction) jndiService().locate( UT_NAME ); return (UserTransaction) jndiService().locate( UT_NAME );
} }
@Override
protected JtaSynchronizationStrategy getSynchronizationStrategy() {
return synchronizationStrategy;
}
} }

View File

@ -36,8 +36,6 @@ public class ResinJtaPlatform extends AbstractJtaPlatform {
public static final String TM_NAME = "java:comp/TransactionManager"; public static final String TM_NAME = "java:comp/TransactionManager";
public static final String UT_NAME = "java:comp/UserTransaction"; public static final String UT_NAME = "java:comp/UserTransaction";
private final JtaSynchronizationStrategy synchronizationStrategy = new TransactionManagerBasedSynchronizationStrategy( this );
@Override @Override
protected TransactionManager locateTransactionManager() { protected TransactionManager locateTransactionManager() {
return (TransactionManager) jndiService().locate( TM_NAME ); return (TransactionManager) jndiService().locate( TM_NAME );
@ -47,9 +45,4 @@ public class ResinJtaPlatform extends AbstractJtaPlatform {
protected UserTransaction locateUserTransaction() { protected UserTransaction locateUserTransaction() {
return (UserTransaction) jndiService().locate( UT_NAME ); return (UserTransaction) jndiService().locate( UT_NAME );
} }
@Override
protected JtaSynchronizationStrategy getSynchronizationStrategy() {
return synchronizationStrategy;
}
} }

View File

@ -38,8 +38,6 @@ public class SunOneJtaPlatform extends AbstractJtaPlatform {
public static final String TM_NAME = "java:appserver/TransactionManager"; public static final String TM_NAME = "java:appserver/TransactionManager";
public static final String UT_NAME = "java:comp/UserTransaction"; public static final String UT_NAME = "java:comp/UserTransaction";
private final JtaSynchronizationStrategy synchronizationStrategy = new TransactionManagerBasedSynchronizationStrategy( this );
@Override @Override
protected TransactionManager locateTransactionManager() { protected TransactionManager locateTransactionManager() {
return (TransactionManager) jndiService().locate( TM_NAME ); return (TransactionManager) jndiService().locate( TM_NAME );
@ -49,9 +47,4 @@ public class SunOneJtaPlatform extends AbstractJtaPlatform {
protected UserTransaction locateUserTransaction() { protected UserTransaction locateUserTransaction() {
return (UserTransaction) jndiService().locate( UT_NAME ); return (UserTransaction) jndiService().locate( UT_NAME );
} }
@Override
protected JtaSynchronizationStrategy getSynchronizationStrategy() {
return synchronizationStrategy;
}
} }

View File

@ -38,8 +38,6 @@ public class TransactionManagerLookupBridge extends AbstractJtaPlatform {
private final TransactionManagerLookup lookup; private final TransactionManagerLookup lookup;
private final Properties jndiProperties; private final Properties jndiProperties;
private final JtaSynchronizationStrategy synchronizationStrategy = new TransactionManagerBasedSynchronizationStrategy( this );
public TransactionManagerLookupBridge(TransactionManagerLookup lookup, Properties jndiProperties) { public TransactionManagerLookupBridge(TransactionManagerLookup lookup, Properties jndiProperties) {
this.lookup = lookup; this.lookup = lookup;
this.jndiProperties = jndiProperties; this.jndiProperties = jndiProperties;
@ -55,11 +53,6 @@ public class TransactionManagerLookupBridge extends AbstractJtaPlatform {
return (UserTransaction) serviceRegistry().getService( JndiService.class ).locate( lookup.getUserTransactionName() ); return (UserTransaction) serviceRegistry().getService( JndiService.class ).locate( lookup.getUserTransactionName() );
} }
@Override
protected JtaSynchronizationStrategy getSynchronizationStrategy() {
return synchronizationStrategy;
}
@Override @Override
public Object getTransactionIdentifier(Transaction transaction) { public Object getTransactionIdentifier(Transaction transaction) {
return lookup.getTransactionIdentifier( transaction ); return lookup.getTransactionIdentifier( transaction );

View File

@ -57,8 +57,6 @@ import org.hibernate.HibernateException;
public class WebSphereExtendedJtaPlatform extends AbstractJtaPlatform { public class WebSphereExtendedJtaPlatform extends AbstractJtaPlatform {
public static final String UT_NAME = "java:comp/UserTransaction"; public static final String UT_NAME = "java:comp/UserTransaction";
private final JtaSynchronizationStrategy synchronizationStrategy = new TransactionManagerBasedSynchronizationStrategy( this );
@Override @Override
protected boolean canCacheTransactionManager() { protected boolean canCacheTransactionManager() {
return true; return true;
@ -81,11 +79,6 @@ public class WebSphereExtendedJtaPlatform extends AbstractJtaPlatform {
return Integer.valueOf( transaction.hashCode() ); return Integer.valueOf( transaction.hashCode() );
} }
@Override
protected JtaSynchronizationStrategy getSynchronizationStrategy() {
return synchronizationStrategy;
}
public class TransactionManagerAdapter implements TransactionManager { public class TransactionManagerAdapter implements TransactionManager {
private final Class synchronizationCallbackClass; private final Class synchronizationCallbackClass;
private final Method registerSynchronizationMethod; private final Method registerSynchronizationMethod;

View File

@ -38,14 +38,11 @@ import org.jboss.logging.Logger;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class WebSphereJtaPlatform extends AbstractJtaPlatform { public class WebSphereJtaPlatform extends AbstractJtaPlatform {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, WebSphereJtaPlatform.class.getName()); private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, WebSphereJtaPlatform.class.getName());
public static final String VERSION_5_UT_NAME = "java:comp/UserTransaction"; public static final String VERSION_5_UT_NAME = "java:comp/UserTransaction";
public static final String VERSION_4_UT_NAME = "jta/usertransaction"; public static final String VERSION_4_UT_NAME = "jta/usertransaction";
private final JtaSynchronizationStrategy synchronizationStrategy = new TransactionManagerBasedSynchronizationStrategy( this );
private final Class transactionManagerAccessClass; private final Class transactionManagerAccessClass;
private final int webSphereVersion; private final int webSphereVersion;
@ -96,9 +93,4 @@ public class WebSphereJtaPlatform extends AbstractJtaPlatform {
final String utName = webSphereVersion == 5 ? VERSION_5_UT_NAME : VERSION_4_UT_NAME; final String utName = webSphereVersion == 5 ? VERSION_5_UT_NAME : VERSION_4_UT_NAME;
return (UserTransaction) jndiService().locate( utName ); return (UserTransaction) jndiService().locate( utName );
} }
@Override
protected JtaSynchronizationStrategy getSynchronizationStrategy() {
return synchronizationStrategy;
}
} }

View File

@ -36,8 +36,6 @@ public class WeblogicJtaPlatform extends AbstractJtaPlatform {
public static final String TM_NAME = "javax.transaction.TransactionManager"; public static final String TM_NAME = "javax.transaction.TransactionManager";
public static final String UT_NAME = "javax.transaction.UserTransaction"; public static final String UT_NAME = "javax.transaction.UserTransaction";
private final JtaSynchronizationStrategy synchronizationStrategy = new TransactionManagerBasedSynchronizationStrategy( this );
@Override @Override
protected TransactionManager locateTransactionManager() { protected TransactionManager locateTransactionManager() {
return (TransactionManager) jndiService().locate( TM_NAME ); return (TransactionManager) jndiService().locate( TM_NAME );
@ -47,9 +45,4 @@ public class WeblogicJtaPlatform extends AbstractJtaPlatform {
protected UserTransaction locateUserTransaction() { protected UserTransaction locateUserTransaction() {
return (UserTransaction) jndiService().locate( UT_NAME ); return (UserTransaction) jndiService().locate( UT_NAME );
} }
@Override
protected JtaSynchronizationStrategy getSynchronizationStrategy() {
return synchronizationStrategy;
}
} }