use of org.hibernate.cache.spi.access.CollectionRegionAccessStrategy 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.CollectionRegionAccessStrategy in project hibernate-orm by hibernate.
the class CacheImpl method containsCollection.
@Override
public boolean containsCollection(String role, Serializable ownerIdentifier) {
CollectionPersister p = sessionFactory.getMetamodel().collectionPersister(role);
if (p.hasCache()) {
CollectionRegionAccessStrategy cache = p.getCacheAccessStrategy();
// have to assume non tenancy
Object key = cache.generateCacheKey(ownerIdentifier, p, sessionFactory, null);
return cache.getRegion().contains(key);
} else {
return false;
}
}
use of org.hibernate.cache.spi.access.CollectionRegionAccessStrategy in project hibernate-orm by hibernate.
the class CacheImpl method evictCollection.
@Override
public void evictCollection(String role, Serializable ownerIdentifier) {
CollectionPersister p = sessionFactory.getMetamodel().collectionPersister(role);
if (p.hasCache()) {
if (LOG.isDebugEnabled()) {
LOG.debugf("Evicting second-level cache: %s", MessageHelper.collectionInfoString(p, ownerIdentifier, sessionFactory));
}
CollectionRegionAccessStrategy cache = p.getCacheAccessStrategy();
// have to assume non tenancy
Object key = cache.generateCacheKey(ownerIdentifier, p, sessionFactory, null);
cache.evict(key);
}
}
use of org.hibernate.cache.spi.access.CollectionRegionAccessStrategy 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.CollectionRegionAccessStrategy in project hibernate-orm by hibernate.
the class CollectionCacheEvictionTest method testCachedValueAfterEviction.
@Test
public void testCachedValueAfterEviction() {
CollectionPersister persister = sessionFactory().getCollectionPersister(Company.class.getName() + ".users");
Session session = openSession();
SessionImplementor sessionImplementor = (SessionImplementor) session;
CollectionRegionAccessStrategy cache = persister.getCacheAccessStrategy();
Object key = cache.generateCacheKey(1, persister, sessionFactory(), session.getTenantIdentifier());
Object cachedValue = cache.get(sessionImplementor, key, sessionImplementor.getTimestamp());
assertNull(cachedValue);
Company company = session.get(Company.class, 1);
//should add in cache
assertEquals(1, company.getUsers().size());
session.close();
session = openSession();
sessionImplementor = (SessionImplementor) session;
key = cache.generateCacheKey(1, persister, sessionFactory(), session.getTenantIdentifier());
cachedValue = cache.get(sessionImplementor, key, sessionImplementor.getTimestamp());
assertNotNull("Collection wasn't cached", cachedValue);
session.close();
}
Aggregations