use of org.hibernate.cache.spi.access.EntityRegionAccessStrategy in project hibernate-orm by hibernate.
the class BatchFetchQueue method isCached.
private boolean isCached(EntityKey entityKey, EntityPersister persister) {
final SharedSessionContractImplementor session = context.getSession();
if (context.getSession().getCacheMode().isGetEnabled() && persister.hasCache()) {
final EntityRegionAccessStrategy cache = persister.getCacheAccessStrategy();
final Object key = cache.generateCacheKey(entityKey.getIdentifier(), persister, session.getFactory(), session.getTenantIdentifier());
return CacheHelper.fromSharedCache(session, key, cache) != null;
}
return false;
}
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 AbstractEntityPersister method isTransient.
public Boolean isTransient(Object entity, SharedSessionContractImplementor session) throws HibernateException {
final Serializable id;
if (canExtractIdOutOfEntity()) {
id = getIdentifier(entity, session);
} else {
id = null;
}
// identifier or no identifier property is unsaved!
if (id == null) {
return Boolean.TRUE;
}
// check the version unsaved-value, if appropriate
final Object version = getVersion(entity);
if (isVersioned()) {
// let this take precedence if defined, since it works for
// assigned identifiers
Boolean result = entityMetamodel.getVersionProperty().getUnsavedValue().isUnsaved(version);
if (result != null) {
return result;
}
}
// check the id unsaved-value
Boolean result = entityMetamodel.getIdentifierProperty().getUnsavedValue().isUnsaved(id);
if (result != null) {
return result;
}
// check to see if it is in the second-level cache
if (session.getCacheMode().isGetEnabled() && hasCache()) {
final EntityRegionAccessStrategy cache = getCacheAccessStrategy();
final Object ck = cache.generateCacheKey(id, this, session.getFactory(), session.getTenantIdentifier());
final Object ce = CacheHelper.fromSharedCache(session, ck, getCacheAccessStrategy());
if (ce != null) {
return Boolean.FALSE;
}
}
return null;
}
Aggregations