HHH-10287 - Made necessary changes to backport
This commit is contained in:
parent
6667020808
commit
81ffaacf09
|
@ -13,7 +13,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
||||
import org.hibernate.boot.registry.selector.spi.StrategyCreator;
|
||||
import org.hibernate.boot.registry.selector.spi.StrategySelectionException;
|
||||
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
||||
|
||||
|
@ -27,20 +26,8 @@ import org.jboss.logging.Logger;
|
|||
public class StrategySelectorImpl implements StrategySelector {
|
||||
private static final Logger log = Logger.getLogger( StrategySelectorImpl.class );
|
||||
|
||||
|
||||
public static StrategyCreator STANDARD_STRATEGY_CREATOR = strategyClass -> {
|
||||
try {
|
||||
return strategyClass.newInstance();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new StrategySelectionException(
|
||||
String.format( "Could not instantiate named strategy class [%s]", strategyClass.getName() ),
|
||||
e
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
private final Map<Class,Map<String,Class>> namedStrategyImplementorByStrategyMap = new ConcurrentHashMap<>();
|
||||
private final Map<Class,Map<String,Class>> namedStrategyImplementorByStrategyMap
|
||||
= new ConcurrentHashMap<Class, Map<String, Class>>();
|
||||
|
||||
private final ClassLoaderService classLoaderService;
|
||||
|
||||
|
@ -57,7 +44,7 @@ public class StrategySelectorImpl implements StrategySelector {
|
|||
public <T> void registerStrategyImplementor(Class<T> strategy, String name, Class<? extends T> implementation) {
|
||||
Map<String,Class> namedStrategyImplementorMap = namedStrategyImplementorByStrategyMap.get( strategy );
|
||||
if ( namedStrategyImplementorMap == null ) {
|
||||
namedStrategyImplementorMap = new ConcurrentHashMap<>();
|
||||
namedStrategyImplementorMap = new ConcurrentHashMap<String, Class>();
|
||||
namedStrategyImplementorByStrategyMap.put( strategy, namedStrategyImplementorMap );
|
||||
}
|
||||
|
||||
|
@ -139,7 +126,12 @@ public class StrategySelectorImpl implements StrategySelector {
|
|||
return resolveDefaultableStrategy(
|
||||
strategy,
|
||||
strategyReference,
|
||||
(Callable<T>) () -> defaultValue
|
||||
new Callable<T>() {
|
||||
@Override
|
||||
public T call() {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -149,30 +141,6 @@ public class StrategySelectorImpl implements StrategySelector {
|
|||
Class<T> strategy,
|
||||
Object strategyReference,
|
||||
Callable<T> defaultResolver) {
|
||||
return (T) resolveStrategy( strategy, strategyReference, defaultResolver, STANDARD_STRATEGY_CREATOR );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T resolveStrategy(
|
||||
Class<T> strategy,
|
||||
Object strategyReference,
|
||||
T defaultValue,
|
||||
StrategyCreator<T> creator) {
|
||||
return resolveStrategy(
|
||||
strategy,
|
||||
strategyReference,
|
||||
(Callable<T>) () -> defaultValue,
|
||||
creator
|
||||
);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T resolveStrategy(
|
||||
Class<T> strategy,
|
||||
Object strategyReference,
|
||||
Callable<T> defaultResolver,
|
||||
StrategyCreator<T> creator) {
|
||||
if ( strategyReference == null ) {
|
||||
try {
|
||||
return defaultResolver.call();
|
||||
|
@ -195,7 +163,7 @@ public class StrategySelectorImpl implements StrategySelector {
|
|||
}
|
||||
|
||||
try {
|
||||
return creator.create( implementationClass );
|
||||
return implementationClass.newInstance();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new StrategySelectionException(
|
||||
|
|
|
@ -19,9 +19,9 @@ import org.hibernate.service.Service;
|
|||
* StrategySelector manages resolution of particular implementation by (possibly short) name via the
|
||||
* {@link #selectStrategyImplementor} method, which is the main contract here. As indicated in the docs of that
|
||||
* method the given name might be either a short registered name or the implementation FQN. As an example, consider
|
||||
* resolving the {@link org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder} implementation to use. To use the
|
||||
* JDBC-based TransactionCoordinatorBuilder the passed name might be either {@code "jdbc"} or
|
||||
* {@code "org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl"} (which is the FQN).
|
||||
* resolving the {@link org.hibernate.engine.transaction.spi.TransactionFactory} implementation to use. To use the
|
||||
* JDBC-based TransactionFactory the passed name might be either {@code "jdbc"} or
|
||||
* {@code "org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory"} (which is the FQN).
|
||||
* <p/>
|
||||
* Strategy implementations can be managed by {@link #registerStrategyImplementor} and
|
||||
* {@link #unRegisterStrategyImplementor}. Originally designed to help the OSGi use case, though no longer used there.
|
||||
|
@ -135,8 +135,4 @@ public interface StrategySelector extends Service {
|
|||
* @return The strategy instance
|
||||
*/
|
||||
<T> T resolveDefaultableStrategy(Class<T> strategy, Object strategyReference, Callable<T> defaultResolver);
|
||||
|
||||
<T> T resolveStrategy(Class<T> strategy, Object strategyReference, Callable<T> defaultResolver, StrategyCreator<T> creator);
|
||||
|
||||
<T> T resolveStrategy(Class<T> strategy, Object strategyReference, T defaultValue, StrategyCreator<T> creator);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.Map;
|
|||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.boot.registry.StandardServiceInitiator;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.boot.registry.selector.spi.StrategySelectionException;
|
||||
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
||||
import org.hibernate.cache.spi.RegionFactory;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
@ -61,14 +61,13 @@ public class RegionFactoryInitiator implements StandardServiceInitiator<RegionFa
|
|||
// The cache provider is needed when we either have second-level cache enabled
|
||||
// or query cache enabled. Note that useSecondLevelCache is enabled by default
|
||||
if ( useSecondLevelCache || useQueryCache ) {
|
||||
final Object setting = configurationValues != null
|
||||
final Object strategyReference = configurationValues != null
|
||||
? configurationValues.get( AvailableSettings.CACHE_REGION_FACTORY )
|
||||
: null;
|
||||
regionFactory = registry.getService( StrategySelector.class ).resolveStrategy(
|
||||
RegionFactory.class,
|
||||
setting,
|
||||
NoCachingRegionFactory.INSTANCE,
|
||||
new StrategyCreatorRegionFactoryImpl( p )
|
||||
regionFactory = resolveRegionFactory(
|
||||
registry.getService( StrategySelector.class ),
|
||||
strategyReference,
|
||||
p
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -77,6 +76,43 @@ public class RegionFactoryInitiator implements StandardServiceInitiator<RegionFa
|
|||
return regionFactory;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private RegionFactory resolveRegionFactory(
|
||||
StrategySelector strategySelector,
|
||||
Object strategyReference,
|
||||
Properties properties) {
|
||||
|
||||
if ( strategyReference == null || RegionFactory.class.isInstance( strategyReference ) ) {
|
||||
// nothing to create; just let strategySelector resolve the RegionFactory
|
||||
return strategySelector.resolveDefaultableStrategy(
|
||||
RegionFactory.class,
|
||||
strategyReference,
|
||||
NoCachingRegionFactory.INSTANCE
|
||||
);
|
||||
}
|
||||
|
||||
final Class<? extends RegionFactory> implementationClass;
|
||||
if ( Class.class.isInstance( strategyReference ) ) {
|
||||
implementationClass = (Class<RegionFactory>) strategyReference;
|
||||
}
|
||||
else {
|
||||
implementationClass = strategySelector.selectStrategyImplementor(
|
||||
RegionFactory.class,
|
||||
strategyReference.toString()
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
return new StrategyCreatorRegionFactoryImpl( properties ).create( implementationClass );
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new StrategySelectionException(
|
||||
String.format( "Could not instantiate named strategy class [%s]", implementationClass.getName() ),
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map legacy names unto the new corollary.
|
||||
*
|
||||
|
|
|
@ -41,7 +41,13 @@ public class StrategyCreatorRegionFactoryImpl implements StrategyCreator<RegionF
|
|||
catch ( NoSuchMethodException e ) {
|
||||
log.debugf( "RegionFactory impl [%s] did not provide constructor accepting Properties", strategyClass.getName() );
|
||||
}
|
||||
catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
|
||||
catch ( IllegalAccessException e ) {
|
||||
throw new ServiceException( "Unable to call constructor of RegionFactory impl [" + strategyClass.getName() + "]", e );
|
||||
}
|
||||
catch ( InstantiationException e ) {
|
||||
throw new ServiceException( "Unable to call constructor of RegionFactory impl [" + strategyClass.getName() + "]", e );
|
||||
}
|
||||
catch ( InvocationTargetException e ) {
|
||||
throw new ServiceException( "Unable to call constructor of RegionFactory impl [" + strategyClass.getName() + "]", e );
|
||||
}
|
||||
|
||||
|
@ -53,7 +59,13 @@ public class StrategyCreatorRegionFactoryImpl implements StrategyCreator<RegionF
|
|||
catch ( NoSuchMethodException e ) {
|
||||
log.debugf( "RegionFactory impl [%s] did not provide constructor accepting Properties", strategyClass.getName() );
|
||||
}
|
||||
catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
|
||||
catch ( IllegalAccessException e ) {
|
||||
throw new ServiceException( "Unable to call constructor of RegionFactory impl [" + strategyClass.getName() + "]", e );
|
||||
}
|
||||
catch ( InstantiationException e ) {
|
||||
throw new ServiceException( "Unable to call constructor of RegionFactory impl [" + strategyClass.getName() + "]", e );
|
||||
}
|
||||
catch ( InvocationTargetException e ) {
|
||||
throw new ServiceException( "Unable to call constructor of RegionFactory impl [" + strategyClass.getName() + "]", e );
|
||||
}
|
||||
|
||||
|
@ -61,7 +73,10 @@ public class StrategyCreatorRegionFactoryImpl implements StrategyCreator<RegionF
|
|||
try {
|
||||
return strategyClass.newInstance();
|
||||
}
|
||||
catch (IllegalAccessException | InstantiationException e) {
|
||||
catch ( IllegalAccessException e ) {
|
||||
throw new ServiceException( "Unable to call constructor of RegionFactory impl [" + strategyClass.getName() + "]", e );
|
||||
}
|
||||
catch ( InstantiationException e ) {
|
||||
throw new ServiceException( "Unable to call constructor of RegionFactory impl [" + strategyClass.getName() + "]", e );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,14 +59,14 @@ public class SharedRegionTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
// now try to load a ZipCodes using the same id : should just return null rather than blow up :)
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
ZipCodes zc = s.find( ZipCodes.class, 1 );
|
||||
ZipCodes zc = s.get( ZipCodes.class, 1 );
|
||||
assertNull( zc );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
s.find( ZipCodes.class, 1 );
|
||||
s.get( ZipCodes.class, 1 );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
|
|
@ -304,7 +304,11 @@ public class InfinispanRegionFactory implements RegionFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CollectionRegion buildCollectionRegion(String regionName, Map<String, Object> configValues, CacheDataDescription metadata) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public CollectionRegion buildCollectionRegion(
|
||||
String regionName,
|
||||
Properties properties,
|
||||
CacheDataDescription metadata) throws CacheException {
|
||||
if ( log.isDebugEnabled() ) {
|
||||
log.debug( "Building collection cache region [" + regionName + "]" );
|
||||
}
|
||||
|
@ -316,15 +320,7 @@ public class InfinispanRegionFactory implements RegionFactory {
|
|||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public CollectionRegion buildCollectionRegion(
|
||||
String regionName,
|
||||
Properties properties,
|
||||
CacheDataDescription metadata) throws CacheException {
|
||||
return buildCollectionRegion( regionName, (Map) properties, metadata );
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityRegion buildEntityRegion(String regionName, Map<String, Object> configValues, CacheDataDescription metadata) {
|
||||
public EntityRegion buildEntityRegion(String regionName, Properties properties, CacheDataDescription metadata) {
|
||||
if ( log.isDebugEnabled() ) {
|
||||
log.debugf(
|
||||
"Building entity cache region [%s] (mutable=%s, versioned=%s)",
|
||||
|
@ -341,12 +337,7 @@ public class InfinispanRegionFactory implements RegionFactory {
|
|||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public EntityRegion buildEntityRegion(String regionName, Properties properties, CacheDataDescription metadata) {
|
||||
return buildEntityRegion( regionName, (Map) properties, metadata );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NaturalIdRegion buildNaturalIdRegion(String regionName, Map<String, Object> configValues, CacheDataDescription metadata) {
|
||||
public NaturalIdRegion buildNaturalIdRegion(String regionName, Properties properties, CacheDataDescription metadata) {
|
||||
if ( log.isDebugEnabled() ) {
|
||||
log.debug("Building natural id cache region [" + regionName + "]");
|
||||
}
|
||||
|
@ -358,12 +349,7 @@ public class InfinispanRegionFactory implements RegionFactory {
|
|||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public NaturalIdRegion buildNaturalIdRegion(String regionName, Properties properties, CacheDataDescription metadata) {
|
||||
return buildNaturalIdRegion( regionName, (Map) properties, metadata );
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryResultsRegion buildQueryResultsRegion(String regionName, Map<String, Object> configValues) {
|
||||
public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties properties) {
|
||||
if ( log.isDebugEnabled() ) {
|
||||
log.debug( "Building query results cache region [" + regionName + "]" );
|
||||
}
|
||||
|
@ -376,12 +362,7 @@ public class InfinispanRegionFactory implements RegionFactory {
|
|||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties properties) {
|
||||
return buildQueryResultsRegion( regionName, (Map) properties );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimestampsRegion buildTimestampsRegion(String regionName, Map<String, Object> configValues) {
|
||||
public TimestampsRegion buildTimestampsRegion(String regionName, Properties properties) {
|
||||
if ( log.isDebugEnabled() ) {
|
||||
log.debug( "Building timestamps cache region [" + regionName + "]" );
|
||||
}
|
||||
|
@ -391,12 +372,6 @@ public class InfinispanRegionFactory implements RegionFactory {
|
|||
return region;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public TimestampsRegion buildTimestampsRegion(String regionName, Properties properties) {
|
||||
return buildTimestampsRegion( regionName, (Map) properties );
|
||||
}
|
||||
|
||||
protected TimestampsRegionImpl createTimestampsRegion(
|
||||
AdvancedCache cache, String regionName) {
|
||||
if ( Caches.isClustered(cache) ) {
|
||||
|
|
Loading…
Reference in New Issue