Search in sources :

Example 6 with EntityRegionAccessStrategy

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;
}
Also used : EntityRegionAccessStrategy(org.hibernate.cache.spi.access.EntityRegionAccessStrategy)

Example 7 with EntityRegionAccessStrategy

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();
}
Also used : QueryCache(org.hibernate.cache.spi.QueryCache) StandardQueryCache(org.hibernate.cache.internal.StandardQueryCache) EntityRegionAccessStrategy(org.hibernate.cache.spi.access.EntityRegionAccessStrategy) CollectionRegionAccessStrategy(org.hibernate.cache.spi.access.CollectionRegionAccessStrategy)

Example 8 with EntityRegionAccessStrategy

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;
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) EntityRegionAccessStrategy(org.hibernate.cache.spi.access.EntityRegionAccessStrategy)

Example 9 with EntityRegionAccessStrategy

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;
}
Also used : EntityRegion(org.hibernate.cache.spi.EntityRegion) EntityRegionAccessStrategy(org.hibernate.cache.spi.access.EntityRegionAccessStrategy) AccessType(org.hibernate.cache.spi.access.AccessType)

Example 10 with EntityRegionAccessStrategy

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;
}
Also used : Serializable(java.io.Serializable) EntityRegionAccessStrategy(org.hibernate.cache.spi.access.EntityRegionAccessStrategy)

Aggregations

EntityRegionAccessStrategy (org.hibernate.cache.spi.access.EntityRegionAccessStrategy)24 EntityPersister (org.hibernate.persister.entity.EntityPersister)13 Serializable (java.io.Serializable)8 CollectionRegionAccessStrategy (org.hibernate.cache.spi.access.CollectionRegionAccessStrategy)5 CacheEntry (org.hibernate.cache.spi.entry.CacheEntry)5 EntityEntry (org.hibernate.engine.spi.EntityEntry)5 AssertionFailure (org.hibernate.AssertionFailure)4 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)4 SharedSessionContractImplementor (org.hibernate.engine.spi.SharedSessionContractImplementor)4 SoftLock (org.hibernate.cache.spi.access.SoftLock)3 PersistenceContext (org.hibernate.engine.spi.PersistenceContext)3 Type (org.hibernate.type.Type)3 HibernateException (org.hibernate.HibernateException)2 LockMode (org.hibernate.LockMode)2 CollectionPersister (org.hibernate.persister.collection.CollectionPersister)2 AssociationType (org.hibernate.type.AssociationType)2 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 EmbeddableType (javax.persistence.metamodel.EmbeddableType)1