HHH-12640 Do not fully deprecate the WildFlyStandAloneJtaPlatform so to allow an explicit user choice

This commit is contained in:
Sanne Grinovero 2018-06-26 15:44:17 +01:00
parent 1a89a167b4
commit d0087948ef
3 changed files with 49 additions and 17 deletions

View File

@ -20,19 +20,17 @@ import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException;
* @author Steve Ebersole
*/
public class JBossStandAloneJtaPlatform extends AbstractJtaPlatform {
public static final String JBOSS_TM_CLASS_NAME = "com.arjuna.ats.jta.TransactionManager";
public static final String JBOSS_UT_CLASS_NAME = "com.arjuna.ats.jta.UserTransaction";
public static final String WILDFLY_TM_CLASS_NAME = "org.wildfly.transaction.client.ContextTransactionManager";
public static final String WILDFLY_UT_CLASS_NAME = "org.wildfly.transaction.client.LocalUserTransaction";
private static final WildFlyStandAloneJtaPlatform wildflyBasedAlternative = new WildFlyStandAloneJtaPlatform();
@Override
protected TransactionManager locateTransactionManager() {
//Try WildFly first as it's the "new generation":
try {
final Class wildflyTmClass = serviceRegistry()
.getService( ClassLoaderService.class )
.classForName( WILDFLY_TM_CLASS_NAME );
return (TransactionManager) wildflyTmClass.getMethod( "getInstance" ).invoke( null );
return wildflyBasedAlternative.locateTransactionManager();
}
catch ( Exception ignore) {
// ignore and look for Arjuna class
@ -51,11 +49,9 @@ public class JBossStandAloneJtaPlatform extends AbstractJtaPlatform {
@Override
protected UserTransaction locateUserTransaction() {
//Try WildFly first as it's the "new generation":
try {
final Class jbossUtClass = serviceRegistry()
.getService( ClassLoaderService.class )
.classForName( WILDFLY_UT_CLASS_NAME );
return (UserTransaction) jbossUtClass.getMethod( "getInstance" ).invoke( null );
return wildflyBasedAlternative.locateUserTransaction();
}
catch ( Exception ignore) {
// ignore and look for Arjuna class

View File

@ -47,8 +47,8 @@ public class StandardJtaPlatformResolver implements JtaPlatformResolver {
// first try loading WildFly Transaction Client
try {
classLoaderService.classForName( JBossStandAloneJtaPlatform.WILDFLY_TM_CLASS_NAME );
classLoaderService.classForName( JBossStandAloneJtaPlatform.WILDFLY_UT_CLASS_NAME );
classLoaderService.classForName( WildFlyStandAloneJtaPlatform.WILDFLY_TM_CLASS_NAME );
classLoaderService.classForName( WildFlyStandAloneJtaPlatform.WILDFLY_UT_CLASS_NAME );
// we know that the WildFly Transaction Client TM classes are available
// if neither of these look-ups resulted in an error (no such class), then WildFly Transaction Client TM is available on
@ -59,7 +59,7 @@ public class StandardJtaPlatformResolver implements JtaPlatformResolver {
// should be relying on that.
// Note that on WF13+, we can expect org.jboss.as.jpa.hibernate5.service.WildFlyCustomJtaPlatformInitiator to choose
// the WildFlyCustomJtaPlatform, unless the application has disabled WildFlyCustomJtaPlatformInitiator.
return new JBossStandAloneJtaPlatform();
return new WildFlyStandAloneJtaPlatform();
}
catch (ClassLoadingException ignore) {
}

View File

@ -6,15 +6,51 @@
*/
package org.hibernate.engine.transaction.jta.platform.internal;
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException;
/**
* Return a standalone JTA transaction manager for WildFly transaction client
* Known to work for WildFly 13+
*
* @author Scott Marlow
*
* @deprecated (since 5.3.1), use {@link org.hibernate.engine.transaction.jta.platform.internal.JBossStandAloneJtaPlatform} instead
*/
@Deprecated
public class WildFlyStandAloneJtaPlatform extends JBossStandAloneJtaPlatform {
public class WildFlyStandAloneJtaPlatform extends AbstractJtaPlatform {
public static final String WILDFLY_TM_CLASS_NAME = "org.wildfly.transaction.client.ContextTransactionManager";
public static final String WILDFLY_UT_CLASS_NAME = "org.wildfly.transaction.client.LocalUserTransaction";
@Override
protected TransactionManager locateTransactionManager() {
try {
final Class wildflyTmClass = serviceRegistry()
.getService( ClassLoaderService.class )
.classForName( WILDFLY_TM_CLASS_NAME );
return (TransactionManager) wildflyTmClass.getMethod( "getInstance" ).invoke( null );
}
catch (Exception e) {
throw new JtaPlatformException(
"Could not obtain WildFly Transaction Client transaction manager instance",
e
);
}
}
@Override
protected UserTransaction locateUserTransaction() {
try {
final Class jbossUtClass = serviceRegistry()
.getService( ClassLoaderService.class )
.classForName( WILDFLY_UT_CLASS_NAME );
return (UserTransaction) jbossUtClass.getMethod( "getInstance" ).invoke( null );
}
catch (Exception e) {
throw new JtaPlatformException(
"Could not obtain WildFly Transaction Client user transaction instance",
e
);
}
}
}