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()));
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations