Search in sources :

Example 1 with NaturalIdDataAccess

use of org.hibernate.cache.spi.access.NaturalIdDataAccess in project hibernate-orm by hibernate.

the class EnabledCaching method prime.

@Override
public void prime(Set<DomainDataRegionConfig> cacheRegionConfigs) {
    for (DomainDataRegionConfig regionConfig : cacheRegionConfigs) {
        final DomainDataRegion region = getRegionFactory().buildDomainDataRegion(regionConfig, this);
        regionsByName.put(region.getName(), region);
        if (!StringTypeDescriptor.INSTANCE.areEqual(region.getName(), regionConfig.getRegionName())) {
            throw new HibernateException(String.format(Locale.ROOT, "Region [%s] returned from RegionFactory [%s] was named differently than requested name.  Expecting `%s`, but found `%s`", region, getRegionFactory().getClass().getName(), regionConfig.getRegionName(), region.getName()));
        }
        for (EntityDataCachingConfig entityAccessConfig : regionConfig.getEntityCaching()) {
            final EntityDataAccess entityDataAccess = entityAccessMap.put(entityAccessConfig.getNavigableRole(), region.getEntityDataAccess(entityAccessConfig.getNavigableRole()));
            legacySecondLevelCacheNames.add(StringHelper.qualifyConditionally(getSessionFactory().getSessionFactoryOptions().getCacheRegionPrefix(), region.getName()));
        }
        if (regionConfig.getNaturalIdCaching().isEmpty()) {
            legacyNaturalIdAccessesForRegion.put(region.getName(), Collections.emptySet());
        } else {
            final HashSet<NaturalIdDataAccess> accesses = new HashSet<>();
            for (NaturalIdDataCachingConfig naturalIdAccessConfig : regionConfig.getNaturalIdCaching()) {
                final NaturalIdDataAccess naturalIdDataAccess = naturalIdAccessMap.put(naturalIdAccessConfig.getNavigableRole(), region.getNaturalIdDataAccess(naturalIdAccessConfig.getNavigableRole()));
                accesses.add(naturalIdDataAccess);
            }
            legacyNaturalIdAccessesForRegion.put(region.getName(), accesses);
        }
        for (CollectionDataCachingConfig collectionAccessConfig : regionConfig.getCollectionCaching()) {
            final CollectionDataAccess collectionDataAccess = collectionAccessMap.put(collectionAccessConfig.getNavigableRole(), region.getCollectionDataAccess(collectionAccessConfig.getNavigableRole()));
            legacySecondLevelCacheNames.add(StringHelper.qualifyConditionally(getSessionFactory().getSessionFactoryOptions().getCacheRegionPrefix(), region.getName()));
        }
    }
}
Also used : NaturalIdDataCachingConfig(org.hibernate.cache.cfg.spi.NaturalIdDataCachingConfig) EntityDataCachingConfig(org.hibernate.cache.cfg.spi.EntityDataCachingConfig) HibernateException(org.hibernate.HibernateException) DomainDataRegionConfig(org.hibernate.cache.cfg.spi.DomainDataRegionConfig) NaturalIdDataAccess(org.hibernate.cache.spi.access.NaturalIdDataAccess) DomainDataRegion(org.hibernate.cache.spi.DomainDataRegion) CollectionDataAccess(org.hibernate.cache.spi.access.CollectionDataAccess) CollectionDataCachingConfig(org.hibernate.cache.cfg.spi.CollectionDataCachingConfig) EntityDataAccess(org.hibernate.cache.spi.access.EntityDataAccess) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 2 with NaturalIdDataAccess

use of org.hibernate.cache.spi.access.NaturalIdDataAccess in project hibernate-orm by hibernate.

the class NaturalIdXrefDelegate method removeNaturalIdCrossReference.

/**
 * Handle removing cross reference entries for the given natural-id/pk combo
 *
 * @param persister The persister representing the entity type.
 * @param pk The primary key value
 * @param naturalIdValues The natural id value(s)
 *
 * @return The cached values, if any.  May be different from incoming values.
 */
public Object[] removeNaturalIdCrossReference(EntityPersister persister, Serializable pk, Object[] naturalIdValues) {
    persister = locatePersisterForKey(persister);
    validateNaturalId(persister, naturalIdValues);
    final NaturalIdResolutionCache entityNaturalIdResolutionCache = naturalIdResolutionCacheMap.get(persister);
    Object[] sessionCachedNaturalIdValues = null;
    if (entityNaturalIdResolutionCache != null) {
        final CachedNaturalId cachedNaturalId = entityNaturalIdResolutionCache.pkToNaturalIdMap.remove(pk);
        if (cachedNaturalId != null) {
            entityNaturalIdResolutionCache.naturalIdToPkMap.remove(cachedNaturalId);
            sessionCachedNaturalIdValues = cachedNaturalId.getValues();
        }
    }
    if (persister.hasNaturalIdCache()) {
        final NaturalIdDataAccess naturalIdCacheAccessStrategy = persister.getNaturalIdCacheAccessStrategy();
        final Object naturalIdCacheKey = naturalIdCacheAccessStrategy.generateCacheKey(naturalIdValues, persister, session());
        naturalIdCacheAccessStrategy.evict(naturalIdCacheKey);
        if (sessionCachedNaturalIdValues != null && !Arrays.equals(sessionCachedNaturalIdValues, naturalIdValues)) {
            final Object sessionNaturalIdCacheKey = naturalIdCacheAccessStrategy.generateCacheKey(sessionCachedNaturalIdValues, persister, session());
            naturalIdCacheAccessStrategy.evict(sessionNaturalIdCacheKey);
        }
    }
    return sessionCachedNaturalIdValues;
}
Also used : NaturalIdDataAccess(org.hibernate.cache.spi.access.NaturalIdDataAccess)

