Search in sources :

Example 16 with CacheManager

use of javax.cache.CacheManager 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)

Example 17 with CacheManager

use of javax.cache.CacheManager in project hibernate-orm by hibernate.

the class TestHelper method buildStandardSessionFactory.

public static SessionFactoryImplementor buildStandardSessionFactory(boolean preBuildCaches, boolean prefixCaches) {
    if (preBuildCaches) {
        final CacheManager cacheManager = locateStandardCacheManager();
        for (String regionName : entityRegionNames) {
            createCache(cacheManager, regionName, prefixCaches);
        }
        for (String regionName : collectionRegionNames) {
            createCache(cacheManager, regionName, prefixCaches);
        }
        createCache(cacheManager, TimestampsRegion.class.getName(), prefixCaches);
        createCache(cacheManager, QueryResultsRegion.class.getName(), prefixCaches);
    }
    final StandardServiceRegistryBuilder ssrb = getStandardServiceRegistryBuilder();
    final StandardServiceRegistry ssr = ssrb.build();
    return (SessionFactoryImplementor) new MetadataSources(ssr).buildMetadata().buildSessionFactory();
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) MetadataSources(org.hibernate.boot.MetadataSources) JCacheHelper.locateStandardCacheManager(org.hibernate.cache.jcache.JCacheHelper.locateStandardCacheManager) CacheManager(javax.cache.CacheManager) TimestampsRegion(org.hibernate.cache.spi.TimestampsRegion) QueryResultsRegion(org.hibernate.cache.spi.QueryResultsRegion) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Example 18 with CacheManager

use of javax.cache.CacheManager in project cache2k by cache2k.

the class CacheManagerTest method getNullTypeCacheRequest.

@Test(expected = NullPointerException.class)
public void getNullTypeCacheRequest() {
    CacheManager cacheManager = getCacheManager();
    MutableConfiguration config = new MutableConfiguration();
    cacheManager.createCache("untyped-cache", config);
    Cache cache = cacheManager.getCache("untyped-cache", null, null);
}
Also used : CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Cache(javax.cache.Cache) Test(org.junit.Test)

Example 19 with CacheManager

use of javax.cache.CacheManager in project cache2k by cache2k.

the class CacheManagerTest method createCache_Same.

@Test
public void createCache_Same() {
    String name = "c1";
    CacheManager cacheManager = getCacheManager();
    try {
        cacheManager.createCache(name, new MutableConfiguration());
        Cache cache1 = cacheManager.getCache(name);
        cacheManager.createCache(name, new MutableConfiguration());
        Cache cache2 = cacheManager.getCache(name);
        fail();
    } catch (CacheException exception) {
    // expected
    }
}
Also used : CacheException(javax.cache.CacheException) CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Cache(javax.cache.Cache) Test(org.junit.Test)

Example 20 with CacheManager

use of javax.cache.CacheManager in project cache2k by cache2k.

the class CacheManagerTest method close.

@Test
public void close() {
    CacheManager cacheManager = getCacheManager();
    assertFalse(cacheManager.isClosed());
    cacheManager.close();
    assertTrue(cacheManager.isClosed());
}
Also used : CacheManager(javax.cache.CacheManager) Test(org.junit.Test)

Aggregations

CacheManager (javax.cache.CacheManager)284 Test (org.junit.Test)182 CachingProvider (javax.cache.spi.CachingProvider)113 QuickTest (com.hazelcast.test.annotation.QuickTest)78 HazelcastInstance (com.hazelcast.core.HazelcastInstance)69 MutableConfiguration (javax.cache.configuration.MutableConfiguration)56 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)55 CacheConfig (com.hazelcast.config.CacheConfig)54 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)50 Cache (javax.cache.Cache)41 URI (java.net.URI)31 AssertTask (com.hazelcast.test.AssertTask)26 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)25 Config (com.hazelcast.config.Config)20 ClientConfig (com.hazelcast.client.config.ClientConfig)17 SlowTest (com.hazelcast.test.annotation.SlowTest)17 Before (org.junit.Before)17 CacheTestSupport.createClientCachingProvider (com.hazelcast.cache.CacheTestSupport.createClientCachingProvider)16 HazelcastCacheManager (com.hazelcast.cache.HazelcastCacheManager)16 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)16