HHH-10248 - map removed TransactionFactory classes

This commit is contained in:
Steve Ebersole 2015-11-04 20:55:52 -06:00
parent 1a2bdd09e8
commit 22ffaea0c3
5 changed files with 139 additions and 3 deletions

View File

@ -20,6 +20,7 @@ import org.hibernate.boot.registry.selector.StrategyRegistrationProvider;
import org.hibernate.boot.registry.selector.internal.StrategySelectorBuilder;
import org.hibernate.integrator.internal.IntegratorServiceImpl;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.service.ServiceRegistry;
/**
* Builder for {@link BootstrapServiceRegistry} instances. Provides registry for services needed for
@ -222,4 +223,17 @@ public class BootstrapServiceRegistryBuilder {
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();
}
}

View File

@ -354,6 +354,23 @@ public class StrategySelectorBuilder {
JtaTransactionCoordinatorBuilderImpl.SHORT_NAME,
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) {

View File

@ -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)"
)
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);
}

View File

@ -11,10 +11,13 @@ import java.util.Map;
import org.hibernate.boot.registry.StandardServiceInitiator;
import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.internal.log.DeprecationLogger;
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.jboss.logging.Logger;
/**
* StandardServiceInitiator for initiating the TransactionCoordinatorBuilder service.
*
@ -22,6 +25,8 @@ import org.hibernate.service.spi.ServiceRegistryImplementor;
* @author Steve Ebersole
*/
public class TransactionCoordinatorBuilderInitiator implements StandardServiceInitiator<TransactionCoordinatorBuilder> {
public static final String LEGACY_SETTING_NAME = "hibernate.transaction.factory_class";
/**
* Singleton access
*/
@ -29,15 +34,32 @@ public class TransactionCoordinatorBuilderInitiator implements StandardServiceIn
@Override
public TransactionCoordinatorBuilder initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
final Object strategy = configurationValues.get( AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY );
return registry.getService( StrategySelector.class ).resolveDefaultableStrategy(
TransactionCoordinatorBuilder.class,
strategy,
determineStrategySelection( configurationValues ),
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
public Class<TransactionCoordinatorBuilder> getServiceInitiated() {
return TransactionCoordinatorBuilder.class;

View File

@ -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 ) );
}
}