Search in sources :

Example 1 with RegionFactory

use of org.hibernate.cache.spi.RegionFactory in project hibernate-orm by hibernate.

the class JndiInfinispanRegionFactoryTestCase method testConstruction.

@Test
public void testConstruction() {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.CACHE_REGION_FACTORY, JndiInfinispanRegionFactory.class.getName()).build();
    try {
        RegionFactory regionFactory = ssr.getService(RegionFactory.class);
        assertTyping(JndiInfinispanRegionFactory.class, regionFactory);
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) RegionFactory(org.hibernate.cache.spi.RegionFactory) JndiInfinispanRegionFactory(org.hibernate.cache.infinispan.JndiInfinispanRegionFactory) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 2 with RegionFactory

use of org.hibernate.cache.spi.RegionFactory in project hibernate-orm by hibernate.

the class RegionFactoryInitiator method initiateService.

@Override
@SuppressWarnings({ "unchecked" })
public RegionFactory initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
    final Properties p = new Properties();
    if (configurationValues != null) {
        p.putAll(configurationValues);
    }
    final boolean useSecondLevelCache = ConfigurationHelper.getBoolean(AvailableSettings.USE_SECOND_LEVEL_CACHE, configurationValues, true);
    final boolean useQueryCache = ConfigurationHelper.getBoolean(AvailableSettings.USE_QUERY_CACHE, configurationValues);
    RegionFactory regionFactory = NoCachingRegionFactory.INSTANCE;
    // or query cache enabled.  Note that useSecondLevelCache is enabled by default
    if (useSecondLevelCache || useQueryCache) {
        final Object setting = configurationValues != null ? configurationValues.get(AvailableSettings.CACHE_REGION_FACTORY) : null;
        regionFactory = registry.getService(StrategySelector.class).resolveStrategy(RegionFactory.class, setting, NoCachingRegionFactory.INSTANCE, new StrategyCreatorRegionFactoryImpl(p));
    }
    LOG.debugf("Cache region factory : %s", regionFactory.getClass().getName());
    return regionFactory;
}
Also used : RegionFactory(org.hibernate.cache.spi.RegionFactory) Properties(java.util.Properties)

Example 3 with RegionFactory

use of org.hibernate.cache.spi.RegionFactory in project hibernate-orm by hibernate.

the class AbstractGeneralDataRegionTest method withSessionFactoriesAndRegions.

protected void withSessionFactoriesAndRegions(int num, SFRConsumer consumer) throws Exception {
    StandardServiceRegistryBuilder ssrb = createStandardServiceRegistryBuilder().applySetting(AvailableSettings.CACHE_REGION_FACTORY, TestInfinispanRegionFactory.class.getName());
    Properties properties = CacheTestUtil.toProperties(ssrb.getSettings());
    List<StandardServiceRegistry> registries = new ArrayList<>();
    List<SessionFactory> sessionFactories = new ArrayList<>();
    List<GeneralDataRegion> regions = new ArrayList<>();
    for (int i = 0; i < num; ++i) {
        StandardServiceRegistry registry = ssrb.build();
        registries.add(registry);
        SessionFactory sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
        sessionFactories.add(sessionFactory);
        InfinispanRegionFactory regionFactory = (InfinispanRegionFactory) registry.getService(RegionFactory.class);
        GeneralDataRegion region = (GeneralDataRegion) createRegion(regionFactory, getStandardRegionName(REGION_PREFIX), properties, null);
        regions.add(region);
    }
    try {
        consumer.accept(sessionFactories, regions);
    } finally {
        for (SessionFactory sessionFactory : sessionFactories) {
            sessionFactory.close();
        }
        for (StandardServiceRegistry registry : registries) {
            StandardServiceRegistryBuilder.destroy(registry);
        }
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) TestInfinispanRegionFactory(org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) ArrayList(java.util.ArrayList) MetadataSources(org.hibernate.boot.MetadataSources) Properties(java.util.Properties) BaseGeneralDataRegion(org.hibernate.cache.infinispan.impl.BaseGeneralDataRegion) GeneralDataRegion(org.hibernate.cache.spi.GeneralDataRegion) InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) RegionFactory(org.hibernate.cache.spi.RegionFactory) TestInfinispanRegionFactory(org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory) TestInfinispanRegionFactory(org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Example 4 with RegionFactory

use of org.hibernate.cache.spi.RegionFactory in project hibernate-orm by hibernate.

the class CacheTestSupport method cleanUp.

private void cleanUp() {
    for (Iterator it = factories.iterator(); it.hasNext(); ) {
        try {
            ((RegionFactory) it.next()).stop();
        } catch (Exception e) {
            storeException(e);
        } finally {
            it.remove();
        }
    }
    factories.clear();
    for (Iterator it = caches.iterator(); it.hasNext(); ) {
        try {
            Cache cache = (Cache) it.next();
            cache.stop();
        } catch (Exception e) {
            storeException(e);
        } finally {
            it.remove();
        }
    }
    caches.clear();
}
Also used : RegionFactory(org.hibernate.cache.spi.RegionFactory) Iterator(java.util.Iterator) Cache(org.infinispan.Cache)

Aggregations

RegionFactory (org.hibernate.cache.spi.RegionFactory)4 Properties (java.util.Properties)2 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)2 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 SessionFactory (org.hibernate.SessionFactory)1 MetadataSources (org.hibernate.boot.MetadataSources)1 InfinispanRegionFactory (org.hibernate.cache.infinispan.InfinispanRegionFactory)1 JndiInfinispanRegionFactory (org.hibernate.cache.infinispan.JndiInfinispanRegionFactory)1 BaseGeneralDataRegion (org.hibernate.cache.infinispan.impl.BaseGeneralDataRegion)1 GeneralDataRegion (org.hibernate.cache.spi.GeneralDataRegion)1 TestInfinispanRegionFactory (org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory)1 Cache (org.infinispan.Cache)1 Test (org.junit.Test)1