Search in sources :

Example 21 with CacheException

use of org.hibernate.cache.CacheException in project wildfly by wildfly.

the class InfinispanRegionFactory method createCacheManager.

@Override
protected EmbeddedCacheManager createCacheManager(Properties properties, final ServiceRegistry serviceRegistry) throws CacheException {
    // Find a suitable service name to represent this session factory instance
    String name = properties.getProperty(AvailableSettings.SESSION_FACTORY_NAME);
    String container = properties.getProperty(CACHE_CONTAINER, DEFAULT_CACHE_CONTAINER);
    HibernateSecondLevelCache.addSecondLevelCacheDependencies(properties, null);
    Properties cacheSettings = new Properties();
    cacheSettings.put(HibernateSecondLevelCache.CACHE_TYPE, CACHE_PRIVATE);
    cacheSettings.put(HibernateSecondLevelCache.CONTAINER, container);
    if (name != null) {
        cacheSettings.put(HibernateSecondLevelCache.NAME, name);
    }
    try {
        // start a private cache for non-JPA use and return the started cache.
        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 22 with CacheException

use of org.hibernate.cache.CacheException in project wildfly by wildfly.

the class InfinispanRegionFactory method createCacheManager.

@Override
protected EmbeddedCacheManager createCacheManager(Properties properties) throws CacheException {
    // Find a suitable service name to represent this session factory instance
    String name = properties.getProperty(AvailableSettings.SESSION_FACTORY_NAME);
    String container = properties.getProperty(CACHE_CONTAINER, DEFAULT_CACHE_CONTAINER);
    HibernateSecondLevelCache.addSecondLevelCacheDependencies(properties, null);
    Properties cacheSettings = new Properties();
    cacheSettings.put(HibernateSecondLevelCache.CACHE_TYPE, CACHE_PRIVATE);
    cacheSettings.put(HibernateSecondLevelCache.CONTAINER, container);
    if (name != null) {
        cacheSettings.put(HibernateSecondLevelCache.NAME, name);
    }
    try {
        // start a private cache for non-JPA use and return the started cache.
        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 23 with CacheException

use of org.hibernate.cache.CacheException in project wildfly by wildfly.

the class SharedInfinispanRegionFactory method createCacheManager.

@Override
protected EmbeddedCacheManager createCacheManager(Properties properties) {
    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 24 with CacheException

use of org.hibernate.cache.CacheException in project PublicCMS-preview by sanluan.

the class SingletonRedisRegionFactory method start.

@Override
public void start(SessionFactoryOptions option, Properties properties) throws CacheException {
    log.debug("SingletonRedisRegionFactory is starting...");
    this.options = option;
    try {
        if (redisClient == null) {
            String configurationResourceName = (String) properties.get("hibernate.redis.configurationResourceName");
            if (CommonUtils.notEmpty(configurationResourceName)) {
                Properties redisProperties = PropertiesLoaderUtils.loadAllProperties(configurationResourceName);
                this.redisClient = new DatabaseRedisClient(RedisUtils.createJedisPool(redisProperties));
            }
            this.cacheTimestamper = createCacheTimestamper(redisClient, SingletonRedisRegionFactory.class.getName());
        }
        referenceCount.incrementAndGet();
        log.info("RedisRegionFactory is started.");
    } catch (Exception 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 25 with CacheException

use of org.hibernate.cache.CacheException in project hibernate-orm by hibernate.

the class SingletonEhcacheRegionFactory method resolveCacheManager.

@Override
protected CacheManager resolveCacheManager(SessionFactoryOptions settings, Map properties) {
    try {
        String configurationResourceName = getOptions().getServiceRegistry().getService(ConfigurationService.class).getSetting(EHCACHE_CONFIGURATION_RESOURCE_NAME, value -> value == null ? null : value.toString());
        if (configurationResourceName == null || configurationResourceName.length() == 0) {
            try {
                REFERENCE_COUNT.incrementAndGet();
                return CacheManager.create();
            } catch (RuntimeException e) {
                REFERENCE_COUNT.decrementAndGet();
                throw e;
            }
        }
        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);
        }
        try {
            REFERENCE_COUNT.incrementAndGet();
            Configuration config = HibernateEhcacheUtils.loadAndCorrectConfiguration(url);
            setCacheManagerNameIfNeeded(settings, config, properties);
            return CacheManager.create(config);
        } catch (RuntimeException e) {
            REFERENCE_COUNT.decrementAndGet();
            throw e;
        }
    } 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) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) URL(java.net.URL)

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