HHH-7943 Corrected RegionFactoryInitiator for failing inifinispan tests

This commit is contained in:
Brett Meyer 2013-05-01 15:04:16 -04:00
parent 60513d2e2e
commit 257d8ee370
1 changed files with 28 additions and 8 deletions

View File

@ -24,7 +24,9 @@
package org.hibernate.cache.internal; package org.hibernate.cache.internal;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import org.hibernate.HibernateException;
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.cache.spi.RegionFactory; import org.hibernate.cache.spi.RegionFactory;
@ -58,21 +60,39 @@ public class RegionFactoryInitiator implements StandardServiceInitiator<RegionFa
@Override @Override
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({ "unchecked" })
public RegionFactory initiateService(Map configurationValues, ServiceRegistryImplementor registry) { 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, boolean useSecondLevelCache = ConfigurationHelper.getBoolean( AvailableSettings.USE_SECOND_LEVEL_CACHE,
configurationValues, true ); configurationValues, true );
boolean useQueryCache = ConfigurationHelper.getBoolean( AvailableSettings.USE_QUERY_CACHE, configurationValues ); 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 // The cache provider is needed when we either have second-level cache enabled
// or query cache enabled. Note that useSecondLevelCache is enabled by default // or query cache enabled. Note that useSecondLevelCache is enabled by default
if ( useSecondLevelCache || useQueryCache ) { final String setting = ConfigurationHelper.getString( AvailableSettings.CACHE_REGION_FACTORY,
final Object setting = configurationValues.get( AvailableSettings.CACHE_REGION_FACTORY ); configurationValues, null );
regionFactory = registry.getService( StrategySelector.class ).resolveDefaultableStrategy( if ( ( useSecondLevelCache || useQueryCache ) && setting != null ) {
RegionFactory.class, setting, NoCachingRegionFactory.INSTANCE ); try {
} Class<? extends RegionFactory> regionFactoryClass = registry.getService( StrategySelector.class )
else { .selectStrategyImplementor( RegionFactory.class, setting );
regionFactory = NoCachingRegionFactory.INSTANCE; 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() ); LOG.debugf( "Cache region factory : %s", regionFactory.getClass().getName() );