HHH-13090 Allow to use specific cache implementations in Ehcache cache provider
Typically, it allows to use a BlockingCache.
This commit is contained in:
parent
c17e4832a9
commit
736d9dd615
|
@ -11,7 +11,7 @@ import java.net.URL;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import net.sf.ehcache.Cache;
|
import net.sf.ehcache.Ehcache;
|
||||||
import net.sf.ehcache.CacheManager;
|
import net.sf.ehcache.CacheManager;
|
||||||
import net.sf.ehcache.config.Configuration;
|
import net.sf.ehcache.config.Configuration;
|
||||||
import net.sf.ehcache.config.ConfigurationFactory;
|
import net.sf.ehcache.config.ConfigurationFactory;
|
||||||
|
@ -131,7 +131,7 @@ public class EhcacheRegionFactory extends RegionFactoryTemplate {
|
||||||
return regionName;
|
return regionName;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Cache getOrCreateCache(String unqualifiedRegionName, SessionFactoryImplementor sessionFactory) {
|
protected Ehcache getOrCreateCache(String unqualifiedRegionName, SessionFactoryImplementor sessionFactory) {
|
||||||
verifyStarted();
|
verifyStarted();
|
||||||
assert !RegionNameQualifier.INSTANCE.isQualified( unqualifiedRegionName, sessionFactory.getSessionFactoryOptions() );
|
assert !RegionNameQualifier.INSTANCE.isQualified( unqualifiedRegionName, sessionFactory.getSessionFactoryOptions() );
|
||||||
|
|
||||||
|
@ -140,14 +140,14 @@ public class EhcacheRegionFactory extends RegionFactoryTemplate {
|
||||||
sessionFactory.getSessionFactoryOptions()
|
sessionFactory.getSessionFactoryOptions()
|
||||||
);
|
);
|
||||||
|
|
||||||
final Cache cache = cacheManager.getCache( qualifiedRegionName );
|
final Ehcache cache = cacheManager.getEhcache( qualifiedRegionName );
|
||||||
if ( cache == null ) {
|
if ( cache == null ) {
|
||||||
return createCache( qualifiedRegionName );
|
return createCache( qualifiedRegionName );
|
||||||
}
|
}
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Cache createCache(String regionName) {
|
protected Ehcache createCache(String regionName) {
|
||||||
switch ( missingCacheStrategy ) {
|
switch ( missingCacheStrategy ) {
|
||||||
case CREATE_WARN:
|
case CREATE_WARN:
|
||||||
SecondLevelCacheLogger.INSTANCE.missingCacheCreated(
|
SecondLevelCacheLogger.INSTANCE.missingCacheCreated(
|
||||||
|
@ -155,10 +155,10 @@ public class EhcacheRegionFactory extends RegionFactoryTemplate {
|
||||||
ConfigSettings.MISSING_CACHE_STRATEGY, MissingCacheStrategy.CREATE.getExternalRepresentation()
|
ConfigSettings.MISSING_CACHE_STRATEGY, MissingCacheStrategy.CREATE.getExternalRepresentation()
|
||||||
);
|
);
|
||||||
cacheManager.addCache( regionName );
|
cacheManager.addCache( regionName );
|
||||||
return cacheManager.getCache( regionName );
|
return cacheManager.getEhcache( regionName );
|
||||||
case CREATE:
|
case CREATE:
|
||||||
cacheManager.addCache( regionName );
|
cacheManager.addCache( regionName );
|
||||||
return cacheManager.getCache( regionName );
|
return cacheManager.getEhcache( regionName );
|
||||||
case FAIL:
|
case FAIL:
|
||||||
throw new CacheException( "On-the-fly creation of Ehcache Cache objects is not supported [" + regionName + "]" );
|
throw new CacheException( "On-the-fly creation of Ehcache Cache objects is not supported [" + regionName + "]" );
|
||||||
default:
|
default:
|
||||||
|
@ -171,13 +171,14 @@ public class EhcacheRegionFactory extends RegionFactoryTemplate {
|
||||||
unqualifiedRegionName,
|
unqualifiedRegionName,
|
||||||
sessionFactory.getSessionFactoryOptions()
|
sessionFactory.getSessionFactoryOptions()
|
||||||
);
|
);
|
||||||
return cacheManager.getCache( qualifiedRegionName ) != null;
|
return cacheManager.getEhcache( qualifiedRegionName ) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
// Lifecycle
|
// Lifecycle
|
||||||
|
|
||||||
|
@Override
|
||||||
protected boolean isStarted() {
|
protected boolean isStarted() {
|
||||||
return super.isStarted() && cacheManager != null;
|
return super.isStarted() && cacheManager != null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.cache.ehcache.internal;
|
package org.hibernate.cache.ehcache.internal;
|
||||||
|
|
||||||
import net.sf.ehcache.Cache;
|
import net.sf.ehcache.Ehcache;
|
||||||
import net.sf.ehcache.Element;
|
import net.sf.ehcache.Element;
|
||||||
import net.sf.ehcache.constructs.nonstop.NonStopCacheException;
|
import net.sf.ehcache.constructs.nonstop.NonStopCacheException;
|
||||||
import net.sf.ehcache.hibernate.nonstop.HibernateNonstopCacheExceptionHandler;
|
import net.sf.ehcache.hibernate.nonstop.HibernateNonstopCacheExceptionHandler;
|
||||||
|
@ -25,14 +25,14 @@ import org.jboss.logging.Logger;
|
||||||
public class StorageAccessImpl implements DomainDataStorageAccess {
|
public class StorageAccessImpl implements DomainDataStorageAccess {
|
||||||
private static final Logger LOG = Logger.getLogger( StorageAccessImpl.class );
|
private static final Logger LOG = Logger.getLogger( StorageAccessImpl.class );
|
||||||
|
|
||||||
private final Cache cache;
|
private final Ehcache cache;
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
public StorageAccessImpl(Cache cache) {
|
public StorageAccessImpl(Ehcache cache) {
|
||||||
this.cache = cache;
|
this.cache = cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cache getCache() {
|
public Ehcache getCache() {
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue