Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHH-18964 Remove obsolete JtaPlatforms #9607

Merged
merged 17 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,13 @@ Hibernate tries to discover the `JtaPlatform` it should use through the use of a
If that resolution does not work, or if you wish to provide a custom implementation you will need to specify the `hibernate.transaction.jta.platform` setting.
Hibernate provides many implementations of the `JtaPlatform` contract, all with short names:

`Atomikos`:: `JtaPlatform` for Atomikos.
`Borland`:: `JtaPlatform` for the Borland Enterprise Server.
`Bitronix`:: `JtaPlatform` for Bitronix.
`JBossAS`:: `JtaPlatform` for Arjuna/JBossTransactions/Narayana when used within the JBoss/WildFly Application Server.
`JBossTS`:: `JtaPlatform` for Arjuna/JBossTransactions/Narayana when used standalone.
`JOnAS`:: `JtaPlatform` for JOTM when used within JOnAS.
`JOTM`:: `JtaPlatform` for JOTM when used standalone.
`JRun4`:: `JtaPlatform` for the JRun 4 Application Server.
`OC4J`:: `JtaPlatform` for Oracle's OC4J container.
`Orion`:: `JtaPlatform` for the Orion Application Server.
`Atomikos`:: `JtaPlatform` for Atomikos.
`GlassFish`, `Payara`:: `JtaPlatform` for GlassFish or Payara.
`Resin`:: `JtaPlatform` for the Resin Application Server.
`SapNetWeaver`:: `JtaPlatform` for the SAP NetWeaver Application Server.
`SunOne`:: `JtaPlatform` for the SunOne Application Server.
`Weblogic`:: `JtaPlatform` for the Weblogic Application Server.
`WebSphere`:: `JtaPlatform` for older versions of the WebSphere Application Server.
`WebSphereExtended`:: `JtaPlatform` for newer versions of the WebSphere Application Server.
`WebSphere`, `WebSphereLiberty`:: `JtaPlatform` for newer versions of the WebSphere Application Server.

[[transactions-api]]
=== Hibernate Transaction API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,10 @@
import java.util.Objects;

