HHH-12640 Update to JBossStandAloneJtaPlatform should be backward compatible attempting old names as well

This commit is contained in:
Scott Marlow 2018-05-27 10:10:00 -04:00
parent bb5ab3881c
commit 558cbdd97d
2 changed files with 82 additions and 0 deletions

View File

@ -45,6 +45,25 @@ public class StandardJtaPlatformResolver implements JtaPlatformResolver {
// IMPL NOTE : essentially we attempt Class lookups and use the exceptions from the class(es) not // IMPL NOTE : essentially we attempt Class lookups and use the exceptions from the class(es) not
// being found as the indicator // being found as the indicator
// first try loading WildFly Transaction Client
try {
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 available on
// the classpath.
//
// todo : we cannot really distinguish between the need for JBossStandAloneJtaPlatform versus JBossApServerJtaPlatform
// but discussions with David led to the JtaPlatformProvider solution above, so inside JBoss AS we
// 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 WildFlyStandAloneJtaPlatform();
}
catch (ClassLoadingException ignore) {
}
// JBoss ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // JBoss ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
try { try {

View File

@ -0,0 +1,63 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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
*/
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
);
}
}
}