HHH-11571 - JTA platform for WebSphere Liberty and OpenLiberty
This commit is contained in:
parent
795055de51
commit
cd4a6e9a49
|
@ -84,6 +84,7 @@ import org.hibernate.engine.transaction.jta.platform.internal.SapNetWeaverJtaPla
|
|||
import org.hibernate.engine.transaction.jta.platform.internal.SunOneJtaPlatform;
|
||||
import org.hibernate.engine.transaction.jta.platform.internal.WebSphereExtendedJtaPlatform;
|
||||
import org.hibernate.engine.transaction.jta.platform.internal.WebSphereJtaPlatform;
|
||||
import org.hibernate.engine.transaction.jta.platform.internal.WebSphereLibertyJtaPlatform;
|
||||
import org.hibernate.engine.transaction.jta.platform.internal.WeblogicJtaPlatform;
|
||||
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
||||
import org.hibernate.event.internal.EntityCopyAllowedLoggedObserver;
|
||||
|
@ -342,6 +343,13 @@ public class StrategySelectorBuilder {
|
|||
"org.hibernate.service.jta.platform.internal.WeblogicJtaPlatform"
|
||||
);
|
||||
|
||||
addJtaPlatforms(
|
||||
strategySelector,
|
||||
WebSphereLibertyJtaPlatform.class,
|
||||
"WebSphereLiberty",
|
||||
"org.hibernate.engine.transaction.jta.platform.internal.WebSphereLibertyJtaPlatform"
|
||||
);
|
||||
|
||||
addJtaPlatforms(
|
||||
strategySelector,
|
||||
WebSphereJtaPlatform.class,
|
||||
|
|
|
@ -87,7 +87,15 @@ public class StandardJtaPlatformResolver implements JtaPlatformResolver {
|
|||
catch (ClassLoadingException ignore) {
|
||||
}
|
||||
|
||||
// WebSphere ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// WebSphere Liberty ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
try {
|
||||
classLoaderService.classForName(WebSphereLibertyJtaPlatform.TMF_CLASS_NAME);
|
||||
return new WebSphereLibertyJtaPlatform();
|
||||
}
|
||||
catch (ClassLoadingException ignore) {
|
||||
}
|
||||
|
||||
// WebSphere traditional ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
for ( WebSphereJtaPlatform.WebSphereEnvironment webSphereEnvironment
|
||||
: WebSphereJtaPlatform.WebSphereEnvironment.values() ) {
|
||||
try {
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.hibernate.HibernateException;
|
|||
* <li>the WAS container in which Hibernate will be utilized</li>
|
||||
* </ul>
|
||||
* <p/>
|
||||
* This class is reported to work on WAS version 6 in any of the standard J2EE/JEE component containers.
|
||||
* This class is reported to work on WAS version 6 in any of the standard J2EE/Java EE component containers.
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author <a href="mailto:jesper@udby.com>Jesper Udby</a>
|
||||
|
@ -58,7 +58,7 @@ public class WebSphereExtendedJtaPlatform extends AbstractJtaPlatform {
|
|||
|
||||
@Override
|
||||
public Object getTransactionIdentifier(Transaction transaction) {
|
||||
// WebSphere, however, is not a sane JEE/JTA container...
|
||||
// WebSphere, however, is not a sane Java EE/JTA container...
|
||||
return transaction.hashCode();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* 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.RollbackException;
|
||||
import javax.transaction.Status;
|
||||
import javax.transaction.Synchronization;
|
||||
import javax.transaction.SystemException;
|
||||
import javax.transaction.Transaction;
|
||||
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;
|
||||
|
||||
/**
|
||||
* JTA platform implementation intended for use with WebSphere Liberty and OpenLiberty
|
||||
*
|
||||
* @author Andrew Guibert
|
||||
* @author Nathan Rauh
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class WebSphereLibertyJtaPlatform extends AbstractJtaPlatform {
|
||||
|
||||
public static final String TMF_CLASS_NAME = "com.ibm.tx.jta.TransactionManagerFactory";
|
||||
|
||||
public static final String UT_NAME = "java:comp/UserTransaction";
|
||||
|
||||
@Override
|
||||
protected TransactionManager locateTransactionManager() {
|
||||
try {
|
||||
final Class<?> TransactionManagerFactory = serviceRegistry()
|
||||
.getService( ClassLoaderService.class )
|
||||
.classForName( TMF_CLASS_NAME );
|
||||
return (TransactionManager) TransactionManagerFactory.getMethod("getTransactionManager").invoke(null);
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
throw new JtaPlatformException( "Could not obtain WebSphere Liberty transaction manager instance", e );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UserTransaction locateUserTransaction() {
|
||||
return (UserTransaction) jndiService().locate( UT_NAME );
|
||||
}
|
||||
|
||||
public boolean canRegisterSynchronization() {
|
||||
try {
|
||||
return getCurrentStatus() == Status.STATUS_ACTIVE;
|
||||
}
|
||||
catch (SystemException x) {
|
||||
throw new RuntimeException(x);
|
||||
}
|
||||
}
|
||||
|
||||
public int getCurrentStatus() throws SystemException {
|
||||
return retrieveTransactionManager().getStatus();
|
||||
}
|
||||
|
||||
public Object getTransactionIdentifier(Transaction transaction) {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
public void registerSynchronization(Synchronization synchronization) {
|
||||
try {
|
||||
retrieveTransactionManager().getTransaction().registerSynchronization(synchronization);
|
||||
}
|
||||
catch ( RollbackException | SystemException x ) {
|
||||
throw new RuntimeException(x);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -39,8 +39,7 @@ public interface JtaPlatform extends Service {
|
|||
* Determine an identifier for the given transaction appropriate for use in caching/lookup usages.
|
||||
* <p/>
|
||||
* Generally speaking the transaction itself will be returned here. This method was added specifically
|
||||
* for use in WebSphere and other unfriendly JEE containers (although WebSphere is still the only known
|
||||
* such brain-dead, sales-driven impl).
|
||||
* for use in WebSphere and other unfriendly Java EE containers.
|
||||
*
|
||||
* @param transaction The transaction to be identified.
|
||||
* @return An appropriate identifier
|
||||
|
|
Loading…
Reference in New Issue