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 SessionFactoryImplementor method getSecondLevelCacheRegionAccessStrategy.
/**
* Find the "access strategy" for the named cache region.
*
* @param regionName The name of the region
*
* @return That region's "access strategy"
*
*
* @deprecated (since 5.2) Use this factory's {@link #getCache()} reference
* to access {@link CacheImplementor#determineEntityRegionAccessStrategy} or
* {@link CacheImplementor#determineCollectionRegionAccessStrategy} instead.
*/
@Deprecated
default default RegionAccessStrategy getSecondLevelCacheRegionAccessStrategy(String regionName) {
final EntityRegionAccessStrategy entityRegionAccess = getCache().getEntityRegionAccess(regionName);
if (entityRegionAccess != null) {
return entityRegionAccess;
}
final CollectionRegionAccessStrategy collectionRegionAccess = getCache().getCollectionRegionAccess(regionName);
if (collectionRegionAccess != null) {
return collectionRegionAccess;
}
return null;
}
use of org.hibernate.cache.spi.access.EntityRegionAccessStrategy in project hibernate-orm by hibernate.
the class SessionFactoryImplementor method getSecondLevelCacheRegion.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Move to CacheImplementor calls
/**
* Get a named second-level cache region
*
* @param regionName The name of the region to retrieve.
*
* @return The name of the region
*
* @deprecated (since 5.2) Use this factory's {@link #getCache()} reference
* to access Region via {@link CacheImplementor#determineEntityRegionAccessStrategy} or
* {@link CacheImplementor#determineCollectionRegionAccessStrategy} instead.
*/
@Deprecated
default default Region getSecondLevelCacheRegion(String regionName) {
final EntityRegionAccessStrategy entityRegionAccess = getCache().getEntityRegionAccess(regionName);
if (entityRegionAccess != null) {
return entityRegionAccess.getRegion();
}
final CollectionRegionAccessStrategy collectionRegionAccess = getCache().getCollectionRegionAccess(regionName);
if (collectionRegionAccess != null) {
return collectionRegionAccess.getRegion();
}
return null;
}
use of org.hibernate.cache.spi.access.EntityRegionAccessStrategy in project hibernate-orm by hibernate.
the class DefaultLoadEventListener method lockAndLoad.
/**
* If the class to be loaded has been configured with a cache, then lock
* given id in that cache and then perform the load.
*
* @param event The initiating load request event
* @param persister The persister corresponding to the entity to be loaded
* @param keyToLoad The key of the entity to be loaded
* @param options The defined load options
* @param source The originating session
*
* @return The loaded entity
*
* @throws HibernateException
*/
private Object lockAndLoad(final LoadEvent event, final EntityPersister persister, final EntityKey keyToLoad, final LoadEventListener.LoadType options, final SessionImplementor source) {
SoftLock lock = null;
final Object ck;
final EntityRegionAccessStrategy cache = persister.getCacheAccessStrategy();
if (persister.hasCache()) {
ck = cache.generateCacheKey(event.getEntityId(), persister, source.getFactory(), source.getTenantIdentifier());
lock = persister.getCacheAccessStrategy().lockItem(source, ck, null);
} else {
ck = null;
}
Object entity;
try {
entity = load(event, persister, keyToLoad, options);
} finally {
if (persister.hasCache()) {
cache.unlockItem(source, ck, lock);
}
}
return event.getSession().getPersistenceContext().proxyFor(persister, keyToLoad, entity);
}
use of org.hibernate.cache.spi.access.EntityRegionAccessStrategy in project hibernate-orm by hibernate.
the class DefaultLoadEventListener method getFromSharedCache.
private Object getFromSharedCache(final LoadEvent event, final EntityPersister persister, SessionImplementor source) {
final EntityRegionAccessStrategy cache = persister.getCacheAccessStrategy();
final Object ck = cache.generateCacheKey(event.getEntityId(), persister, source.getFactory(), source.getTenantIdentifier());
final Object ce = CacheHelper.fromSharedCache(source, ck, persister.getCacheAccessStrategy());
if (source.getFactory().getStatistics().isStatisticsEnabled()) {
if (ce == null) {
source.getFactory().getStatisticsImplementor().secondLevelCacheMiss(cache.getRegion().getName());
} else {
source.getFactory().getStatisticsImplementor().secondLevelCacheHit(cache.getRegion().getName());
}
}
return ce;
}
Aggregations