HHH-7943 Corrected RegionFactoryInitiator for failing inifinispan tests
This commit is contained in:
parent
60513d2e2e
commit
257d8ee370
|
@ -24,7 +24,9 @@
|
|||
package org.hibernate.cache.internal;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.boot.registry.StandardServiceInitiator;
|
||||
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
||||
import org.hibernate.cache.spi.RegionFactory;
|
||||
|
@ -58,21 +60,39 @@ public class RegionFactoryInitiator implements StandardServiceInitiator<RegionFa
|
|||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public RegionFactory initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
|
||||
Properties p = new Properties();
|
||||
if (configurationValues != null) {
|
||||
p.putAll( configurationValues );
|
||||
}
|
||||
|
||||
boolean useSecondLevelCache = ConfigurationHelper.getBoolean( AvailableSettings.USE_SECOND_LEVEL_CACHE,
|
||||
configurationValues, true );
|
||||
boolean useQueryCache = ConfigurationHelper.getBoolean( AvailableSettings.USE_QUERY_CACHE, configurationValues );
|
||||
|
||||
RegionFactory regionFactory;
|
||||
RegionFactory regionFactory = NoCachingRegionFactory.INSTANCE;
|
||||
|
||||
// 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.get( AvailableSettings.CACHE_REGION_FACTORY );
|
||||
regionFactory = registry.getService( StrategySelector.class ).resolveDefaultableStrategy(
|
||||
RegionFactory.class, setting, NoCachingRegionFactory.INSTANCE );
|
||||
}
|
||||
else {
|
||||
regionFactory = NoCachingRegionFactory.INSTANCE;
|
||||
final String setting = ConfigurationHelper.getString( AvailableSettings.CACHE_REGION_FACTORY,
|
||||
configurationValues, null );
|
||||
if ( ( useSecondLevelCache || useQueryCache ) && setting != null ) {
|
||||
try {
|
||||
Class<? extends RegionFactory> regionFactoryClass = registry.getService( StrategySelector.class )
|
||||
.selectStrategyImplementor( RegionFactory.class, setting );
|
||||
try {
|
||||
regionFactory = regionFactoryClass.getConstructor( Properties.class ).newInstance( p );
|
||||
}
|
||||
catch ( NoSuchMethodException e ) {
|
||||
// no constructor accepting Properties found, try no arg constructor
|
||||
LOG.debugf(
|
||||
"%s did not provide constructor accepting java.util.Properties; attempting no-arg constructor.",
|
||||
regionFactoryClass.getSimpleName() );
|
||||
regionFactory = regionFactoryClass.getConstructor().newInstance();
|
||||
}
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
throw new HibernateException( "could not instantiate RegionFactory [" + setting + "]", e );
|
||||
}
|
||||
}
|
||||
|
||||
LOG.debugf( "Cache region factory : %s", regionFactory.getClass().getName() );
|
||||
|
|
Loading…
Reference in New Issue