use of org.hibernate.cache.spi.access.EntityRegionAccessStrategy in project hibernate-orm by hibernate.
the class CacheImpl method close.
@Override
public void close() {
for (EntityRegionAccessStrategy access : entityRegionAccessStrategyMap.values()) {
access.getRegion().destroy();
}
for (CollectionRegionAccessStrategy access : collectionRegionAccessStrategyMap.values()) {
access.getRegion().destroy();
}
if (settings.isQueryCacheEnabled()) {
defaultQueryCache.destroy();
for (QueryCache cache : queryCaches.values()) {
cache.destroy();
}
updateTimestampsCache.destroy();
}
regionFactory.stop();
}
use of org.hibernate.cache.spi.access.EntityRegionAccessStrategy in project hibernate-orm by hibernate.
the class CacheImpl method containsEntity.
@Override
public boolean containsEntity(String entityName, Serializable identifier) {
EntityPersister p = sessionFactory.getMetamodel().entityPersister(entityName);
if (p.hasCache()) {
EntityRegionAccessStrategy cache = p.getCacheAccessStrategy();
// have to assume non tenancy
Object key = cache.generateCacheKey(identifier, p, sessionFactory, null);
return cache.getRegion().contains(key);
} else {
return false;
}
}
use of org.hibernate.cache.spi.access.EntityRegionAccessStrategy in project hibernate-orm by hibernate.
the class CacheImpl method determineEntityRegionAccessStrategy.
@Override
public EntityRegionAccessStrategy determineEntityRegionAccessStrategy(PersistentClass model) {
final String cacheRegionName = cacheRegionPrefix + model.getRootClass().getCacheRegionName();
EntityRegionAccessStrategy accessStrategy = entityRegionAccessStrategyMap.get(cacheRegionName);
if (accessStrategy == null && settings.isSecondLevelCacheEnabled()) {
final AccessType accessType = AccessType.fromExternalName(model.getCacheConcurrencyStrategy());
if (accessType != null) {
LOG.tracef("Building shared cache region for entity data [%s]", model.getEntityName());
EntityRegion entityRegion = regionFactory.buildEntityRegion(cacheRegionName, sessionFactory.getProperties(), CacheDataDescriptionImpl.decode(model));
accessStrategy = entityRegion.buildAccessStrategy(accessType);
entityRegionAccessStrategyMap.put(cacheRegionName, accessStrategy);
}
}
return accessStrategy;
}
use of org.hibernate.cache.spi.access.EntityRegionAccessStrategy in project hibernate-orm by hibernate.
the class ConcurrentStatisticsImpl method getSecondLevelCacheStatistics.
/**
* Second level cache statistics per region
*
* @param regionName region name
*
* @return SecondLevelCacheStatistics
*/
public ConcurrentSecondLevelCacheStatisticsImpl getSecondLevelCacheStatistics(String regionName) {
ConcurrentSecondLevelCacheStatisticsImpl stat = secondLevelCacheStatistics.get(regionName);
if (stat == null) {
if (sessionFactory == null) {
return null;
}
final EntityRegionAccessStrategy entityRegionAccess = sessionFactory.getCache().getEntityRegionAccess(regionName);
final CollectionRegionAccessStrategy collectionRegionAccess = sessionFactory.getCache().getCollectionRegionAccess(regionName);
if (entityRegionAccess == null && collectionRegionAccess == null) {
final Region region = sessionFactory.getCache().getQueryCache(regionName).getRegion();
if (region == null) {
throw new IllegalArgumentException("Could not resolve region name [" + regionName + "]");
}
stat = new ConcurrentSecondLevelCacheStatisticsImpl(region, null, null);
} else {
final Region region = entityRegionAccess != null ? entityRegionAccess.getRegion() : collectionRegionAccess.getRegion();
stat = new ConcurrentSecondLevelCacheStatisticsImpl(region, entityRegionAccess, collectionRegionAccess);
}
ConcurrentSecondLevelCacheStatisticsImpl previous;
if ((previous = secondLevelCacheStatistics.putIfAbsent(regionName, stat)) != null) {
stat = previous;
}
}
return stat;
}
use of org.hibernate.cache.spi.access.EntityRegionAccessStrategy in project hibernate-orm by hibernate.
the class CacheImpl method evictEntity.
@Override
public void evictEntity(String entityName, Serializable identifier) {
EntityPersister p = sessionFactory.getMetamodel().entityPersister(entityName);
if (p.hasCache()) {
if (LOG.isDebugEnabled()) {
LOG.debugf("Evicting second-level cache: %s", MessageHelper.infoString(p, identifier, sessionFactory));
}
EntityRegionAccessStrategy cache = p.getCacheAccessStrategy();
// have to assume non tenancy
Object key = cache.generateCacheKey(identifier, p, sessionFactory, null);
cache.evict(key);
}
}
Aggregations