Search in sources :

Example 1 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 2 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 3 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 4 with EntityRegionAccessStrategy

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

Example 5 with EntityRegionAccessStrategy

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

Aggregations

EntityRegionAccessStrategy (org.hibernate.cache.spi.access.EntityRegionAccessStrategy)7 CollectionRegionAccessStrategy (org.hibernate.cache.spi.access.CollectionRegionAccessStrategy)4 EntityPersister (org.hibernate.persister.entity.EntityPersister)2 StandardQueryCache (org.hibernate.cache.internal.StandardQueryCache)1 EntityRegion (org.hibernate.cache.spi.EntityRegion)1 QueryCache (org.hibernate.cache.spi.QueryCache)1 Region (org.hibernate.cache.spi.Region)1 AccessType (org.hibernate.cache.spi.access.AccessType)1