use of org.hibernate.cache.CacheException in project hibernate-orm by hibernate.
the class StorageAccessTests method testOnTheFlyCreationDisallowed.
@Test
public void testOnTheFlyCreationDisallowed() {
// first, lets make sure that the region name we think is non-existent really does not exist
final CacheManager cacheManager = JCacheHelper.locateStandardCacheManager();
assertThat(cacheManager.getCache(NON_CACHE_NAME), nullValue());
// and now let's try to build the standard testing SessionFactory, without pre-defining caches
try (SessionFactoryImplementor sessionFactory = TestHelper.buildStandardSessionFactory(false)) {
fail();
} catch (ServiceException expected) {
assertTyping(CacheException.class, expected.getCause());
assertThat(expected.getMessage(), CoreMatchers.equalTo("Unable to create requested service [" + org.hibernate.cache.spi.CacheImplementor.class.getName() + "]"));
assertThat(expected.getCause().getMessage(), CoreMatchers.startsWith("On-the-fly creation of JCache Cache objects is not supported"));
} catch (CacheException expected) {
assertThat(expected.getMessage(), CoreMatchers.equalTo("On-the-fly creation of JCache Cache objects is not supported"));
}
}
use of org.hibernate.cache.CacheException in project hibernate-orm by hibernate.
the class RegionFactoryInitiator method resolveRegionFactory.
@SuppressWarnings({ "unchecked", "WeakerAccess" })
protected RegionFactory resolveRegionFactory(Map configurationValues, ServiceRegistryImplementor registry) {
final Properties p = new Properties();
p.putAll(configurationValues);
final Boolean useSecondLevelCache = ConfigurationHelper.getBooleanWrapper(AvailableSettings.USE_SECOND_LEVEL_CACHE, configurationValues, null);
final Boolean useQueryCache = ConfigurationHelper.getBooleanWrapper(AvailableSettings.USE_QUERY_CACHE, configurationValues, null);
// 2) USE_SECOND_LEVEL_CACHE is FALSE and USE_QUERY_CACHE is null
if (useSecondLevelCache != null && useSecondLevelCache == FALSE) {
if (useQueryCache == null || useQueryCache == FALSE) {
return NoCachingRegionFactory.INSTANCE;
}
}
final Object setting = configurationValues.get(AvailableSettings.CACHE_REGION_FACTORY);
final StrategySelector selector = registry.getService(StrategySelector.class);
final Collection<Class<? extends RegionFactory>> implementors = selector.getRegisteredStrategyImplementors(RegionFactory.class);
if (setting == null && implementors.size() != 1) {
// if either are explicitly defined as TRUE we need a RegionFactory
if ((useSecondLevelCache != null && useSecondLevelCache == TRUE) || (useQueryCache != null && useQueryCache == TRUE)) {
throw new CacheException("Caching was explicitly requested, but no RegionFactory was defined and there is not a single registered RegionFactory");
}
}
final RegionFactory regionFactory = registry.getService(StrategySelector.class).resolveStrategy(RegionFactory.class, setting, (RegionFactory) null, new StrategyCreatorRegionFactoryImpl(p));
if (regionFactory != null) {
return regionFactory;
}
if (implementors.size() == 1) {
final RegionFactory registeredFactory = selector.resolveStrategy(RegionFactory.class, implementors.iterator().next());
configurationValues.put(AvailableSettings.CACHE_REGION_FACTORY, registeredFactory);
configurationValues.put(AvailableSettings.USE_SECOND_LEVEL_CACHE, "true");
return registeredFactory;
} else {
LOG.debugf("Cannot default RegionFactory based on registered strategies as `%s` RegionFactory strategies were registered", implementors);
}
return NoCachingRegionFactory.INSTANCE;
}
use of org.hibernate.cache.CacheException in project wildfly by wildfly.
the class ManagedEmbeddedCacheManagerProvider method getEmbeddedCacheManager.
@Override
public EmbeddedCacheManager getEmbeddedCacheManager(Properties properties) {
Properties settings = new Properties();
String container = properties.getProperty(CACHE_CONTAINER, DEFAULT_CACHE_CONTAINER);
settings.setProperty(HibernateSecondLevelCache.CONTAINER, container);
if (!Boolean.parseBoolean(properties.getProperty(SHARED, DEFAULT_SHARED))) {
HibernateSecondLevelCache.addSecondLevelCacheDependencies(properties, null);
settings.setProperty(HibernateSecondLevelCache.CACHE_TYPE, HibernateSecondLevelCache.CACHE_PRIVATE);
// Find a suitable service name to represent this session factory instance
String name = properties.getProperty(AvailableSettings.SESSION_FACTORY_NAME);
if (name != null) {
settings.setProperty(HibernateSecondLevelCache.NAME, name);
}
settings.setProperty(HibernateSecondLevelCache.CACHES, String.join(" ", HibernateSecondLevelCache.findCaches(properties)));
}
try {
return new JipiJapaCacheManager(Notification.startCache(Classification.INFINISPAN, settings));
} catch (CacheException e) {
throw e;
} catch (Exception e) {
throw new CacheException(e);
}
}
Aggregations