Search in sources :

Example 1 with CacheException

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);
    }
}
Also used : CacheException(org.hibernate.cache.CacheException)

Example 2 with CacheException

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);
        }
    }
}
Also used : Configuration(net.sf.ehcache.config.Configuration) CacheException(org.hibernate.cache.CacheException) CacheManager(net.sf.ehcache.CacheManager) URL(java.net.URL)

Example 3 with CacheException

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));
    }
}
Also used : CacheException(org.hibernate.cache.CacheException) Properties(java.util.Properties) Test(org.junit.Test)

Example 4 with CacheException

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);
    }
}
Also used : CacheException(org.hibernate.cache.CacheException) Properties(java.util.Properties) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) CacheException(org.hibernate.cache.CacheException)

Example 5 with CacheException

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;
}
Also used : CacheException(org.hibernate.cache.CacheException) CacheManager(javax.cache.CacheManager) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) CachingProvider(javax.cache.spi.CachingProvider)

Aggregations

CacheException (org.hibernate.cache.CacheException)28 Properties (java.util.Properties)11 URL (java.net.URL)4 Configuration (net.sf.ehcache.config.Configuration)4 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)4 CacheManager (javax.cache.CacheManager)3 Element (net.sf.ehcache.Element)3 NonStopCacheException (net.sf.ehcache.constructs.nonstop.NonStopCacheException)3 DatabaseRedisClient (com.publiccms.common.redis.DatabaseRedisClient)2 MalformedURLException (java.net.MalformedURLException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 CachingProvider (javax.cache.spi.CachingProvider)2 InitialContext (javax.naming.InitialContext)2 NamingException (javax.naming.NamingException)2 CacheManager (net.sf.ehcache.CacheManager)2 Test (org.junit.Test)2 RedissonClient (org.redisson.api.RedissonClient)2 Config (org.redisson.config.Config)2 Enumeration (java.util.Enumeration)1