From d0087948ef353ff51c27e464b3258fc6646369c2 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Tue, 26 Jun 2018 15:44:17 +0100 Subject: [PATCH] HHH-12640 Do not fully deprecate the WildFlyStandAloneJtaPlatform so to allow an explicit user choice --- .../internal/JBossStandAloneJtaPlatform.java | 16 +++---- .../internal/StandardJtaPlatformResolver.java | 6 +-- .../WildFlyStandAloneJtaPlatform.java | 44 +++++++++++++++++-- 3 files changed, 49 insertions(+), 17 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/transaction/jta/platform/internal/JBossStandAloneJtaPlatform.java b/hibernate-core/src/main/java/org/hibernate/engine/transaction/jta/platform/internal/JBossStandAloneJtaPlatform.java index 2b3a17d42d..1e46283c4d 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/transaction/jta/platform/internal/JBossStandAloneJtaPlatform.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/transaction/jta/platform/internal/JBossStandAloneJtaPlatform.java @@ -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 diff --git a/hibernate-core/src/main/java/org/hibernate/engine/transaction/jta/platform/internal/StandardJtaPlatformResolver.java b/hibernate-core/src/main/java/org/hibernate/engine/transaction/jta/platform/internal/StandardJtaPlatformResolver.java index a32eaa9003..a04af918a0 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/transaction/jta/platform/internal/StandardJtaPlatformResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/transaction/jta/platform/internal/StandardJtaPlatformResolver.java @@ -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) { } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/transaction/jta/platform/internal/WildFlyStandAloneJtaPlatform.java b/hibernate-core/src/main/java/org/hibernate/engine/transaction/jta/platform/internal/WildFlyStandAloneJtaPlatform.java index 42327779c1..64e2a80c70 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/transaction/jta/platform/internal/WildFlyStandAloneJtaPlatform.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/transaction/jta/platform/internal/WildFlyStandAloneJtaPlatform.java @@ -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 + ); + } + } }