use of org.hibernate.cache.CacheException in project hibernate-orm by hibernate.
the class StorageAccessImpl method putIntoCache.
@Override
public void putIntoCache(Object key, Object value, SharedSessionContractImplementor session) {
try {
final Element element = new Element(key, value);
getCache().put(element);
} catch (IllegalArgumentException | 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 EhcacheRegionFactory method useNormalCacheManager.
/**
* Locate the CacheManager during start-up. protected to allow for subclassing
* such as SingletonEhcacheRegionFactory
*/
protected static CacheManager useNormalCacheManager(SessionFactoryOptions settings, Map properties) {
try {
String configurationResourceName = null;
if (properties != null) {
configurationResourceName = (String) properties.get(EHCACHE_CONFIGURATION_RESOURCE_NAME);
}
if (configurationResourceName == null || configurationResourceName.length() == 0) {
final Configuration configuration = ConfigurationFactory.parseConfiguration();
setCacheManagerNameIfNeeded(settings, configuration, properties);
return new CacheManager(configuration);
} else {
final URL url = loadResource(configurationResourceName, settings);
final Configuration configuration = HibernateEhcacheUtils.loadAndCorrectConfiguration(url);
setCacheManagerNameIfNeeded(settings, configuration, properties);
return new CacheManager(configuration);
}
} catch (net.sf.ehcache.CacheException e) {
if (e.getMessage().startsWith("Cannot parseConfiguration CacheManager. Attempt to create a new instance of " + "CacheManager using the diskStorePath")) {
throw new CacheException("Attempt to restart an already started EhCacheRegionFactory. " + "Use sessionFactory.close() between repeated calls to buildSessionFactory. " + "Consider using SingletonEhCacheRegionFactory. Error from ehcache was: " + e.getMessage());
} else {
throw new CacheException(e);
}
}
}
use of org.hibernate.cache.CacheException in project onebusaway-application-modules by camsys.
the class EhCacheProvider method buildCache.
@Override
public Cache buildCache(String name, Properties properties) throws CacheException {
try {
net.sf.ehcache.Ehcache cache = cacheManager.getEhcache(name);
if (cache == null) {
LOG.warn("Could not find a specific ehcache configuration for cache named [" + name + "]; using defaults.");
cacheManager.addCache(name);
cache = cacheManager.getEhcache(name);
EhCacheProvider.LOG.debug("started EHCache region: " + name);
}
return new net.sf.ehcache.hibernate.EhCache(cache);
} catch (net.sf.ehcache.CacheException e) {
throw new CacheException(e);
}
}
use of org.hibernate.cache.CacheException in project PublicCMS-preview by sanluan.
the class RedisRegionFactory method start.
@Override
public void start(SessionFactoryOptions option, Properties properties) throws CacheException {
log.debug("RedisRegionFactory is starting... ");
this.options = option;
try {
if (redisClient == null) {
String configurationResourceName = (String) properties.get("hibernate.redis.configurationResourceName");
if (null != configurationResourceName) {
Properties redisProperties = PropertiesLoaderUtils.loadAllProperties(configurationResourceName);
this.redisClient = new DatabaseRedisClient(RedisUtils.createJedisPool(redisProperties));
}
this.cacheTimestamper = createCacheTimestamper(redisClient, RedisRegionFactory.class.getName());
}
log.info("RedisRegionFactory is started.");
} catch (Exception e) {
log.error("Fail to start RedisRegionFactory.", e);
throw new CacheException(e);
}
}
use of org.hibernate.cache.CacheException in project redisson by redisson.
the class JndiRedissonRegionFactory method createRedissonClient.
@Override
protected RedissonClient createRedissonClient(Properties properties) {
String jndiName = ConfigurationHelper.getString(JNDI_NAME, properties);
if (jndiName == null) {
throw new CacheException(JNDI_NAME + " property not set");
}
Properties jndiProperties = JndiServiceImpl.extractJndiProperties(properties);
InitialContext context = null;
try {
context = new InitialContext(jndiProperties);
return (RedissonClient) context.lookup(jndiName);
} catch (NamingException e) {
throw new CacheException("Unable to locate Redisson instance by name: " + jndiName, e);
} finally {
if (context != null) {
try {
context.close();
} catch (NamingException e) {
throw new CacheException("Unable to close JNDI context", e);
}
}
}
}
Aggregations