HHH-15649 Additional performance fixes relating to Klass's _secondary_super_cache interaction with entity enhancement
This commit is contained in:
parent
77d1bdac4c
commit
bedbd402e6
|
@ -28,7 +28,6 @@ import org.hibernate.collection.spi.PersistentSet;
|
|||
import org.hibernate.collection.spi.PersistentSortedMap;
|
||||
import org.hibernate.collection.spi.PersistentSortedSet;
|
||||
import org.hibernate.collection.spi.PersistentCollection;
|
||||
import org.hibernate.engine.internal.ManagedTypeHelper;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
|
@ -37,6 +36,9 @@ import org.hibernate.proxy.HibernateProxy;
|
|||
import org.hibernate.proxy.LazyInitializer;
|
||||
import org.hibernate.collection.spi.LazyInitializable;
|
||||
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable;
|
||||
|
||||
/**
|
||||
* Various utility functions for working with proxies and lazy collection references.
|
||||
* <p>
|
||||
|
@ -90,9 +92,8 @@ public final class Hibernate {
|
|||
else if ( proxy instanceof LazyInitializable ) {
|
||||
( (LazyInitializable) proxy ).forceInitialization();
|
||||
}
|
||||
else if ( proxy instanceof PersistentAttributeInterceptable ) {
|
||||
final PersistentAttributeInterceptable interceptable = (PersistentAttributeInterceptable) proxy;
|
||||
final PersistentAttributeInterceptor interceptor = interceptable.$$_hibernate_getInterceptor();
|
||||
else if ( isPersistentAttributeInterceptable( proxy ) ) {
|
||||
final PersistentAttributeInterceptor interceptor = asPersistentAttributeInterceptable( proxy ).$$_hibernate_getInterceptor();
|
||||
if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor ) {
|
||||
( (EnhancementAsProxyLazinessInterceptor) interceptor ).forceInitialize( proxy, null );
|
||||
}
|
||||
|
@ -109,10 +110,8 @@ public final class Hibernate {
|
|||
if ( proxy instanceof HibernateProxy ) {
|
||||
return !( (HibernateProxy) proxy ).getHibernateLazyInitializer().isUninitialized();
|
||||
}
|
||||
else if ( ManagedTypeHelper.isPersistentAttributeInterceptable( proxy ) ) {
|
||||
final PersistentAttributeInterceptable asPersistentAttributeInterceptable = ManagedTypeHelper.asPersistentAttributeInterceptable(
|
||||
proxy );
|
||||
final PersistentAttributeInterceptor interceptor = asPersistentAttributeInterceptable.$$_hibernate_getInterceptor();
|
||||
else if ( isPersistentAttributeInterceptable( proxy ) ) {
|
||||
final PersistentAttributeInterceptor interceptor = asPersistentAttributeInterceptable( proxy ).$$_hibernate_getInterceptor();
|
||||
return !(interceptor instanceof EnhancementAsProxyLazinessInterceptor);
|
||||
}
|
||||
else if ( proxy instanceof LazyInitializable ) {
|
||||
|
@ -230,8 +229,8 @@ public final class Hibernate {
|
|||
entity = proxy;
|
||||
}
|
||||
|
||||
if ( entity instanceof PersistentAttributeInterceptable ) {
|
||||
PersistentAttributeInterceptor interceptor = ( (PersistentAttributeInterceptable) entity ).$$_hibernate_getInterceptor();
|
||||
if ( isPersistentAttributeInterceptable( entity ) ) {
|
||||
PersistentAttributeInterceptor interceptor = asPersistentAttributeInterceptable( entity ).$$_hibernate_getInterceptor();
|
||||
if ( interceptor instanceof BytecodeLazyAttributeInterceptor ) {
|
||||
return ( (BytecodeLazyAttributeInterceptor) interceptor ).isAttributeLoaded( propertyName );
|
||||
}
|
||||
|
|
|
@ -8,23 +8,22 @@ package org.hibernate.bytecode.enhance.spi.interceptor;
|
|||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.bytecode.BytecodeLogging;
|
||||
import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer;
|
||||
import org.hibernate.engine.internal.ManagedTypeHelper;
|
||||
import org.hibernate.engine.spi.EntityKey;
|
||||
import org.hibernate.engine.spi.SelfDirtinessTracker;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||
import org.hibernate.metamodel.mapping.AttributeMapping;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.type.CompositeType;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isSelfDirtinessTrackerType;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
|
@ -73,7 +72,7 @@ public class EnhancementAsProxyLazinessInterceptor extends AbstractLazyLoadInter
|
|||
}
|
||||
}
|
||||
|
||||
this.inLineDirtyChecking = ManagedTypeHelper.isSelfDirtinessTrackerType( entityPersister.getMappedClass() );
|
||||
this.inLineDirtyChecking = isSelfDirtinessTrackerType( entityPersister.getMappedClass() );
|
||||
// if self-dirty tracking is enabled but DynamicUpdate is not enabled then we need to initialise the entity
|
||||
// because the pre-computed update statement contains even not dirty properties and so we need all the values
|
||||
// we have to initialise it even if it's versioned to fetch the current version
|
||||
|
|
|
@ -21,6 +21,9 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
|||
import org.hibernate.engine.spi.Status;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.asSelfDirtinessTracker;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isSelfDirtinessTracker;
|
||||
|
||||
/**
|
||||
* Interceptor that loads attributes lazily
|
||||
*
|
||||
|
@ -156,13 +159,14 @@ public class LazyAttributeLoadingInterceptor extends AbstractLazyLoadInterceptor
|
|||
}
|
||||
|
||||
private void takeCollectionSizeSnapshot(Object target, String fieldName, Object value) {
|
||||
if ( value instanceof Collection && target instanceof SelfDirtinessTracker ) {
|
||||
if ( value instanceof Collection && isSelfDirtinessTracker( target ) ) {
|
||||
// This must be called first, so that we remember that there is a collection out there,
|
||||
// even if we don't know its size (see below).
|
||||
CollectionTracker tracker = ( (SelfDirtinessTracker) target ).$$_hibernate_getCollectionTracker();
|
||||
final SelfDirtinessTracker targetSDT = asSelfDirtinessTracker( target );
|
||||
CollectionTracker tracker = targetSDT.$$_hibernate_getCollectionTracker();
|
||||
if ( tracker == null ) {
|
||||
( (SelfDirtinessTracker) target ).$$_hibernate_clearDirtyAttributes();
|
||||
tracker = ( (SelfDirtinessTracker) target ).$$_hibernate_getCollectionTracker();
|
||||
targetSDT.$$_hibernate_clearDirtyAttributes();
|
||||
tracker = targetSDT.$$_hibernate_getCollectionTracker();
|
||||
}
|
||||
|
||||
if ( value instanceof PersistentCollection && !( (PersistentCollection<?>) value ).wasInitialized() ) {
|
||||
|
|
|
@ -21,7 +21,6 @@ import org.hibernate.engine.spi.CachedNaturalIdValueSource;
|
|||
import org.hibernate.engine.spi.EntityEntry;
|
||||
import org.hibernate.engine.spi.EntityEntryExtraState;
|
||||
import org.hibernate.engine.spi.EntityKey;
|
||||
import org.hibernate.engine.spi.Managed;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
|
||||
|
@ -34,6 +33,9 @@ import org.hibernate.persister.entity.UniqueKeyLoadable;
|
|||
import org.hibernate.pretty.MessageHelper;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable;
|
||||
|
||||
/**
|
||||
* A base implementation of EntityEntry
|
||||
*
|
||||
|
@ -330,8 +332,8 @@ public abstract class AbstractEntityEntry implements Serializable, EntityEntry {
|
|||
private boolean isUnequivocallyNonDirty(Object entity) {
|
||||
if ( ManagedTypeHelper.isSelfDirtinessTracker( entity ) ) {
|
||||
boolean uninitializedProxy = false;
|
||||
if ( ManagedTypeHelper.isPersistentAttributeInterceptable( entity ) ) {
|
||||
final PersistentAttributeInterceptable interceptable = ManagedTypeHelper.asPersistentAttributeInterceptable( entity );
|
||||
if ( isPersistentAttributeInterceptable( entity ) ) {
|
||||
final PersistentAttributeInterceptable interceptable = asPersistentAttributeInterceptable( entity );
|
||||
final PersistentAttributeInterceptor interceptor = interceptable.$$_hibernate_getInterceptor();
|
||||
if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor ) {
|
||||
EnhancementAsProxyLazinessInterceptor enhancementAsProxyLazinessInterceptor = (EnhancementAsProxyLazinessInterceptor) interceptor;
|
||||
|
@ -348,8 +350,8 @@ public abstract class AbstractEntityEntry implements Serializable, EntityEntry {
|
|||
&& !ManagedTypeHelper.asSelfDirtinessTracker( entity ).$$_hibernate_hasDirtyAttributes();
|
||||
}
|
||||
|
||||
if ( ManagedTypeHelper.isPersistentAttributeInterceptable( entity ) ) {
|
||||
final PersistentAttributeInterceptable interceptable = ManagedTypeHelper.asPersistentAttributeInterceptable( entity );
|
||||
if ( isPersistentAttributeInterceptable( entity ) ) {
|
||||
final PersistentAttributeInterceptable interceptable = asPersistentAttributeInterceptable( entity );
|
||||
final PersistentAttributeInterceptor interceptor = interceptable.$$_hibernate_getInterceptor();
|
||||
if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor ) {
|
||||
// we never have to check an uninitialized proxy
|
||||
|
|
|
@ -9,7 +9,6 @@ package org.hibernate.engine.internal;
|
|||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.engine.internal.ManagedTypeHelper;
|
||||
import org.hibernate.engine.spi.EntityEntry;
|
||||
import org.hibernate.engine.spi.ManagedEntity;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
|
@ -24,6 +23,10 @@ import java.lang.reflect.Method;
|
|||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.asManagedEntity;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isManaged;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isManagedEntity;
|
||||
|
||||
/**
|
||||
* Defines a context for maintaining the relation between an entity associated with the Session ultimately owning this
|
||||
* EntityEntryContext instance and that entity's corresponding EntityEntry. 2 approaches are supported:<ul>
|
||||
|
@ -91,8 +94,8 @@ public class EntityEntryContext {
|
|||
ManagedEntity managedEntity = getAssociatedManagedEntity( entity );
|
||||
final boolean alreadyAssociated = managedEntity != null;
|
||||
if ( !alreadyAssociated ) {
|
||||
if ( ManagedTypeHelper.isManaged( entity ) ) {
|
||||
final ManagedEntity managed = ManagedTypeHelper.asManagedEntity( entity );
|
||||
if ( isManaged( entity ) ) {
|
||||
final ManagedEntity managed = asManagedEntity( entity );
|
||||
if ( entityEntry.getPersister().isMutable() ) {
|
||||
managedEntity = managed;
|
||||
// We know that managedEntity is not associated with the same PersistenceContext.
|
||||
|
@ -151,8 +154,8 @@ public class EntityEntryContext {
|
|||
}
|
||||
|
||||
private ManagedEntity getAssociatedManagedEntity(Object entity) {
|
||||
if ( ManagedTypeHelper.isManaged( entity ) ) {
|
||||
final ManagedEntity managedEntity = ManagedTypeHelper.asManagedEntity( entity );
|
||||
if ( isManaged( entity ) ) {
|
||||
final ManagedEntity managedEntity = asManagedEntity( entity );
|
||||
if ( managedEntity.$$_hibernate_getEntityEntry() == null ) {
|
||||
// it is not associated
|
||||
return null;
|
||||
|
@ -253,7 +256,7 @@ public class EntityEntryContext {
|
|||
immutableManagedEntityXref.remove( entity );
|
||||
|
||||
}
|
||||
else if ( !(entity instanceof ManagedEntity) ) {
|
||||
else if ( ! ( isManagedEntity( entity ) ) ) {
|
||||
nonEnhancedEntityXref.remove( entity );
|
||||
}
|
||||
|
||||
|
|
|
@ -145,8 +145,8 @@ public final class ForeignKeys {
|
|||
// or 2) returnedValue was initialized, but not nullified.
|
||||
// When bytecode-enhancement is used for dirty-checking, the change should
|
||||
// only be tracked when returnedValue was nullified (1)).
|
||||
if ( value != returnedValue && returnedValue == null && self instanceof SelfDirtinessTracker ) {
|
||||
( (SelfDirtinessTracker) self ).$$_hibernate_trackChange( propertyName );
|
||||
if ( value != returnedValue && returnedValue == null ) {
|
||||
ManagedTypeHelper.processIfSelfDirtinessTracker( self, SelfDirtinessTracker::$$_hibernate_trackChange, propertyName );
|
||||
}
|
||||
return returnedValue;
|
||||
}
|
||||
|
|
|
@ -64,6 +64,14 @@ public final class ManagedTypeHelper {
|
|||
return entity instanceof EnhancedEntity || entity instanceof Managed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @return true if and only if the entity implements {@see ManagedEntity}
|
||||
*/
|
||||
public static boolean isManagedEntity(final Object entity) {
|
||||
return entity instanceof EnhancedEntity || entity instanceof ManagedEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type
|
||||
* @return true if and only if the type is assignable to a {@see PersistentAttributeInterceptable} type.
|
||||
|
@ -137,6 +145,30 @@ public final class ManagedTypeHelper {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the entity is implementing SelfDirtinessTracker, apply some action to it; this action should take
|
||||
* a parameter of type T.
|
||||
* It is first cast to SelfDirtinessTracker using an optimal strategy.
|
||||
* If the entity does not implement SelfDirtinessTracker, no operation is performed.
|
||||
* @param entity
|
||||
* @param action
|
||||
* @param optionalParam a parameter which can be passed to the action
|
||||
* @param <T> the type of the additional parameter.
|
||||
*/
|
||||
public static <T> void processIfSelfDirtinessTracker(
|
||||
final Object entity,
|
||||
final BiConsumer<SelfDirtinessTracker, T> action,
|
||||
final T optionalParam) {
|
||||
if ( entity instanceof EnhancedEntity ) {
|
||||
EnhancedEntity e = (EnhancedEntity) entity;
|
||||
action.accept( e, optionalParam );
|
||||
}
|
||||
else if ( entity instanceof SelfDirtinessTracker ) {
|
||||
SelfDirtinessTracker e = (SelfDirtinessTracker) entity;
|
||||
action.accept( e, optionalParam );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cast the object to PersistentAttributeInterceptable
|
||||
* (using this is highly preferrable over a direct cast)
|
||||
|
@ -184,4 +216,5 @@ public final class ManagedTypeHelper {
|
|||
return (SelfDirtinessTracker) entity;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@ import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInter
|
|||
import org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor;
|
||||
import org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor;
|
||||
import org.hibernate.collection.spi.PersistentCollection;
|
||||
import org.hibernate.engine.internal.ManagedTypeHelper;
|
||||
import org.hibernate.engine.spi.AssociationKey;
|
||||
import org.hibernate.engine.spi.BatchFetchQueue;
|
||||
import org.hibernate.engine.spi.CollectionEntry;
|
||||
|
@ -69,6 +68,9 @@ import org.hibernate.type.CollectionType;
|
|||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable;
|
||||
|
||||
/**
|
||||
* A <strong>stateful</strong> implementation of the {@link PersistenceContext} contract meaning that we maintain this
|
||||
* state throughout the life of the persistence context.
|
||||
|
@ -603,8 +605,8 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
}
|
||||
|
||||
// or an uninitialized enhanced entity ("bytecode proxy")...
|
||||
if ( value instanceof PersistentAttributeInterceptable ) {
|
||||
final PersistentAttributeInterceptable bytecodeProxy = (PersistentAttributeInterceptable) value;
|
||||
if ( isPersistentAttributeInterceptable( value ) ) {
|
||||
final PersistentAttributeInterceptable bytecodeProxy = asPersistentAttributeInterceptable( value );
|
||||
final BytecodeLazyAttributeInterceptor interceptor = (BytecodeLazyAttributeInterceptor) bytecodeProxy.$$_hibernate_getInterceptor();
|
||||
if ( interceptor != null ) {
|
||||
interceptor.setSession( getSession() );
|
||||
|
@ -674,8 +676,8 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
//initialize + unwrap the object and return it
|
||||
return li.getImplementation();
|
||||
}
|
||||
else if ( ManagedTypeHelper.isPersistentAttributeInterceptable( maybeProxy ) ) {
|
||||
final PersistentAttributeInterceptable interceptable = ManagedTypeHelper.asPersistentAttributeInterceptable( maybeProxy );
|
||||
else if ( isPersistentAttributeInterceptable( maybeProxy ) ) {
|
||||
final PersistentAttributeInterceptable interceptable = asPersistentAttributeInterceptable( maybeProxy );
|
||||
final PersistentAttributeInterceptor interceptor = interceptable.$$_hibernate_getInterceptor();
|
||||
if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor ) {
|
||||
( (EnhancementAsProxyLazinessInterceptor) interceptor ).forceInitialize( maybeProxy, null );
|
||||
|
|
|
@ -37,6 +37,8 @@ import org.hibernate.pretty.MessageHelper;
|
|||
import org.hibernate.type.Type;
|
||||
import org.hibernate.type.TypeHelper;
|
||||
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.processIfSelfDirtinessTracker;
|
||||
|
||||
/**
|
||||
* A convenience base class for listeners responding to save events.
|
||||
*
|
||||
|
@ -106,9 +108,7 @@ public abstract class AbstractSaveEventListener<C>
|
|||
boolean requiresImmediateIdAccess) {
|
||||
callbackRegistry.preCreate( entity );
|
||||
|
||||
if ( entity instanceof SelfDirtinessTracker ) {
|
||||
( (SelfDirtinessTracker) entity ).$$_hibernate_clearDirtyAttributes();
|
||||
}
|
||||
processIfSelfDirtinessTracker( entity, SelfDirtinessTracker::$$_hibernate_clearDirtyAttributes );
|
||||
|
||||
EntityPersister persister = source.getEntityPersister( entityName, entity );
|
||||
Object generatedId = persister.getIdentifierGenerator().generate( source, entity );
|
||||
|
|
|
@ -15,14 +15,10 @@ import org.hibernate.StaleObjectStateException;
|
|||
import org.hibernate.action.internal.DelayedPostInsertIdentifier;
|
||||
import org.hibernate.action.internal.EntityUpdateAction;
|
||||
import org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor;
|
||||
import org.hibernate.engine.internal.ManagedTypeHelper;
|
||||
import org.hibernate.engine.internal.Nullability;
|
||||
import org.hibernate.engine.internal.Versioning;
|
||||
import org.hibernate.engine.spi.EntityEntry;
|
||||
import org.hibernate.engine.spi.EntityKey;
|
||||
import org.hibernate.engine.spi.Managed;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
|
||||
import org.hibernate.engine.spi.SelfDirtinessTracker;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
|
@ -43,6 +39,11 @@ import org.hibernate.stat.spi.StatisticsImplementor;
|
|||
import org.hibernate.type.Type;
|
||||
|
||||
import static org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer.UNFETCHED_PROPERTY;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.asSelfDirtinessTracker;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isSelfDirtinessTracker;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.processIfSelfDirtinessTracker;
|
||||
|
||||
/**
|
||||
* An event that occurs for each entity instance at flush time
|
||||
|
@ -102,10 +103,8 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
}
|
||||
|
||||
private static boolean isUninitializedEnhanced(Object entity) {
|
||||
if ( ManagedTypeHelper.isPersistentAttributeInterceptable( entity ) ) {
|
||||
final PersistentAttributeInterceptable asPersistentAttributeInterceptable = ManagedTypeHelper.asPersistentAttributeInterceptable(
|
||||
entity );
|
||||
final PersistentAttributeInterceptor interceptor = asPersistentAttributeInterceptable.$$_hibernate_getInterceptor();
|
||||
if ( isPersistentAttributeInterceptable( entity ) ) {
|
||||
final PersistentAttributeInterceptor interceptor = asPersistentAttributeInterceptable( entity ).$$_hibernate_getInterceptor();
|
||||
// the entity is an un-initialized enhancement-as-proxy reference
|
||||
return interceptor instanceof EnhancementAsProxyLazinessInterceptor;
|
||||
}
|
||||
|
@ -206,9 +205,7 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
return true;
|
||||
}
|
||||
else {
|
||||
if ( event.getEntity() instanceof SelfDirtinessTracker ) {
|
||||
( (SelfDirtinessTracker) event.getEntity() ).$$_hibernate_clearDirtyAttributes();
|
||||
}
|
||||
processIfSelfDirtinessTracker( event.getEntity(), SelfDirtinessTracker::$$_hibernate_clearDirtyAttributes );
|
||||
EventSource source = event.getSession();
|
||||
source.getFactory()
|
||||
.getCustomEntityDirtinessStrategy()
|
||||
|
@ -540,8 +537,8 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
}
|
||||
else {
|
||||
final Object entity = event.getEntity();
|
||||
return entity instanceof SelfDirtinessTracker
|
||||
? getDirtyPropertiesFromSelfDirtinessTracker( (SelfDirtinessTracker) entity, event )
|
||||
return isSelfDirtinessTracker( entity )
|
||||
? getDirtyPropertiesFromSelfDirtinessTracker( asSelfDirtinessTracker( entity ), event )
|
||||
: getDirtyPropertiesFromCustomEntityDirtinessStrategy( event );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.hibernate.engine.spi.CollectionEntry;
|
|||
import org.hibernate.engine.spi.EntityEntry;
|
||||
import org.hibernate.engine.spi.EntityKey;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
|
||||
import org.hibernate.engine.spi.SelfDirtinessTracker;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
|
@ -47,6 +46,11 @@ import org.hibernate.type.EntityType;
|
|||
import org.hibernate.type.ForeignKeyDirection;
|
||||
import org.hibernate.type.TypeHelper;
|
||||
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.asSelfDirtinessTracker;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isSelfDirtinessTracker;
|
||||
|
||||
/**
|
||||
* Defines the default copy event listener used by hibernate for copying entities
|
||||
* in response to generated copy events.
|
||||
|
@ -109,9 +113,8 @@ public class DefaultMergeEventListener
|
|||
doMerge( event, copiedAlready, li.getImplementation() );
|
||||
}
|
||||
}
|
||||
else if ( original instanceof PersistentAttributeInterceptable ) {
|
||||
final PersistentAttributeInterceptable interceptable = (PersistentAttributeInterceptable) original;
|
||||
final PersistentAttributeInterceptor interceptor = interceptable.$$_hibernate_getInterceptor();
|
||||
else if ( isPersistentAttributeInterceptable( original ) ) {
|
||||
final PersistentAttributeInterceptor interceptor = asPersistentAttributeInterceptable( original ).$$_hibernate_getInterceptor();
|
||||
if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor ) {
|
||||
final EnhancementAsProxyLazinessInterceptor proxyInterceptor = (EnhancementAsProxyLazinessInterceptor) interceptor;
|
||||
LOG.trace( "Ignoring uninitialized enhanced-proxy" );
|
||||
|
@ -236,9 +239,8 @@ public class DefaultMergeEventListener
|
|||
|
||||
event.setResult( copy );
|
||||
|
||||
if ( copy instanceof PersistentAttributeInterceptable ) {
|
||||
final PersistentAttributeInterceptable interceptable = (PersistentAttributeInterceptable) copy;
|
||||
final PersistentAttributeInterceptor interceptor = interceptable.$$_hibernate_getInterceptor();
|
||||
if ( isPersistentAttributeInterceptable( copy ) ) {
|
||||
final PersistentAttributeInterceptor interceptor = asPersistentAttributeInterceptable( copy ).$$_hibernate_getInterceptor();
|
||||
if ( interceptor == null ) {
|
||||
persister.getBytecodeEnhancementMetadata().injectInterceptor( copy, id, session );
|
||||
}
|
||||
|
@ -396,13 +398,11 @@ public class DefaultMergeEventListener
|
|||
return source.getPersistenceContextInternal().unproxy( managed );
|
||||
}
|
||||
|
||||
if ( incoming instanceof PersistentAttributeInterceptable
|
||||
if ( isPersistentAttributeInterceptable( incoming )
|
||||
&& persister.getBytecodeEnhancementMetadata().isEnhancedForLazyLoading() ) {
|
||||
|
||||
final PersistentAttributeInterceptor incomingInterceptor =
|
||||
( (PersistentAttributeInterceptable) incoming ).$$_hibernate_getInterceptor();
|
||||
final PersistentAttributeInterceptor managedInterceptor =
|
||||
( (PersistentAttributeInterceptable) managed ).$$_hibernate_getInterceptor();
|
||||
final PersistentAttributeInterceptor incomingInterceptor = asPersistentAttributeInterceptable( incoming ).$$_hibernate_getInterceptor();
|
||||
final PersistentAttributeInterceptor managedInterceptor = asPersistentAttributeInterceptable( managed ).$$_hibernate_getInterceptor();
|
||||
|
||||
// todo - do we need to specially handle the case where both `incoming` and `managed` are initialized, but
|
||||
// with different attributes initialized?
|
||||
|
@ -427,11 +427,12 @@ public class DefaultMergeEventListener
|
|||
|
||||
private static void markInterceptorDirty(final Object entity, final Object target) {
|
||||
// for enhanced entities, copy over the dirty attributes
|
||||
if ( entity instanceof SelfDirtinessTracker && target instanceof SelfDirtinessTracker ) {
|
||||
if ( isSelfDirtinessTracker( entity ) && isSelfDirtinessTracker( target ) ) {
|
||||
// clear, because setting the embedded attributes dirties them
|
||||
( (SelfDirtinessTracker) target ).$$_hibernate_clearDirtyAttributes();
|
||||
for ( String fieldName : ( (SelfDirtinessTracker) entity ).$$_hibernate_getDirtyAttributes() ) {
|
||||
( (SelfDirtinessTracker) target ).$$_hibernate_trackChange( fieldName );
|
||||
final SelfDirtinessTracker selfDirtinessTrackerTarget = asSelfDirtinessTracker( target );
|
||||
selfDirtinessTrackerTarget.$$_hibernate_clearDirtyAttributes();
|
||||
for ( String fieldName : asSelfDirtinessTracker( entity ).$$_hibernate_getDirtyAttributes() ) {
|
||||
selfDirtinessTrackerTarget.$$_hibernate_trackChange( fieldName );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,12 +9,14 @@ package org.hibernate.event.internal;
|
|||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor;
|
||||
import org.hibernate.collection.spi.PersistentCollection;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.event.spi.EventSource;
|
||||
import org.hibernate.type.CollectionType;
|
||||
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable;
|
||||
|
||||
/**
|
||||
* Do we have a dirty collection here?
|
||||
* 1. if it is a new application-instantiated collection, return true (does not occur anymore!)
|
||||
|
@ -32,9 +34,8 @@ public class DirtyCollectionSearchVisitor extends AbstractVisitor {
|
|||
public DirtyCollectionSearchVisitor(Object entity, EventSource session, boolean[] propertyVersionability) {
|
||||
super( session );
|
||||
EnhancementAsProxyLazinessInterceptor interceptor = null;
|
||||
if ( entity instanceof PersistentAttributeInterceptable ) {
|
||||
PersistentAttributeInterceptor attributeInterceptor =
|
||||
((PersistentAttributeInterceptable) entity).$$_hibernate_getInterceptor();
|
||||
if ( isPersistentAttributeInterceptable( entity ) ) {
|
||||
PersistentAttributeInterceptor attributeInterceptor = asPersistentAttributeInterceptable( entity ).$$_hibernate_getInterceptor();
|
||||
if ( attributeInterceptor instanceof EnhancementAsProxyLazinessInterceptor ) {
|
||||
interceptor = (EnhancementAsProxyLazinessInterceptor) attributeInterceptor;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ import org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterc
|
|||
import org.hibernate.collection.spi.PersistentCollection;
|
||||
import org.hibernate.engine.spi.CollectionEntry;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.event.spi.EventSource;
|
||||
|
@ -27,6 +26,9 @@ import org.hibernate.type.CollectionType;
|
|||
import org.hibernate.type.CompositeType;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable;
|
||||
|
||||
/**
|
||||
* Wrap collections in a Hibernate collection wrapper.
|
||||
*
|
||||
|
@ -102,9 +104,8 @@ public class WrapVisitor extends ProxyVisitor {
|
|||
return null;
|
||||
}
|
||||
else {
|
||||
if ( entity instanceof PersistentAttributeInterceptable ) {
|
||||
PersistentAttributeInterceptor attributeInterceptor =
|
||||
((PersistentAttributeInterceptable) entity).$$_hibernate_getInterceptor();
|
||||
if ( isPersistentAttributeInterceptable( entity ) ) {
|
||||
PersistentAttributeInterceptor attributeInterceptor = asPersistentAttributeInterceptable( entity ).$$_hibernate_getInterceptor();
|
||||
if ( attributeInterceptor instanceof EnhancementAsProxyLazinessInterceptor ) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.hibernate.engine.internal.Versioning;
|
|||
import org.hibernate.engine.spi.EntityKey;
|
||||
import org.hibernate.engine.spi.LoadQueryInfluencers;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
|
||||
import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
|
||||
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
||||
|
@ -38,6 +37,9 @@ import org.hibernate.tuple.entity.EntityMetamodel;
|
|||
|
||||
import jakarta.transaction.SystemException;
|
||||
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable;
|
||||
|
||||
/**
|
||||
* Concrete implementation of the {@link StatelessSession} API.
|
||||
* <p/>
|
||||
|
@ -408,9 +410,8 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen
|
|||
}
|
||||
}
|
||||
}
|
||||
else if ( association instanceof PersistentAttributeInterceptable) {
|
||||
final PersistentAttributeInterceptor interceptor =
|
||||
( (PersistentAttributeInterceptable) association ).$$_hibernate_getInterceptor();
|
||||
else if ( isPersistentAttributeInterceptable( association ) ) {
|
||||
final PersistentAttributeInterceptor interceptor = asPersistentAttributeInterceptable( association ).$$_hibernate_getInterceptor();
|
||||
if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor) {
|
||||
EnhancementAsProxyLazinessInterceptor proxyInterceptor =
|
||||
(EnhancementAsProxyLazinessInterceptor) interceptor;
|
||||
|
|
|
@ -13,7 +13,6 @@ import jakarta.persistence.spi.LoadState;
|
|||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.engine.spi.EntityEntry;
|
||||
import org.hibernate.engine.spi.ManagedEntity;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.jpa.internal.util.PersistenceUtilHelper;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
@ -21,6 +20,9 @@ import org.hibernate.proxy.HibernateProxy;
|
|||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.asManagedEntity;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isManagedEntity;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
|
@ -70,8 +72,8 @@ public class PersistenceUnitUtilImpl implements PersistenceUnitUtil, Serializabl
|
|||
if ( entity instanceof HibernateProxy ) {
|
||||
return ((HibernateProxy) entity).getHibernateLazyInitializer().getInternalIdentifier();
|
||||
}
|
||||
else if ( entity instanceof ManagedEntity ) {
|
||||
EntityEntry entityEntry = ((ManagedEntity) entity).$$_hibernate_getEntityEntry();
|
||||
else if ( isManagedEntity( entity ) ) {
|
||||
EntityEntry entityEntry = asManagedEntity( entity ).$$_hibernate_getEntityEntry();
|
||||
if ( entityEntry != null ) {
|
||||
return entityEntry.getId();
|
||||
}
|
||||
|
|
|
@ -20,9 +20,7 @@ import java.util.WeakHashMap;
|
|||
import jakarta.persistence.spi.LoadState;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.bytecode.enhance.spi.interceptor.AbstractLazyLoadInterceptor;
|
||||
import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor;
|
||||
import org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor;
|
||||
import org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor;
|
||||
import org.hibernate.collection.spi.PersistentCollection;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||
|
@ -31,6 +29,9 @@ import org.hibernate.internal.util.securitymanager.SystemSecurityManager;
|
|||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.proxy.LazyInitializer;
|
||||
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable;
|
||||
|
||||
/**
|
||||
* Central delegate for handling calls from:<ul>
|
||||
* <li>{@link jakarta.persistence.PersistenceUtil#isLoaded(Object)}</li>
|
||||
|
@ -83,8 +84,8 @@ public final class PersistenceUtilHelper {
|
|||
final boolean isInitialized = !( (HibernateProxy) reference ).getHibernateLazyInitializer().isUninitialized();
|
||||
return isInitialized ? LoadState.LOADED : LoadState.NOT_LOADED;
|
||||
}
|
||||
else if ( reference instanceof PersistentAttributeInterceptable ) {
|
||||
boolean isInitialized = isInitialized( (PersistentAttributeInterceptable) reference );
|
||||
else if ( isPersistentAttributeInterceptable( reference ) ) {
|
||||
boolean isInitialized = isInitialized( asPersistentAttributeInterceptable( reference ) );
|
||||
return isInitialized ? LoadState.LOADED : LoadState.NOT_LOADED;
|
||||
}
|
||||
else if ( reference instanceof PersistentCollection ) {
|
||||
|
@ -131,8 +132,8 @@ public final class PersistenceUtilHelper {
|
|||
}
|
||||
|
||||
// we are instrumenting but we can't assume we are the only ones
|
||||
if ( entity instanceof PersistentAttributeInterceptable ) {
|
||||
final BytecodeLazyAttributeInterceptor interceptor = extractInterceptor( (PersistentAttributeInterceptable) entity );
|
||||
if ( isPersistentAttributeInterceptable( entity ) ) {
|
||||
final BytecodeLazyAttributeInterceptor interceptor = extractInterceptor( asPersistentAttributeInterceptable( entity ) );
|
||||
final boolean isInitialized = interceptor == null || interceptor.isAttributeLoaded( attributeName );
|
||||
LoadState state;
|
||||
if (isInitialized && interceptor != null) {
|
||||
|
|
|
@ -21,9 +21,7 @@ import org.hibernate.engine.internal.TwoPhaseLoad;
|
|||
import org.hibernate.engine.internal.Versioning;
|
||||
import org.hibernate.engine.spi.EntityEntry;
|
||||
import org.hibernate.engine.spi.EntityKey;
|
||||
import org.hibernate.engine.spi.ManagedEntity;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
|
@ -44,6 +42,9 @@ import org.hibernate.stat.spi.StatisticsImplementor;
|
|||
import org.hibernate.type.Type;
|
||||
import org.hibernate.type.TypeHelper;
|
||||
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isManagedEntity;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable;
|
||||
import static org.hibernate.loader.ast.internal.LoaderHelper.upgradeLock;
|
||||
|
||||
/**
|
||||
|
@ -331,7 +332,7 @@ public class CacheEntityLoaderHelper {
|
|||
// make it circular-reference safe
|
||||
final StatefulPersistenceContext statefulPersistenceContext = (StatefulPersistenceContext) session.getPersistenceContext();
|
||||
|
||||
if ( ( entity instanceof ManagedEntity ) ) {
|
||||
if ( ( isManagedEntity( entity ) ) ) {
|
||||
statefulPersistenceContext.addReferenceEntry(
|
||||
entity,
|
||||
Status.READ_ONLY
|
||||
|
@ -378,8 +379,8 @@ public class CacheEntityLoaderHelper {
|
|||
? source.instantiate( subclassPersister, entityId )
|
||||
: instanceToLoad;
|
||||
|
||||
if ( entity instanceof PersistentAttributeInterceptable ) {
|
||||
PersistentAttributeInterceptor persistentAttributeInterceptor = ( (PersistentAttributeInterceptable) entity ).$$_hibernate_getInterceptor();
|
||||
if ( isPersistentAttributeInterceptable( entity ) ) {
|
||||
PersistentAttributeInterceptor persistentAttributeInterceptor = asPersistentAttributeInterceptable( entity ).$$_hibernate_getInterceptor();
|
||||
// if we do this after the entity has been initialized the BytecodeLazyAttributeInterceptor#isAttributeLoaded(String fieldName) would return false;
|
||||
if ( persistentAttributeInterceptor == null || persistentAttributeInterceptor instanceof EnhancementAsProxyLazinessInterceptor ) {
|
||||
persister.getBytecodeEnhancementMetadata().injectInterceptor(
|
||||
|
|
|
@ -10,12 +10,14 @@ package org.hibernate.metamodel.internal;
|
|||
import org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.internal.ManagedTypeHelper;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.metamodel.spi.EntityInstantiator;
|
||||
import org.hibernate.tuple.entity.EntityMetamodel;
|
||||
import org.hibernate.type.descriptor.java.JavaType;
|
||||
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptableType;
|
||||
|
||||
/**
|
||||
* Base support for instantiating entity values as POJO representation
|
||||
*
|
||||
|
@ -36,7 +38,7 @@ public abstract class AbstractEntityInstantiatorPojo extends AbstractPojoInstant
|
|||
this.proxyInterface = persistentClass.getProxyInterface();
|
||||
|
||||
//TODO this PojoEntityInstantiator appears to not be reused ?!
|
||||
this.applyBytecodeInterception = ManagedTypeHelper.isPersistentAttributeInterceptableType( persistentClass.getMappedClass() );
|
||||
this.applyBytecodeInterception = isPersistentAttributeInterceptableType( persistentClass.getMappedClass() );
|
||||
}
|
||||
|
||||
protected Object applyInterception(Object entity) {
|
||||
|
@ -52,7 +54,7 @@ public abstract class AbstractEntityInstantiatorPojo extends AbstractPojoInstant
|
|||
.getLazyAttributeNames(),
|
||||
null
|
||||
);
|
||||
ManagedTypeHelper.asPersistentAttributeInterceptable( entity ).$$_hibernate_setInterceptor( interceptor );
|
||||
asPersistentAttributeInterceptable( entity ).$$_hibernate_setInterceptor( interceptor );
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,14 +6,11 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.internal;
|
||||
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import org.hibernate.InstantiationException;
|
||||
import org.hibernate.PropertyNotFoundException;
|
||||
import org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor;
|
||||
import org.hibernate.engine.internal.ManagedTypeHelper;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
|
@ -23,6 +20,9 @@ import org.hibernate.mapping.PersistentClass;
|
|||
import org.hibernate.tuple.entity.EntityMetamodel;
|
||||
import org.hibernate.type.descriptor.java.JavaType;
|
||||
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptableType;
|
||||
|
||||
/**
|
||||
* Support for instantiating entity values as POJO representation
|
||||
*/
|
||||
|
@ -48,7 +48,7 @@ public class EntityInstantiatorPojoStandard extends AbstractEntityInstantiatorPo
|
|||
? null
|
||||
: resolveConstructor( getMappedPojoClass() );
|
||||
|
||||
this.applyBytecodeInterception = ManagedTypeHelper.isPersistentAttributeInterceptableType( persistentClass.getMappedClass() );
|
||||
this.applyBytecodeInterception = isPersistentAttributeInterceptableType( persistentClass.getMappedClass() );
|
||||
}
|
||||
|
||||
protected static Constructor<?> resolveConstructor(Class<?> mappedPojoClass) {
|
||||
|
@ -81,7 +81,7 @@ public class EntityInstantiatorPojoStandard extends AbstractEntityInstantiatorPo
|
|||
.getLazyAttributeNames(),
|
||||
null
|
||||
);
|
||||
ManagedTypeHelper.asPersistentAttributeInterceptable( entity ).$$_hibernate_setInterceptor( interceptor );
|
||||
asPersistentAttributeInterceptable( entity ).$$_hibernate_setInterceptor( interceptor );
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ package org.hibernate.metamodel.internal;
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
@ -23,8 +22,6 @@ import org.hibernate.bytecode.spi.ReflectionOptimizer;
|
|||
import org.hibernate.bytecode.spi.ReflectionOptimizer.InstantiationOptimizer;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.classic.Lifecycle;
|
||||
import org.hibernate.engine.internal.ManagedTypeHelper;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
|
@ -57,6 +54,7 @@ import org.hibernate.type.descriptor.java.JavaType;
|
|||
import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry;
|
||||
import org.hibernate.type.spi.CompositeTypeImplementor;
|
||||
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptableType;
|
||||
import static org.hibernate.internal.util.collections.ArrayHelper.EMPTY_CLASS_ARRAY;
|
||||
import static org.hibernate.internal.util.collections.ArrayHelper.EMPTY_STRING_ARRAY;
|
||||
|
||||
|
@ -103,7 +101,7 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent
|
|||
}
|
||||
|
||||
this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedJavaType );
|
||||
this.isBytecodeEnhanced = ManagedTypeHelper.isPersistentAttributeInterceptableType( mappedJavaType );
|
||||
this.isBytecodeEnhanced = isPersistentAttributeInterceptableType( mappedJavaType );
|
||||
|
||||
final Property identifierProperty = bootDescriptor.getIdentifierProperty();
|
||||
if ( identifierProperty == null ) {
|
||||
|
|
|
@ -71,7 +71,6 @@ import org.hibernate.engine.FetchTiming;
|
|||
import org.hibernate.engine.OptimisticLockStyle;
|
||||
import org.hibernate.engine.internal.CacheHelper;
|
||||
import org.hibernate.engine.internal.ImmutableEntityEntryFactory;
|
||||
import org.hibernate.engine.internal.ManagedTypeHelper;
|
||||
import org.hibernate.engine.internal.MutableEntityEntryFactory;
|
||||
import org.hibernate.engine.internal.StatefulPersistenceContext;
|
||||
import org.hibernate.engine.internal.Versioning;
|
||||
|
@ -268,6 +267,10 @@ import org.hibernate.type.Type;
|
|||
import org.hibernate.type.descriptor.java.JavaType;
|
||||
import org.hibernate.type.descriptor.java.MutabilityPlan;
|
||||
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.processIfPersistentAttributeInterceptable;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.processIfSelfDirtinessTracker;
|
||||
|
||||
/**
|
||||
* Basic functionality for persisting an entity via JDBC
|
||||
* through either generated or custom SQL
|
||||
|
@ -5024,7 +5027,7 @@ public abstract class AbstractEntityPersister
|
|||
|
||||
@Override
|
||||
public void afterInitialize(Object entity, SharedSessionContractImplementor session) {
|
||||
if ( ManagedTypeHelper.isPersistentAttributeInterceptable( entity ) && getRepresentationStrategy().getMode() == RepresentationMode.POJO ) {
|
||||
if ( isPersistentAttributeInterceptable( entity ) && getRepresentationStrategy().getMode() == RepresentationMode.POJO ) {
|
||||
final BytecodeLazyAttributeInterceptor interceptor = getEntityMetamodel().getBytecodeEnhancementMetadata()
|
||||
.extractLazyInterceptor( entity );
|
||||
assert interceptor != null;
|
||||
|
@ -5034,7 +5037,7 @@ public abstract class AbstractEntityPersister
|
|||
}
|
||||
|
||||
// clear the fields that are marked as dirty in the dirtiness tracker
|
||||
ManagedTypeHelper.processIfSelfDirtinessTracker( entity, AbstractEntityPersister::clearDirtyAttributes );
|
||||
processIfSelfDirtinessTracker( entity, AbstractEntityPersister::clearDirtyAttributes );
|
||||
}
|
||||
|
||||
private static void clearDirtyAttributes(final SelfDirtinessTracker entity) {
|
||||
|
@ -5272,7 +5275,7 @@ public abstract class AbstractEntityPersister
|
|||
if ( session == null ) {
|
||||
return;
|
||||
}
|
||||
ManagedTypeHelper.processIfPersistentAttributeInterceptable( entity, this::setSession, session );
|
||||
processIfPersistentAttributeInterceptable( entity, this::setSession, session );
|
||||
}
|
||||
|
||||
private void setSession(PersistentAttributeInterceptable entity, SharedSessionContractImplementor session) {
|
||||
|
|
|
@ -8,7 +8,6 @@ package org.hibernate.property.access.internal;
|
|||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
||||
import org.hibernate.engine.internal.ManagedTypeHelper;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.metamodel.RepresentationMode;
|
||||
import org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies;
|
||||
|
@ -16,6 +15,8 @@ import org.hibernate.property.access.spi.PropertyAccessStrategy;
|
|||
import org.hibernate.property.access.spi.PropertyAccessStrategyResolver;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isManagedType;
|
||||
|
||||
/**
|
||||
* Standard implementation of PropertyAccessStrategyResolver
|
||||
*
|
||||
|
@ -38,7 +39,7 @@ public class PropertyAccessStrategyResolverStandardImpl implements PropertyAcces
|
|||
|| BuiltInPropertyAccessStrategies.FIELD.getExternalName().equals( explicitAccessStrategyName )
|
||||
|| BuiltInPropertyAccessStrategies.MIXED.getExternalName().equals( explicitAccessStrategyName ) ) {
|
||||
//type-cache-pollution agent: always check for EnhancedEntity type first.
|
||||
if ( ManagedTypeHelper.isManagedType( containerClass ) ) {
|
||||
if ( isManagedType( containerClass ) ) {
|
||||
// PROPERTY (BASIC) and MIXED are not valid for bytecode enhanced entities...
|
||||
return PropertyAccessStrategyEnhancedImpl.INSTANCE;
|
||||
}
|
||||
|
|
|
@ -10,13 +10,14 @@ import java.io.Serializable;
|
|||
import java.lang.reflect.Field;
|
||||
|
||||
import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor;
|
||||
import org.hibernate.engine.internal.ManagedTypeHelper;
|
||||
import org.hibernate.engine.spi.CompositeOwner;
|
||||
import org.hibernate.engine.spi.CompositeTracker;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
|
||||
import org.hibernate.property.access.internal.AbstractFieldSerialForm;
|
||||
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptableType;
|
||||
|
||||
/**
|
||||
* A specialized Setter implementation for handling setting values into
|
||||
* a bytecode-enhanced Class. The reason we need specialized handling
|
||||
|
@ -40,7 +41,7 @@ public class EnhancedSetterImpl extends SetterFieldImpl {
|
|||
this.propertyName = propertyName;
|
||||
this.enhancementState = ( CompositeOwner.class.isAssignableFrom( containerClass ) ? COMPOSITE_OWNER : 0 )
|
||||
| ( CompositeTracker.class.isAssignableFrom( field.getType() ) ? COMPOSITE_TRACKER_MASK : 0 )
|
||||
| ( ManagedTypeHelper.isPersistentAttributeInterceptableType( containerClass ) ? PERSISTENT_ATTRIBUTE_INTERCEPTABLE_MASK : 0 );
|
||||
| ( isPersistentAttributeInterceptableType( containerClass ) ? PERSISTENT_ATTRIBUTE_INTERCEPTABLE_MASK : 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -54,9 +55,7 @@ public class EnhancedSetterImpl extends SetterFieldImpl {
|
|||
|
||||
// This marks the attribute as initialized, so it doesn't get lazily loaded afterwards
|
||||
if ( ( enhancementState & PERSISTENT_ATTRIBUTE_INTERCEPTABLE_MASK ) != 0 ) {
|
||||
final PersistentAttributeInterceptable asPersistentAttributeInterceptable = ManagedTypeHelper.asPersistentAttributeInterceptable(
|
||||
target );
|
||||
PersistentAttributeInterceptor interceptor = asPersistentAttributeInterceptable.$$_hibernate_getInterceptor();
|
||||
PersistentAttributeInterceptor interceptor = asPersistentAttributeInterceptable( target ).$$_hibernate_getInterceptor();
|
||||
if ( interceptor instanceof BytecodeLazyAttributeInterceptor ) {
|
||||
( (BytecodeLazyAttributeInterceptor) interceptor ).attributeInitialized( propertyName );
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.hibernate.engine.spi.EntityEntry;
|
|||
import org.hibernate.engine.spi.EntityKey;
|
||||
import org.hibernate.engine.spi.EntityUniqueKey;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
|
||||
import org.hibernate.engine.spi.SessionEventListenerManager;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
|
@ -63,6 +62,8 @@ import org.hibernate.type.AssociationType;
|
|||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable;
|
||||
import static org.hibernate.internal.log.LoggingHelper.toLoggableString;
|
||||
|
||||
/**
|
||||
|
@ -704,8 +705,8 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
|
|||
rowProcessingState
|
||||
);
|
||||
|
||||
if ( toInitialize instanceof PersistentAttributeInterceptable ) {
|
||||
PersistentAttributeInterceptor persistentAttributeInterceptor = ( (PersistentAttributeInterceptable) toInitialize ).$$_hibernate_getInterceptor();
|
||||
if ( isPersistentAttributeInterceptable( toInitialize ) ) {
|
||||
PersistentAttributeInterceptor persistentAttributeInterceptor = asPersistentAttributeInterceptable( toInitialize ).$$_hibernate_getInterceptor();
|
||||
if ( persistentAttributeInterceptor == null || persistentAttributeInterceptor instanceof EnhancementAsProxyLazinessInterceptor ) {
|
||||
// if we do this after the entity has been initialized the BytecodeLazyAttributeInterceptor#isAttributeLoaded(String fieldName) would return false;
|
||||
concreteDescriptor.getBytecodeEnhancementMetadata().injectInterceptor(
|
||||
|
@ -905,8 +906,8 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
|
|||
return true;
|
||||
}
|
||||
|
||||
if ( toInitialize instanceof PersistentAttributeInterceptable ) {
|
||||
final PersistentAttributeInterceptor interceptor = ( (PersistentAttributeInterceptable) toInitialize ).$$_hibernate_getInterceptor();
|
||||
if ( isPersistentAttributeInterceptable( toInitialize ) ) {
|
||||
final PersistentAttributeInterceptor interceptor = asPersistentAttributeInterceptable( toInitialize ).$$_hibernate_getInterceptor();
|
||||
if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor ) {
|
||||
if ( entry.getStatus() != Status.LOADING ) {
|
||||
// Avoid loading the same entity proxy twice for the same result set: it could lead to errors,
|
||||
|
|
|
@ -16,7 +16,6 @@ import org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterc
|
|||
import org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributesMetadata;
|
||||
import org.hibernate.bytecode.spi.BytecodeEnhancementMetadata;
|
||||
import org.hibernate.bytecode.spi.NotInstrumentedException;
|
||||
import org.hibernate.engine.internal.ManagedTypeHelper;
|
||||
import org.hibernate.engine.spi.EntityKey;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||
|
@ -28,6 +27,10 @@ import org.hibernate.mapping.PersistentClass;
|
|||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.type.CompositeType;
|
||||
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptableType;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.processIfSelfDirtinessTracker;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
|
@ -42,7 +45,7 @@ public final class BytecodeEnhancementMetadataPojoImpl implements BytecodeEnhanc
|
|||
boolean collectionsInDefaultFetchGroupEnabled,
|
||||
Metadata metadata) {
|
||||
final Class<?> mappedClass = persistentClass.getMappedClass();
|
||||
final boolean enhancedForLazyLoading = ManagedTypeHelper.isPersistentAttributeInterceptableType( mappedClass );
|
||||
final boolean enhancedForLazyLoading = isPersistentAttributeInterceptableType( mappedClass );
|
||||
final LazyAttributesMetadata lazyAttributesMetadata = enhancedForLazyLoading
|
||||
? LazyAttributesMetadata.from( persistentClass, true, collectionsInDefaultFetchGroupEnabled, metadata )
|
||||
: LazyAttributesMetadata.nonEnhanced( persistentClass.getEntityName() );
|
||||
|
@ -142,13 +145,10 @@ public final class BytecodeEnhancementMetadataPojoImpl implements BytecodeEnhanc
|
|||
final PersistenceContext persistenceContext = session.getPersistenceContext();
|
||||
|
||||
// first, instantiate the entity instance to use as the proxy
|
||||
final PersistentAttributeInterceptable entity = ManagedTypeHelper.asPersistentAttributeInterceptable( persister.instantiate(
|
||||
identifier,
|
||||
session
|
||||
) );
|
||||
final PersistentAttributeInterceptable entity = asPersistentAttributeInterceptable( persister.instantiate( identifier, session ) );
|
||||
|
||||
// clear the fields that are marked as dirty in the dirtiness tracker
|
||||
ManagedTypeHelper.processIfSelfDirtinessTracker( entity, BytecodeEnhancementMetadataPojoImpl::clearDirtyAttributes );
|
||||
processIfSelfDirtinessTracker( entity, BytecodeEnhancementMetadataPojoImpl::clearDirtyAttributes );
|
||||
// add the entity (proxy) instance to the PC
|
||||
persistenceContext.addEnhancedProxy( entityKey, entity );
|
||||
|
||||
|
@ -251,7 +251,7 @@ public final class BytecodeEnhancementMetadataPojoImpl implements BytecodeEnhanc
|
|||
);
|
||||
}
|
||||
|
||||
ManagedTypeHelper.asPersistentAttributeInterceptable( entity ).$$_hibernate_setInterceptor( interceptor );
|
||||
asPersistentAttributeInterceptable( entity ).$$_hibernate_setInterceptor( interceptor );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -270,7 +270,7 @@ public final class BytecodeEnhancementMetadataPojoImpl implements BytecodeEnhanc
|
|||
);
|
||||
}
|
||||
|
||||
final PersistentAttributeInterceptor interceptor = ManagedTypeHelper.asPersistentAttributeInterceptable( entity ).$$_hibernate_getInterceptor();
|
||||
final PersistentAttributeInterceptor interceptor = asPersistentAttributeInterceptable( entity ).$$_hibernate_getInterceptor();
|
||||
if ( interceptor == null ) {
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue