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);
}
}
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;
}
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);
}
}
}
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();
}
Aggregations