expose some methods for HR
This commit is contained in:
parent
af25660720
commit
7bfab04e63
|
@ -138,7 +138,7 @@ public class EntityInsertAction extends AbstractEntityInsertAction {
|
|||
}
|
||||
}
|
||||
|
||||
private void putCacheIfNecessary() {
|
||||
protected void putCacheIfNecessary() {
|
||||
final EntityPersister persister = getPersister();
|
||||
final SharedSessionContractImplementor session = getSession();
|
||||
if ( isCachePutEnabled( persister, session ) ) {
|
||||
|
|
|
@ -169,6 +169,7 @@ public class EntityUpdateAction extends EntityAction {
|
|||
throw new AssertionFailure( "possible non thread safe access to session" );
|
||||
}
|
||||
handleGeneratedProperties( entry );
|
||||
handleDeleted( entry );
|
||||
updateCacheItem( previousVersion, ck, entry );
|
||||
handleNaturalIdResolutions( persister, session, id );
|
||||
postUpdate();
|
||||
|
@ -180,7 +181,7 @@ public class EntityUpdateAction extends EntityAction {
|
|||
}
|
||||
}
|
||||
|
||||
private void handleNaturalIdResolutions(EntityPersister persister, SharedSessionContractImplementor session, Object id) {
|
||||
protected void handleNaturalIdResolutions(EntityPersister persister, SharedSessionContractImplementor session, Object id) {
|
||||
if ( naturalIdMapping != null ) {
|
||||
session.getPersistenceContextInternal().getNaturalIdResolutions().manageSharedResolution(
|
||||
id,
|
||||
|
@ -192,7 +193,7 @@ public class EntityUpdateAction extends EntityAction {
|
|||
}
|
||||
}
|
||||
|
||||
private void updateCacheItem(Object previousVersion, Object ck, EntityEntry entry) {
|
||||
protected void updateCacheItem(Object previousVersion, Object ck, EntityEntry entry) {
|
||||
final EntityPersister persister = getPersister();
|
||||
if ( persister.canWriteToCache() ) {
|
||||
final SharedSessionContractImplementor session = getSession();
|
||||
|
@ -220,15 +221,16 @@ public class EntityUpdateAction extends EntityAction {
|
|||
EntityPersister persister,
|
||||
SharedSessionContractImplementor session) {
|
||||
// the cache has to be invalidated when CacheMode is equal to GET or IGNORE
|
||||
return persister.isCacheInvalidationRequired() || session.getCacheMode() == CacheMode.GET || session.getCacheMode() == CacheMode.IGNORE;
|
||||
return persister.isCacheInvalidationRequired()
|
||||
|| session.getCacheMode() == CacheMode.GET
|
||||
|| session.getCacheMode() == CacheMode.IGNORE;
|
||||
}
|
||||
|
||||
private void handleGeneratedProperties(EntityEntry entry) {
|
||||
final EntityPersister persister = getPersister();
|
||||
final Object instance = getInstance();
|
||||
|
||||
if ( entry.getStatus() == Status.MANAGED || persister.isVersionPropertyGenerated() ) {
|
||||
final SharedSessionContractImplementor session = getSession();
|
||||
final Object instance = getInstance();
|
||||
final Object id = getId();
|
||||
// get the updated snapshot of the entity state by cloning current state;
|
||||
// it is safe to copy in place, since by this time no-one else (should have)
|
||||
|
@ -252,16 +254,18 @@ public class EntityUpdateAction extends EntityAction {
|
|||
}
|
||||
entry.postUpdate( instance, state, nextVersion );
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDeleted(EntityEntry entry) {
|
||||
if ( entry.getStatus() == Status.DELETED ) {
|
||||
final EntityMetamodel entityMetamodel = persister.getEntityMetamodel();
|
||||
final EntityMetamodel entityMetamodel = getPersister().getEntityMetamodel();
|
||||
final boolean isImpliedOptimisticLocking = !entityMetamodel.isVersioned()
|
||||
&& entityMetamodel.getOptimisticLockStyle().isAllOrDirty();
|
||||
if ( isImpliedOptimisticLocking && entry.getLoadedState() != null ) {
|
||||
// The entity will be deleted and because we are going to create a delete statement
|
||||
// that uses all the state values in the where clause, the entry state needs to be
|
||||
// updated otherwise the statement execution will not delete any row (see HHH-15218).
|
||||
entry.postUpdate( instance, state, nextVersion );
|
||||
entry.postUpdate( getInstance(), state, nextVersion );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -279,7 +283,7 @@ public class EntityUpdateAction extends EntityAction {
|
|||
}
|
||||
}
|
||||
|
||||
private Object lockCacheItem(Object previousVersion) {
|
||||
protected Object lockCacheItem(Object previousVersion) {
|
||||
final EntityPersister persister = getPersister();
|
||||
if ( persister.canWriteToCache() ) {
|
||||
final SharedSessionContractImplementor session = getSession();
|
||||
|
|
|
@ -35,7 +35,6 @@ import org.hibernate.metamodel.mapping.EntityMappingType;
|
|||
import org.hibernate.metamodel.mapping.MappingType;
|
||||
import org.hibernate.metamodel.mapping.NonAggregatedIdentifierMapping;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.proxy.LazyInitializer;
|
||||
import org.hibernate.stat.spi.StatisticsImplementor;
|
||||
|
@ -542,22 +541,29 @@ public class DefaultLoadEventListener implements LoadEventListener {
|
|||
final Object entity = persistenceContextEntry.getEntity();
|
||||
if ( entity != null ) {
|
||||
if ( persistenceContextEntry.isManaged() ) {
|
||||
if ( isPersistentAttributeInterceptable( entity ) ) {
|
||||
final PersistentAttributeInterceptor interceptor = asPersistentAttributeInterceptable( entity ).$$_hibernate_getInterceptor();
|
||||
if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor ) {
|
||||
( (EnhancementAsProxyLazinessInterceptor) interceptor ).forceInitialize( entity, null );
|
||||
}
|
||||
}
|
||||
initializeIfNecessary( entity );
|
||||
return entity;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return load( event, persister, keyToLoad );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void initializeIfNecessary(Object entity) {
|
||||
if ( isPersistentAttributeInterceptable( entity ) ) {
|
||||
final PersistentAttributeInterceptable interceptable = asPersistentAttributeInterceptable( entity );
|
||||
final PersistentAttributeInterceptor interceptor = interceptable.$$_hibernate_getInterceptor();
|
||||
if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor ) {
|
||||
( (EnhancementAsProxyLazinessInterceptor) interceptor ).forceInitialize( entity, null );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Object load(LoadEvent event, EntityPersister persister, EntityKey keyToLoad) {
|
||||
final EventSource session = event.getSession();
|
||||
final Object entity = loadFromCacheOrDatasource( event, persister, keyToLoad );
|
||||
|
|
Loading…
Reference in New Issue