use of org.hibernate.cache.CacheException in project hibernate-orm by hibernate.
the class AbstractEhcacheRegionFactory method getCache.
private Ehcache getCache(String name) throws CacheException {
try {
Ehcache cache = manager.getEhcache(name);
if (cache == null) {
LOG.unableToFindEhCacheConfiguration(name);
manager.addCache(name);
cache = manager.getEhcache(name);
LOG.debug("started EHCache region: " + name);
}
return cache;
} catch (net.sf.ehcache.CacheException e) {
throw new CacheException(e);
}
}
use of org.hibernate.cache.CacheException in project hibernate-orm by hibernate.
the class SingletonEhCacheRegionFactory method start.
@Override
public void start(SessionFactoryOptions settings, Properties properties) throws CacheException {
this.settings = settings;
try {
String configurationResourceName = null;
if (properties != null) {
configurationResourceName = (String) properties.get(NET_SF_EHCACHE_CONFIGURATION_RESOURCE_NAME);
}
if (configurationResourceName == null || configurationResourceName.length() == 0) {
manager = CacheManager.create();
REFERENCE_COUNT.incrementAndGet();
} else {
URL url;
try {
url = new URL(configurationResourceName);
} catch (MalformedURLException e) {
if (!configurationResourceName.startsWith("/")) {
configurationResourceName = "/" + configurationResourceName;
LOG.debugf("prepending / to %s. It should be placed in the root of the classpath rather than in a package.", configurationResourceName);
}
url = loadResource(configurationResourceName);
}
final Configuration configuration = HibernateEhcacheUtils.loadAndCorrectConfiguration(url);
manager = CacheManager.create(configuration);
REFERENCE_COUNT.incrementAndGet();
}
mbeanRegistrationHelper.registerMBean(manager, properties);
} catch (net.sf.ehcache.CacheException e) {
throw new CacheException(e);
}
}
use of org.hibernate.cache.CacheException in project hibernate-orm by hibernate.
the class EhcacheGeneralDataRegion method put.
@Override
public void put(SharedSessionContractImplementor session, Object key, Object value) throws CacheException {
LOG.debugf("key: %s value: %s", key, value);
try {
final Element element = new Element(key, value);
getCache().put(element);
} catch (IllegalArgumentException e) {
throw new CacheException(e);
} catch (IllegalStateException e) {
throw new CacheException(e);
} catch (net.sf.ehcache.CacheException e) {
if (e instanceof NonStopCacheException) {
HibernateNonstopCacheExceptionHandler.getInstance().handleNonstopCacheException((NonStopCacheException) e);
} else {
throw new CacheException(e);
}
}
}
use of org.hibernate.cache.CacheException in project hibernate-orm by hibernate.
the class EhcacheTransactionalDataRegion method put.
/**
* Map the given value to the given key, replacing any existing mapping for this key
*
* @param key The cache key
* @param value The data to cache
*
* @throws CacheException Indicates a problem accessing the cache
*/
public final void put(Object key, Object value) throws CacheException {
try {
final Element element = new Element(key, value);
getCache().put(element);
} catch (IllegalArgumentException e) {
throw new CacheException(e);
} catch (IllegalStateException e) {
throw new CacheException(e);
} catch (net.sf.ehcache.CacheException e) {
if (e instanceof NonStopCacheException) {
HibernateNonstopCacheExceptionHandler.getInstance().handleNonstopCacheException((NonStopCacheException) e);
} else {
throw new CacheException(e);
}
}
}
use of org.hibernate.cache.CacheException in project hibernate-orm by hibernate.
the class InfinispanRegionFactory method start.
@Override
public void start(SessionFactoryOptions settings, Properties properties) throws CacheException {
log.debug("Starting Infinispan region factory");
// determine the CacheKeysFactory to use...
this.cacheKeysFactory = determineCacheKeysFactory(settings, properties);
try {
this.settings = settings;
transactionManagerlookup = createTransactionManagerLookup(settings, properties);
transactionManager = transactionManagerlookup.getTransactionManager();
final Enumeration keys = properties.propertyNames();
while (keys.hasMoreElements()) {
final String key = (String) keys.nextElement();
int prefixLoc;
if ((prefixLoc = key.indexOf(PREFIX)) != -1) {
parseProperty(prefixLoc, key, extractProperty(key, properties));
}
}
defaultConfiguration = loadConfiguration(settings.getServiceRegistry(), DEF_INFINISPAN_CONFIG_RESOURCE);
manager = createCacheManager(properties, settings.getServiceRegistry());
if (!manager.getCacheManagerConfiguration().isClustered()) {
// If we got non-clustered cache manager, use non-clustered (local) configuration as defaults
// for the data types
defaultConfiguration = loadConfiguration(settings.getServiceRegistry(), INFINISPAN_CONFIG_LOCAL_RESOURCE);
}
defineDataTypeCacheConfigurations();
} catch (CacheException ce) {
throw ce;
} catch (Throwable t) {
throw log.unableToStart(t);
}
}
Aggregations