HHH-10248 - map removed TransactionFactory classes
This commit is contained in:
parent
1a2bdd09e8
commit
22ffaea0c3
|
@ -20,6 +20,7 @@ import org.hibernate.boot.registry.selector.StrategyRegistrationProvider;
|
||||||
import org.hibernate.boot.registry.selector.internal.StrategySelectorBuilder;
|
import org.hibernate.boot.registry.selector.internal.StrategySelectorBuilder;
|
||||||
import org.hibernate.integrator.internal.IntegratorServiceImpl;
|
import org.hibernate.integrator.internal.IntegratorServiceImpl;
|
||||||
import org.hibernate.integrator.spi.Integrator;
|
import org.hibernate.integrator.spi.Integrator;
|
||||||
|
import org.hibernate.service.ServiceRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder for {@link BootstrapServiceRegistry} instances. Provides registry for services needed for
|
* Builder for {@link BootstrapServiceRegistry} instances. Provides registry for services needed for
|
||||||
|
@ -222,4 +223,17 @@ public class BootstrapServiceRegistryBuilder {
|
||||||
integratorService
|
integratorService
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy a service registry. Applications should only destroy registries they have explicitly created.
|
||||||
|
*
|
||||||
|
* @param serviceRegistry The registry to be closed.
|
||||||
|
*/
|
||||||
|
public static void destroy(ServiceRegistry serviceRegistry) {
|
||||||
|
if ( serviceRegistry == null ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
( (BootstrapServiceRegistryImpl) serviceRegistry ).destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -354,6 +354,23 @@ public class StrategySelectorBuilder {
|
||||||
JtaTransactionCoordinatorBuilderImpl.SHORT_NAME,
|
JtaTransactionCoordinatorBuilderImpl.SHORT_NAME,
|
||||||
JtaTransactionCoordinatorBuilderImpl.class
|
JtaTransactionCoordinatorBuilderImpl.class
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// add the legacy TransactionFactory impl names...
|
||||||
|
strategySelector.registerStrategyImplementor(
|
||||||
|
TransactionCoordinatorBuilder.class,
|
||||||
|
"org.hibernate.transaction.JDBCTransactionFactory",
|
||||||
|
JdbcResourceLocalTransactionCoordinatorBuilderImpl.class
|
||||||
|
);
|
||||||
|
strategySelector.registerStrategyImplementor(
|
||||||
|
TransactionCoordinatorBuilder.class,
|
||||||
|
"org.hibernate.transaction.JTATransactionFactory",
|
||||||
|
JtaTransactionCoordinatorBuilderImpl.class
|
||||||
|
);
|
||||||
|
strategySelector.registerStrategyImplementor(
|
||||||
|
TransactionCoordinatorBuilder.class,
|
||||||
|
"org.hibernate.transaction.CMTTransactionFactory",
|
||||||
|
JtaTransactionCoordinatorBuilderImpl.class
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addMultiTableBulkIdStrategies(StrategySelectorImpl strategySelector) {
|
private void addMultiTableBulkIdStrategies(StrategySelectorImpl strategySelector) {
|
||||||
|
|
|
@ -193,4 +193,11 @@ public interface DeprecationLogger extends BasicLogger {
|
||||||
value = "Found use of deprecated entity-type selector syntax in HQL/JPQL query ['%1$s.class']; use TYPE operator instead : type(%1$s)"
|
value = "Found use of deprecated entity-type selector syntax in HQL/JPQL query ['%1$s.class']; use TYPE operator instead : type(%1$s)"
|
||||||
)
|
)
|
||||||
void logDeprecationOfClassEntityTypeSelector(String path);
|
void logDeprecationOfClassEntityTypeSelector(String path);
|
||||||
|
|
||||||
|
@LogMessage(level = WARN)
|
||||||
|
@Message(
|
||||||
|
id = 90000018,
|
||||||
|
value = "Found use of deprecated transaction factory setting [%s]; use the new TransactionCoordinatorBuilder settings [%s] instead"
|
||||||
|
)
|
||||||
|
void logDeprecatedTransactionFactorySetting(String legacySettingName, String updatedSettingName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,13 @@ import java.util.Map;
|
||||||
import org.hibernate.boot.registry.StandardServiceInitiator;
|
import org.hibernate.boot.registry.StandardServiceInitiator;
|
||||||
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
|
import org.hibernate.internal.log.DeprecationLogger;
|
||||||
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
|
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
|
||||||
import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl;
|
import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl;
|
||||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||||
|
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StandardServiceInitiator for initiating the TransactionCoordinatorBuilder service.
|
* StandardServiceInitiator for initiating the TransactionCoordinatorBuilder service.
|
||||||
*
|
*
|
||||||
|
@ -22,6 +25,8 @@ import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class TransactionCoordinatorBuilderInitiator implements StandardServiceInitiator<TransactionCoordinatorBuilder> {
|
public class TransactionCoordinatorBuilderInitiator implements StandardServiceInitiator<TransactionCoordinatorBuilder> {
|
||||||
|
public static final String LEGACY_SETTING_NAME = "hibernate.transaction.factory_class";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Singleton access
|
* Singleton access
|
||||||
*/
|
*/
|
||||||
|
@ -29,15 +34,32 @@ public class TransactionCoordinatorBuilderInitiator implements StandardServiceIn
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TransactionCoordinatorBuilder initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
|
public TransactionCoordinatorBuilder initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
|
||||||
final Object strategy = configurationValues.get( AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY );
|
|
||||||
|
|
||||||
return registry.getService( StrategySelector.class ).resolveDefaultableStrategy(
|
return registry.getService( StrategySelector.class ).resolveDefaultableStrategy(
|
||||||
TransactionCoordinatorBuilder.class,
|
TransactionCoordinatorBuilder.class,
|
||||||
strategy,
|
determineStrategySelection( configurationValues ),
|
||||||
JdbcResourceLocalTransactionCoordinatorBuilderImpl.INSTANCE
|
JdbcResourceLocalTransactionCoordinatorBuilderImpl.INSTANCE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Object determineStrategySelection(Map configurationValues) {
|
||||||
|
final Object coordinatorStrategy = configurationValues.get( AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY );
|
||||||
|
if ( coordinatorStrategy != null ) {
|
||||||
|
return coordinatorStrategy;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Object legacySetting = configurationValues.get( LEGACY_SETTING_NAME );
|
||||||
|
if ( legacySetting != null ) {
|
||||||
|
DeprecationLogger.DEPRECATION_LOGGER.logDeprecatedTransactionFactorySetting(
|
||||||
|
LEGACY_SETTING_NAME,
|
||||||
|
AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY
|
||||||
|
);
|
||||||
|
return legacySetting;
|
||||||
|
}
|
||||||
|
|
||||||
|
// triggers the default
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<TransactionCoordinatorBuilder> getServiceInitiated() {
|
public Class<TransactionCoordinatorBuilder> getServiceInitiated() {
|
||||||
return TransactionCoordinatorBuilder.class;
|
return TransactionCoordinatorBuilder.class;
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
/*
|
||||||
|
* 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.test.resource.transaction;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||||
|
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||||
|
import org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl;
|
||||||
|
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
|
||||||
|
import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl;
|
||||||
|
import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl;
|
||||||
|
import org.hibernate.resource.transaction.internal.TransactionCoordinatorBuilderInitiator;
|
||||||
|
|
||||||
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class LegacySettingInitiatorTest extends BaseUnitTestCase {
|
||||||
|
private BootstrapServiceRegistryImpl bsr;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void before() {
|
||||||
|
bsr = (BootstrapServiceRegistryImpl) new BootstrapServiceRegistryBuilder().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void after() {
|
||||||
|
if ( bsr != null ) {
|
||||||
|
bsr.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLegacySettingSelection() {
|
||||||
|
final TransactionCoordinatorBuilderInitiator initiator = new TransactionCoordinatorBuilderInitiator();
|
||||||
|
|
||||||
|
TransactionCoordinatorBuilder builder = initiator.initiateService(
|
||||||
|
Collections.singletonMap(
|
||||||
|
TransactionCoordinatorBuilderInitiator.LEGACY_SETTING_NAME,
|
||||||
|
"org.hibernate.transaction.JDBCTransactionFactory"
|
||||||
|
),
|
||||||
|
bsr
|
||||||
|
);
|
||||||
|
assertThat( builder, instanceOf( JdbcResourceLocalTransactionCoordinatorBuilderImpl.class ) );
|
||||||
|
|
||||||
|
builder = initiator.initiateService(
|
||||||
|
Collections.singletonMap(
|
||||||
|
TransactionCoordinatorBuilderInitiator.LEGACY_SETTING_NAME,
|
||||||
|
"org.hibernate.transaction.JTATransactionFactory"
|
||||||
|
),
|
||||||
|
bsr
|
||||||
|
);
|
||||||
|
assertThat( builder, instanceOf( JtaTransactionCoordinatorBuilderImpl.class ) );
|
||||||
|
|
||||||
|
builder = initiator.initiateService(
|
||||||
|
Collections.singletonMap(
|
||||||
|
TransactionCoordinatorBuilderInitiator.LEGACY_SETTING_NAME,
|
||||||
|
"org.hibernate.transaction.CMTTransactionFactory"
|
||||||
|
),
|
||||||
|
bsr
|
||||||
|
);
|
||||||
|
assertThat( builder, instanceOf( JtaTransactionCoordinatorBuilderImpl.class ) );
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue