[HHH-5260] (Allow query region name specific eviction settings) Ported to trunk.

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19901 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Galder Zamarreno 2010-07-05 17:36:04 +00:00
parent 6e57774e42
commit 80b082086e
3 changed files with 51 additions and 9 deletions

View File

@ -99,7 +99,7 @@ public class InfinispanRegionFactory implements RegionFactory {
/**
* Name of the configuration that should be used for timestamp caches.
*
* @see #DEF_TS_RESOURCE
* @see #DEF_TIMESTAMPS_RESOURCE
*/
public static final String TIMESTAMPS_CACHE_RESOURCE_PROP = PREFIX + TIMESTAMPS_KEY + CONFIG_SUFFIX;
@ -113,7 +113,7 @@ public class InfinispanRegionFactory implements RegionFactory {
public static final String QUERY_CACHE_RESOURCE_PROP = PREFIX + QUERY_KEY + CONFIG_SUFFIX;
/**
* Default value for {@link #INFINISPAN_RESOURCE_PROP}. Specifies the "infinispan-configs.xml" file in this package.
* Default value for {@link #INFINISPAN_CONFIG_RESOURCE_PROP}. Specifies the "infinispan-configs.xml" file in this package.
*/
public static final String DEF_INFINISPAN_CONFIG_RESOURCE = "org/hibernate/cache/infinispan/builder/infinispan-configs.xml";
@ -184,7 +184,12 @@ public class InfinispanRegionFactory implements RegionFactory {
throws CacheException {
if (log.isDebugEnabled()) log.debug("Building query results cache region [" + regionName + "]");
String cacheName = typeOverrides.get(QUERY_KEY).getCacheName();
CacheAdapter cacheAdapter = CacheAdapterImpl.newInstance(manager.getCache(cacheName));
// If region name is not default one, lookup a cache for that region name
if (!regionName.equals("org.hibernate.cache.StandardQueryCache"))
cacheName = regionName;
Cache cache = getCache(cacheName, QUERY_KEY, properties);
CacheAdapter cacheAdapter = CacheAdapterImpl.newInstance(cache);
QueryResultsRegionImpl region = new QueryResultsRegionImpl(cacheAdapter, regionName, properties, transactionManager, this);
region.start();
return region;
@ -369,7 +374,7 @@ public class InfinispanRegionFactory implements RegionFactory {
String templateCacheName = null;
Configuration regionCacheCfg = null;
if (regionOverride != null) {
if (log.isDebugEnabled()) log.debug("Entity cache region specific configuration exists: " + regionOverride);
if (log.isDebugEnabled()) log.debug("Cache region specific configuration exists: " + regionOverride);
regionOverride = overrideStatisticsIfPresent(regionOverride, properties);
regionCacheCfg = regionOverride.createInfinispanConfiguration();
String cacheName = regionOverride.getCacheName();
@ -412,4 +417,4 @@ public class InfinispanRegionFactory implements RegionFactory {
}
return override;
}
}
}

View File

@ -415,6 +415,32 @@ public class InfinispanRegionFactoryTestCase extends TestCase {
}
}
public void testBuildQueryRegionWithCustomRegionName() {
final String queryRegionName = "myquery";
Properties p = new Properties();
InfinispanRegionFactory factory = new InfinispanRegionFactory();
p.setProperty("hibernate.cache.infinispan.myquery.cfg", "timestamps-none-eviction");
p.setProperty("hibernate.cache.infinispan.myquery.eviction.strategy", "FIFO");
p.setProperty("hibernate.cache.infinispan.myquery.eviction.wake_up_interval", "2222");
p.setProperty("hibernate.cache.infinispan.myquery.eviction.max_entries", "11111");
factory.start(null, p);
CacheManager manager = factory.getCacheManager();
manager.getGlobalConfiguration().setTransportClass(null);
try {
assertTrue(factory.getDefinedConfigurations().contains("local-query"));
QueryResultsRegionImpl region = (QueryResultsRegionImpl) factory.buildQueryResultsRegion(queryRegionName, p);
assertNotNull(factory.getTypeOverrides().get(queryRegionName));
assertTrue(factory.getDefinedConfigurations().contains(queryRegionName));
CacheAdapter cache = region.getCacheAdapter();
Configuration cacheCfg = cache.getConfiguration();
assertEquals(EvictionStrategy.FIFO, cacheCfg.getEvictionStrategy());
assertEquals(2222, cacheCfg.getEvictionWakeUpInterval());
assertEquals(11111, cacheCfg.getEvictionMaxEntries());
} finally {
factory.stop();
}
}
public void testEnableStatistics() {
Properties p = new Properties();
p.setProperty("hibernate.cache.infinispan.statistics", "true");

View File

@ -88,6 +88,7 @@ public class IsolatedClassLoaderTest extends DualNodeTestCase {
protected void standardConfigure(Configuration cfg) {
super.standardConfigure(cfg);
cfg.setProperty(InfinispanRegionFactory.QUERY_CACHE_RESOURCE_PROP, "replicated-query");
cfg.setProperty("hibernate.cache.infinispan.AccountRegion.cfg", "replicated-query");
}
@ -164,15 +165,25 @@ public class IsolatedClassLoaderTest extends DualNodeTestCase {
// Bind a listener to the "local" cache
// Our region factory makes its CacheManager available to us
CacheManager localManager = ClusterAwareRegionFactory.getCacheManager(DualNodeTestCase.LOCAL);
localQueryCache = localManager.getCache("replicated-query");
// Bind a listener to the "remote" cache
CacheManager remoteManager = ClusterAwareRegionFactory.getCacheManager(DualNodeTestCase.REMOTE);
String cacheName;
if (useNamedRegion) {
cacheName = "AccountRegion"; // As defined by ClassLoaderTestDAO via calls to query.setCacheRegion
// Define cache configurations for region early to avoid ending up with local caches for this region
localManager.defineConfiguration(cacheName, "replicated-query", new org.infinispan.config.Configuration());
remoteManager.defineConfiguration(cacheName, "replicated-query", new org.infinispan.config.Configuration());
} else {
cacheName = "replicated-query";
}
localQueryCache = localManager.getCache(cacheName);
localQueryListener = new CacheAccessListener();
localQueryCache.addListener(localQueryListener);
TransactionManager localTM = DualNodeJtaTransactionManagerImpl.getInstance(DualNodeTestCase.LOCAL);
// Bind a listener to the "remote" cache
CacheManager remoteManager = ClusterAwareRegionFactory.getCacheManager(DualNodeTestCase.REMOTE);
remoteQueryCache = remoteManager.getCache("replicated-query");
remoteQueryCache = remoteManager.getCache(cacheName);
remoteQueryListener = new CacheAccessListener();
remoteQueryCache.addListener(remoteQueryListener);