use of org.hibernate.cache.CacheException in project hibernate-orm by hibernate.
the class EhCacheRegionFactory method stop.
@Override
public void stop() {
try {
if (manager != null) {
mbeanRegistrationHelper.unregisterMBean();
manager.shutdown();
manager = null;
}
} catch (net.sf.ehcache.CacheException e) {
throw new CacheException(e);
}
}
use of org.hibernate.cache.CacheException in project hibernate-orm by hibernate.
the class EhCacheRegionFactory method start.
@Override
public void start(SessionFactoryOptions settings, Properties properties) throws CacheException {
this.settings = settings;
if (manager != null) {
LOG.attemptToRestartAlreadyStartedEhCacheProvider();
return;
}
try {
String configurationResourceName = null;
if (properties != null) {
configurationResourceName = (String) properties.get(NET_SF_EHCACHE_CONFIGURATION_RESOURCE_NAME);
}
if (configurationResourceName == null || configurationResourceName.length() == 0) {
final Configuration configuration = ConfigurationFactory.parseConfiguration();
manager = new CacheManager(configuration);
} else {
final URL url = loadResource(configurationResourceName);
final Configuration configuration = HibernateEhcacheUtils.loadAndCorrectConfiguration(url);
manager = new CacheManager(configuration);
}
mbeanRegistrationHelper.registerMBean(manager, properties);
} 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 hibernate-orm by hibernate.
the class JCacheRegionFactoryTest method testRemainsStoppedOnFailure.
@Test
public void testRemainsStoppedOnFailure() {
final Properties properties = new Properties();
properties.setProperty(JCacheRegionFactory.CONFIG_URI, "_fil:");
try {
factory.start(null, properties);
fail();
} catch (CacheException e) {
assertThat(factory.isStarted(), is(false));
}
properties.setProperty(JCacheRegionFactory.PROVIDER, "no.such.thing");
try {
factory.start(null, properties);
fail();
} catch (javax.cache.CacheException e) {
assertThat(factory.isStarted(), is(false));
}
}
use of org.hibernate.cache.CacheException in project wildfly by wildfly.
the class SharedInfinispanRegionFactory method createCacheManager.
@Override
protected EmbeddedCacheManager createCacheManager(Properties properties, final ServiceRegistry serviceRegistry) {
String container = properties.getProperty(CACHE_CONTAINER, DEFAULT_CACHE_CONTAINER);
Properties cacheSettings = new Properties();
cacheSettings.put(HibernateSecondLevelCache.CONTAINER, container);
try {
// Get the (shared) cache manager for JPA application use
wrapper = Notification.startCache(Classification.INFINISPAN, cacheSettings);
return (EmbeddedCacheManager) wrapper.getValue();
} catch (Exception e) {
throw new CacheException(e);
}
}
use of org.hibernate.cache.CacheException in project hibernate-orm by hibernate.
the class JCacheRegionFactory method resolveCacheManager.
@SuppressWarnings("WeakerAccess")
protected CacheManager resolveCacheManager(SessionFactoryOptions settings, Map properties) {
final Object explicitCacheManager = properties.get(ConfigSettings.CACHE_MANAGER);
if (explicitCacheManager != null) {
return useExplicitCacheManager(settings, explicitCacheManager);
}
final CachingProvider cachingProvider = getCachingProvider(properties);
final CacheManager cacheManager;
final String cacheManagerUri = getProp(properties, ConfigSettings.CONFIG_URI);
if (cacheManagerUri != null) {
URI uri;
try {
uri = new URI(cacheManagerUri);
} catch (URISyntaxException e) {
throw new CacheException("Couldn't create URI from " + cacheManagerUri, e);
}
// todo (5.3) : shouldn't this use Hibernate's AggregatedClassLoader?
cacheManager = cachingProvider.getCacheManager(uri, cachingProvider.getDefaultClassLoader());
} else {
cacheManager = cachingProvider.getCacheManager();
}
return cacheManager;
}
Aggregations