use of org.hibernate.metamodel.mapping.NaturalIdMapping in project hibernate-orm by hibernate.
the class NaturalIdResolutionsImpl method handleSynchronization.
@Override
public void handleSynchronization(Object pk, Object entity, EntityMappingType entityDescriptor) {
final NaturalIdMapping naturalIdMapping = entityDescriptor.getNaturalIdMapping();
if (naturalIdMapping == null) {
// nothing to do
return;
}
final EntityPersister persister = locatePersisterForKey(entityDescriptor.getEntityPersister());
final Object naturalIdValuesFromCurrentObjectState = naturalIdMapping.extractNaturalIdFromEntity(entity, session());
final boolean changed = !sameAsCached(persister, pk, naturalIdValuesFromCurrentObjectState);
if (changed) {
final Object cachedNaturalIdValues = findCachedNaturalIdById(pk, persister);
cacheResolution(pk, naturalIdValuesFromCurrentObjectState, persister);
stashInvalidNaturalIdReference(persister, cachedNaturalIdValues);
removeSharedResolution(pk, cachedNaturalIdValues, persister);
}
}
use of org.hibernate.metamodel.mapping.NaturalIdMapping in project hibernate-orm by hibernate.
the class NaturalIdResolutionsImpl method removeSharedResolution.
@Override
public void removeSharedResolution(Object id, Object naturalId, EntityMappingType entityDescriptor) {
final NaturalIdMapping naturalIdMapping = entityDescriptor.getNaturalIdMapping();
if (naturalIdMapping == null) {
// nothing to do
return;
}
final NaturalIdDataAccess cacheAccess = naturalIdMapping.getCacheAccess();
if (cacheAccess == null) {
// nothing to do
return;
}
// todo : couple of things wrong here:
// 1) should be using access strategy, not plain evict..
// 2) should prefer session-cached values if any (requires interaction from removeLocalNaturalIdCrossReference)
final EntityPersister persister = locatePersisterForKey(entityDescriptor.getEntityPersister());
final Object naturalIdCacheKey = cacheAccess.generateCacheKey(naturalId, persister, session());
cacheAccess.evict(naturalIdCacheKey);
// if ( sessionCachedNaturalIdValues != null
// && !Arrays.equals( sessionCachedNaturalIdValues, deletedNaturalIdValues ) ) {
// final NaturalIdCacheKey sessionNaturalIdCacheKey = new NaturalIdCacheKey( sessionCachedNaturalIdValues, persister, session );
// cacheAccess.evict( sessionNaturalIdCacheKey );
// }
}
use of org.hibernate.metamodel.mapping.NaturalIdMapping in project hibernate-orm by hibernate.
the class NaturalIdResolutionsImpl method manageLocalResolution.
@Override
public void manageLocalResolution(Object id, Object naturalIdValue, EntityMappingType entityDescriptor, CachedNaturalIdValueSource source) {
final NaturalIdMapping naturalIdMapping = entityDescriptor.getNaturalIdMapping();
if (naturalIdMapping == null) {
// nothing to do
return;
}
cacheResolutionLocally(id, naturalIdValue, entityDescriptor);
}
use of org.hibernate.metamodel.mapping.NaturalIdMapping in project hibernate-orm by hibernate.
the class NaturalIdResolutionsImpl method manageSharedResolution.
@Override
public void manageSharedResolution(final Object id, Object naturalId, Object previousNaturalId, EntityMappingType entityDescriptor, CachedNaturalIdValueSource source) {
final NaturalIdMapping naturalIdMapping = entityDescriptor.getNaturalIdMapping();
if (naturalIdMapping == null) {
// nothing to do
return;
}
if (naturalIdMapping.getCacheAccess() == null) {
// nothing to do
return;
}
manageSharedResolution(entityDescriptor.getEntityPersister(), id, naturalId, previousNaturalId, source);
}
use of org.hibernate.metamodel.mapping.NaturalIdMapping in project hibernate-orm by hibernate.
the class NaturalIdResolutionsImpl method cacheResolutionFromLoad.
@Override
public void cacheResolutionFromLoad(Object id, Object naturalId, EntityMappingType entityDescriptor) {
NaturalIdLogging.LOGGER.debugf("Caching resolution natural-id resolution from load (%s) : `%s` -> `%s`", entityDescriptor.getEntityName(), naturalId, id);
final EntityPersister persister = locatePersisterForKey(entityDescriptor.getEntityPersister());
final NaturalIdMapping naturalIdMapping = entityDescriptor.getNaturalIdMapping();
if (naturalIdMapping == null) {
// nothing to do
return;
}
// 'justAddedLocally' is meant to handle the case where we would get double stats journaling
// from a single load event. The first put journal would come from the natural id resolution;
// the second comes from the entity loading. In this condition, we want to avoid the multiple
// 'put' stats incrementing.
final boolean justAddedLocally = cacheResolution(id, naturalId, entityDescriptor);
if (justAddedLocally && naturalIdMapping.getCacheAccess() != null) {
manageSharedResolution(persister, id, naturalId, (Object) null, CachedNaturalIdValueSource.LOAD);
}
}
Aggregations