Example 3 with NaturalIdDataAccess

use of org.hibernate.cache.spi.access.NaturalIdDataAccess in project hibernate-orm by hibernate.

the class DeprecatedNaturalIdCacheStatisticsImpl method getElementCountOnDisk.

@Override
public long getElementCountOnDisk() {
    long count = 0;
    HashSet<Region> processedRegions = null;
    for (NaturalIdDataAccess accessStrategy : accessStrategies) {
        final DomainDataRegion region = accessStrategy.getRegion();
        if (ExtendedStatisticsSupport.class.isInstance(region)) {
        }
        if (region instanceof ExtendedStatisticsSupport) {
            if (processedRegions == null) {
                processedRegions = new HashSet<>();
            }
            if (processedRegions.add(region)) {
                count += ((ExtendedStatisticsSupport) region).getElementCountOnDisk();
            }
        }
    }
    if (count == 0) {
        return NO_EXTENDED_STAT_SUPPORT_RETURN;
    }
    return count;
}
Also used : ExtendedStatisticsSupport(org.hibernate.cache.spi.ExtendedStatisticsSupport) DomainDataRegion(org.hibernate.cache.spi.DomainDataRegion) Region(org.hibernate.cache.spi.Region) NaturalIdDataAccess(org.hibernate.cache.spi.access.NaturalIdDataAccess) DomainDataRegion(org.hibernate.cache.spi.DomainDataRegion)

Example 4 with NaturalIdDataAccess

use of org.hibernate.cache.spi.access.NaturalIdDataAccess in project hibernate-orm by hibernate.

the class DeprecatedNaturalIdCacheStatisticsImpl method getSizeInMemory.

@Override
public long getSizeInMemory() {
    long count = 0;
    HashSet<Region> processedRegions = null;
    for (NaturalIdDataAccess accessStrategy : accessStrategies) {
        final DomainDataRegion region = accessStrategy.getRegion();
        if (ExtendedStatisticsSupport.class.isInstance(region)) {
        }
        if (region instanceof ExtendedStatisticsSupport) {
            if (processedRegions == null) {
                processedRegions = new HashSet<>();
            }
            if (processedRegions.add(region)) {
                count += ((ExtendedStatisticsSupport) region).getElementCountOnDisk();
            }
        }
    }
    if (count == 0) {
        return NO_EXTENDED_STAT_SUPPORT_RETURN;
    }
    return count;
}
Also used : ExtendedStatisticsSupport(org.hibernate.cache.spi.ExtendedStatisticsSupport) DomainDataRegion(org.hibernate.cache.spi.DomainDataRegion) Region(org.hibernate.cache.spi.Region) NaturalIdDataAccess(org.hibernate.cache.spi.access.NaturalIdDataAccess) DomainDataRegion(org.hibernate.cache.spi.DomainDataRegion)

Example 5 with NaturalIdDataAccess

use of org.hibernate.cache.spi.access.NaturalIdDataAccess in project hibernate-orm by hibernate.

the class DeprecatedNaturalIdCacheStatisticsImpl method getElementCountInMemory.

@Override
public long getElementCountInMemory() {
    long count = 0;
    HashSet<Region> processedRegions = null;
    for (NaturalIdDataAccess accessStrategy : accessStrategies) {
        final DomainDataRegion region = accessStrategy.getRegion();
        if (ExtendedStatisticsSupport.class.isInstance(region)) {
        }
        if (region instanceof ExtendedStatisticsSupport) {
            if (processedRegions == null) {
                processedRegions = new HashSet<>();
            }
            if (processedRegions.add(region)) {
                count += ((ExtendedStatisticsSupport) region).getElementCountInMemory();
            }
        }
    }
    if (count == 0) {
        return NO_EXTENDED_STAT_SUPPORT_RETURN;
    }
    return count;
}
Also used : ExtendedStatisticsSupport(org.hibernate.cache.spi.ExtendedStatisticsSupport) DomainDataRegion(org.hibernate.cache.spi.DomainDataRegion) Region(org.hibernate.cache.spi.Region) NaturalIdDataAccess(org.hibernate.cache.spi.access.NaturalIdDataAccess) DomainDataRegion(org.hibernate.cache.spi.DomainDataRegion)

Aggregations

NaturalIdDataAccess (org.hibernate.cache.spi.access.NaturalIdDataAccess)7 DomainDataRegion (org.hibernate.cache.spi.DomainDataRegion)4 ExtendedStatisticsSupport (org.hibernate.cache.spi.ExtendedStatisticsSupport)3 Region (org.hibernate.cache.spi.Region)3 HibernateException (org.hibernate.HibernateException)2 CollectionDataAccess (org.hibernate.cache.spi.access.CollectionDataAccess)2 EntityDataAccess (org.hibernate.cache.spi.access.EntityDataAccess)2 Serializable (java.io.Serializable)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 EmbeddableType (javax.persistence.metamodel.EmbeddableType)1 EntityType (javax.persistence.metamodel.EntityType)1 ManagedType (javax.persistence.metamodel.ManagedType)1 MappedSuperclassType (javax.persistence.metamodel.MappedSuperclassType)1 CollectionDataCachingConfig (org.hibernate.cache.cfg.spi.CollectionDataCachingConfig)1 DomainDataRegionConfig (org.hibernate.cache.cfg.spi.DomainDataRegionConfig)1 EntityDataCachingConfig (org.hibernate.cache.cfg.spi.EntityDataCachingConfig)1