Search in sources :

Example 16 with CacheException

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

Example 17 with CacheException

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

Example 18 with CacheException

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);
        }
    }
}
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 19 with CacheException

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

Example 20 with CacheException

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

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