import org.hibernate.engine.transaction.jta.platform.internal.AtomikosJtaPlatform;
import org.hibernate.engine.transaction.jta.platform.internal.BitronixJtaPlatform;
import org.hibernate.engine.transaction.jta.platform.internal.BorlandEnterpriseServerJtaPlatform;
import org.hibernate.engine.transaction.jta.platform.internal.JBossAppServerJtaPlatform;
import org.hibernate.engine.transaction.jta.platform.internal.JBossStandAloneJtaPlatform;
import org.hibernate.engine.transaction.jta.platform.internal.JOTMJtaPlatform;
import org.hibernate.engine.transaction.jta.platform.internal.JOnASJtaPlatform;
import org.hibernate.engine.transaction.jta.platform.internal.JRun4JtaPlatform;
import org.hibernate.engine.transaction.jta.platform.internal.OC4JJtaPlatform;
import org.hibernate.engine.transaction.jta.platform.internal.OrionJtaPlatform;
import org.hibernate.engine.transaction.jta.platform.internal.ResinJtaPlatform;
import org.hibernate.engine.transaction.jta.platform.internal.SapNetWeaverJtaPlatform;
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.GlassFishJtaPlatform;
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;
Expand All @@ -30,109 +20,46 @@ public class DefaultJtaPlatformSelector implements LazyServiceResolver<JtaPlatfo
@Override
public Class<? extends JtaPlatform> resolve(final String name) {
Objects.requireNonNull( name);
if ( name.isEmpty() ) {
if ( name.isBlank() ) {
return null;
}
//Let's organize all string matches in groups by first letter:
final char n = name.charAt( 0 );
switch ( n ) {
case 'B': return caseB( name );
case 'J': return caseJ( name );
case 'W': return caseW( name );
case 'o': return caseLegacy( name, this );
default: return caseOthers( name );
else if ( name.startsWith( "org." ) ) {
return legacy( name, this );
}
else {
return switch ( name ) {
case "JBossAS" -> JBossAppServerJtaPlatform.class;
case "JBossTS" -> JBossStandAloneJtaPlatform.class;
case "Weblogic" -> WeblogicJtaPlatform.class;
case "WebSphere", "WebSphereLiberty" -> WebSphereLibertyJtaPlatform.class;
case "Atomikos" -> AtomikosJtaPlatform.class;
case "Resin" -> ResinJtaPlatform.class;
case "GlassFish", "Payara", "SunOne" -> GlassFishJtaPlatform.class;
default -> null;
};
}
}

private static Class<? extends JtaPlatform> caseB(final String name) {
if ( "Bitronix".equals( name ) ) {
return BitronixJtaPlatform.class;
}
if ( "Borland".equals( name ) ) {
return BorlandEnterpriseServerJtaPlatform.class;
}
return null;
}

private static Class<? extends JtaPlatform> caseJ(final String name) {
if ( "JBossAS".equals( name ) ) {
return JBossAppServerJtaPlatform.class;
}
if ( "JBossTS".equals( name ) ) {
return JBossStandAloneJtaPlatform.class;
}
if ( "JOnAS".equals( name ) ) {
return JOnASJtaPlatform.class;
}
if ( "JOTM".equals( name ) ) {
return JOTMJtaPlatform.class;
}
if ( "JRun4".equals( name ) ) {
return JRun4JtaPlatform.class;
}
return null;
}

private static Class<? extends JtaPlatform> caseW(final String name) {
if ( "Weblogic".equals( name ) ) {
return WeblogicJtaPlatform.class;
}
if ( "WebSphereLiberty".equals( name ) ) {
return WebSphereLibertyJtaPlatform.class;
}
if ( "WebSphere".equals( name ) ) {
return WebSphereJtaPlatform.class;
}
if ( "WebSphereExtended".equals( name ) ) {
return WebSphereExtendedJtaPlatform.class;
}
return null;
}

private static Class<? extends JtaPlatform> caseOthers(final String name) {
if ( "Atomikos".equals( name ) ) {
return AtomikosJtaPlatform.class;
}
if ( "OC4J".equals( name ) ) {
return OC4JJtaPlatform.class;
}
if ( "Orion".equals( name ) ) {
return OrionJtaPlatform.class;
}
if ( "Resin".equals( name ) ) {
return ResinJtaPlatform.class;
}
if ( "SapNetWeaver".equals( name ) ) {
return SapNetWeaverJtaPlatform.class;
}
if ( "SunOne".equals( name ) ) {
return SunOneJtaPlatform.class;
}
return null;
}

/**
* Special case: we have several old fully qualified classnames which need to
* be remapped to their new names for backwards compatibility reasons.
*/
private static Class<? extends JtaPlatform> caseLegacy(
private static Class<? extends JtaPlatform> legacy(
final String name,
final DefaultJtaPlatformSelector defaultJtaPlatformSelector) {

//First, let's deal with the special cases which don't follow any recognizable pattern:
if ( name.equals( "org.hibernate.service.jta.platform.internal.BorlandEnterpriseServerJtaPlatform" ) ) {
return BorlandEnterpriseServerJtaPlatform.class;
}
if ( name.equals( "org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" ) ) {
return JBossAppServerJtaPlatform.class;
}
if ( name.equals( "org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform" ) ) {
return JBossStandAloneJtaPlatform.class;
}
//This one shouldn't be necessary as it matches the implementation FQN, but let's translate the existing
//code faithfully.
if ( name.equals( "org.hibernate.engine.transaction.jta.platform.internal.WebSphereLibertyJtaPlatform" ) ) {
return WebSphereLibertyJtaPlatform.class;
switch ( name ) {
case "org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" -> {
return JBossAppServerJtaPlatform.class;
}
case "org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform" -> {
return JBossStandAloneJtaPlatform.class;
}
case "org.hibernate.engine.transaction.jta.platform.internal.WebSphereLibertyJtaPlatform" -> {
return WebSphereLibertyJtaPlatform.class;
}
}

//All other ones follow a pattern, beginning with the same prefix and ending with the same postfix,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@
import jakarta.transaction.TransactionManager;
import jakarta.transaction.UserTransaction;

import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.jndi.spi.JndiService;
import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.spi.Configurable;
import org.hibernate.service.spi.ServiceRegistryAwareService;
import org.hibernate.service.spi.ServiceRegistryImplementor;

import static org.hibernate.cfg.TransactionSettings.JTA_CACHE_TM;
import static org.hibernate.cfg.TransactionSettings.JTA_CACHE_UT;
import static org.hibernate.internal.util.config.ConfigurationHelper.getBoolean;

/**
* @author Steve Ebersole
*/
Expand All @@ -43,7 +45,7 @@ private final class TransactionManagerBasedSynchronizationStrategy implements Jt
@Override
public void registerSynchronization(Synchronization synchronization) {
try {
AbstractJtaPlatform.this.getTransactionManager().getTransaction().registerSynchronization( synchronization );
getTransactionManager().getTransaction().registerSynchronization( synchronization );
}
catch (Exception e) {
throw new JtaPlatformException( "Could not access JTA Transaction to register synchronization", e );
Expand All @@ -52,7 +54,7 @@ public void registerSynchronization(Synchronization synchronization) {

@Override
public boolean canRegisterSynchronization() {
return JtaStatusHelper.isActive( AbstractJtaPlatform.this.getTransactionManager() );
return JtaStatusHelper.isActive( getTransactionManager() );
}
}

Expand All @@ -68,16 +70,8 @@ protected JndiService jndiService() {
protected abstract UserTransaction locateUserTransaction();

public void configure(Map<String, Object> configValues) {
cacheTransactionManager = ConfigurationHelper.getBoolean(
AvailableSettings.JTA_CACHE_TM,
configValues,
canCacheTransactionManagerByDefault()
);
cacheUserTransaction = ConfigurationHelper.getBoolean(
AvailableSettings.JTA_CACHE_UT,
configValues,
canCacheUserTransactionByDefault()
);
cacheTransactionManager = getBoolean( JTA_CACHE_TM, configValues, canCacheTransactionManagerByDefault() );
cacheUserTransaction = getBoolean( JTA_CACHE_UT, configValues, canCacheUserTransactionByDefault() );
}

protected boolean canCacheTransactionManagerByDefault() {
Expand Down Expand Up @@ -126,7 +120,9 @@ public UserTransaction retrieveUserTransaction() {
}
return userTransaction;
}
return locateUserTransaction();
else {
return locateUserTransaction();
}
}

@Override
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Emmanuel Bernard
* @author Steve Ebersole
*/
public class SunOneJtaPlatform extends AbstractJtaPlatform {
public class GlassFishJtaPlatform extends AbstractJtaPlatform {
public static final String TM_NAME = "java:appserver/TransactionManager";
public static final String UT_NAME = "java:comp/UserTransaction";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ protected boolean canCacheUserTransactionByDefault() {
return true;
}

@Override
protected boolean canCacheTransactionManagerByDefault() {
return true;
}

@Override
protected TransactionManager locateTransactionManager() {
try {
Expand Down

This file was deleted.

Loading
Loading