Search in sources :

Example 6 with CacheException

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);
        }
    }
}
Also used : CacheException(org.hibernate.cache.CacheException) NonStopCacheException(net.sf.ehcache.constructs.nonstop.NonStopCacheException) Element(net.sf.ehcache.Element) NonStopCacheException(net.sf.ehcache.constructs.nonstop.NonStopCacheException)

Example 7 with CacheException

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

Example 8 with CacheException

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

Example 9 with CacheException

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);
    }
}
Also used : CacheException(org.hibernate.cache.CacheException) Properties(java.util.Properties) DatabaseRedisClient(com.publiccms.common.redis.DatabaseRedisClient) CacheException(org.hibernate.cache.CacheException)

Example 10 with CacheException

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);
            }
        }
    }
}
Also used : RedissonClient(org.redisson.api.RedissonClient) CacheException(org.hibernate.cache.CacheException) NamingException(javax.naming.NamingException) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext)

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