HHH-6735 Let Core use InstrumentationService instead of FieldIinterceptionHelper directly
This commit is contained in:
parent
2357dcc442
commit
aef27fec41
|
@ -35,6 +35,7 @@ import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
import org.hibernate.persister.entity.UniqueKeyLoadable;
|
import org.hibernate.persister.entity.UniqueKeyLoadable;
|
||||||
import org.hibernate.pretty.MessageHelper;
|
import org.hibernate.pretty.MessageHelper;
|
||||||
|
import org.hibernate.service.instrumentation.spi.InstrumentationService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We need an entry to tell us all about the current state of an object with respect to its persistent state
|
* We need an entry to tell us all about the current state of an object with respect to its persistent state
|
||||||
|
@ -256,8 +257,8 @@ public final class EntityEntry implements Serializable {
|
||||||
public boolean requiresDirtyCheck(Object entity) {
|
public boolean requiresDirtyCheck(Object entity) {
|
||||||
return isModifiableEntity() && (
|
return isModifiableEntity() && (
|
||||||
getPersister().hasMutableProperties() ||
|
getPersister().hasMutableProperties() ||
|
||||||
!FieldInterceptionHelper.isInstrumented( entity ) ||
|
!getPersister().getFactory().getServiceRegistry().getService( InstrumentationService.class ).isInstrumented(entity) ||
|
||||||
FieldInterceptionHelper.extractFieldInterceptor( entity).isDirty()
|
FieldInterceptionHelper.extractFieldInterceptor(entity).isDirty()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ import org.hibernate.engine.internal.Versioning;
|
||||||
import org.hibernate.engine.spi.CascadingAction;
|
import org.hibernate.engine.spi.CascadingAction;
|
||||||
import org.hibernate.engine.spi.EntityEntry;
|
import org.hibernate.engine.spi.EntityEntry;
|
||||||
import org.hibernate.engine.spi.EntityKey;
|
import org.hibernate.engine.spi.EntityKey;
|
||||||
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
import org.hibernate.engine.spi.Status;
|
import org.hibernate.engine.spi.Status;
|
||||||
import org.hibernate.event.spi.EventSource;
|
import org.hibernate.event.spi.EventSource;
|
||||||
|
@ -50,6 +51,7 @@ import org.hibernate.id.IdentifierGeneratorHelper;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
import org.hibernate.pretty.MessageHelper;
|
import org.hibernate.pretty.MessageHelper;
|
||||||
|
import org.hibernate.service.instrumentation.spi.InstrumentationService;
|
||||||
import org.hibernate.type.Type;
|
import org.hibernate.type.Type;
|
||||||
import org.hibernate.type.TypeHelper;
|
import org.hibernate.type.TypeHelper;
|
||||||
|
|
||||||
|
@ -339,7 +341,10 @@ public abstract class AbstractSaveEventListener extends AbstractReassociateEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
private void markInterceptorDirty(Object entity, EntityPersister persister, EventSource source) {
|
private void markInterceptorDirty(Object entity, EntityPersister persister, EventSource source) {
|
||||||
if ( FieldInterceptionHelper.isInstrumented( entity ) ) {
|
InstrumentationService instrumentationService = persister.getFactory()
|
||||||
|
.getServiceRegistry()
|
||||||
|
.getService( InstrumentationService.class );
|
||||||
|
if ( instrumentationService.isInstrumented( entity ) ) {
|
||||||
FieldInterceptor interceptor = FieldInterceptionHelper.injectFieldInterceptor(
|
FieldInterceptor interceptor = FieldInterceptionHelper.injectFieldInterceptor(
|
||||||
entity,
|
entity,
|
||||||
persister.getEntityName(),
|
persister.getEntityName(),
|
||||||
|
|
|
@ -35,6 +35,7 @@ import org.hibernate.AssertionFailure;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.engine.internal.Cascade;
|
import org.hibernate.engine.internal.Cascade;
|
||||||
import org.hibernate.engine.spi.EntityEntry;
|
import org.hibernate.engine.spi.EntityEntry;
|
||||||
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
import org.hibernate.event.spi.EventSource;
|
import org.hibernate.event.spi.EventSource;
|
||||||
import org.hibernate.event.spi.MergeEvent;
|
import org.hibernate.event.spi.MergeEvent;
|
||||||
|
@ -53,6 +54,7 @@ import org.hibernate.engine.spi.Status;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
import org.hibernate.proxy.HibernateProxy;
|
import org.hibernate.proxy.HibernateProxy;
|
||||||
import org.hibernate.proxy.LazyInitializer;
|
import org.hibernate.proxy.LazyInitializer;
|
||||||
|
import org.hibernate.service.instrumentation.spi.InstrumentationService;
|
||||||
import org.hibernate.type.ForeignKeyDirection;
|
import org.hibernate.type.ForeignKeyDirection;
|
||||||
import org.hibernate.type.Type;
|
import org.hibernate.type.Type;
|
||||||
import org.hibernate.type.TypeHelper;
|
import org.hibernate.type.TypeHelper;
|
||||||
|
@ -493,15 +495,18 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
|
||||||
copyValues(persister, entity, target, source, copyCache);
|
copyValues(persister, entity, target, source, copyCache);
|
||||||
|
|
||||||
//copyValues works by reflection, so explicitly mark the entity instance dirty
|
//copyValues works by reflection, so explicitly mark the entity instance dirty
|
||||||
markInterceptorDirty( entity, target );
|
markInterceptorDirty( entity, target, persister.getFactory() );
|
||||||
|
|
||||||
event.setResult(result);
|
event.setResult(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void markInterceptorDirty(final Object entity, final Object target) {
|
private void markInterceptorDirty(final Object entity, final Object target, SessionFactoryImplementor factory) {
|
||||||
if ( FieldInterceptionHelper.isInstrumented( entity ) ) {
|
InstrumentationService instrumentationService = factory
|
||||||
|
.getServiceRegistry()
|
||||||
|
.getService( InstrumentationService.class );
|
||||||
|
if ( instrumentationService.isInstrumented( entity ) ) {
|
||||||
FieldInterceptor interceptor = FieldInterceptionHelper.extractFieldInterceptor( target );
|
FieldInterceptor interceptor = FieldInterceptionHelper.extractFieldInterceptor( target );
|
||||||
if ( interceptor != null ) {
|
if ( interceptor != null ) {
|
||||||
interceptor.dirty();
|
interceptor.dirty();
|
||||||
|
|
|
@ -104,6 +104,7 @@ import org.hibernate.metamodel.relational.DerivedValue;
|
||||||
import org.hibernate.metamodel.relational.Value;
|
import org.hibernate.metamodel.relational.Value;
|
||||||
import org.hibernate.pretty.MessageHelper;
|
import org.hibernate.pretty.MessageHelper;
|
||||||
import org.hibernate.property.BackrefPropertyAccessor;
|
import org.hibernate.property.BackrefPropertyAccessor;
|
||||||
|
import org.hibernate.service.instrumentation.spi.InstrumentationService;
|
||||||
import org.hibernate.sql.Alias;
|
import org.hibernate.sql.Alias;
|
||||||
import org.hibernate.sql.Delete;
|
import org.hibernate.sql.Delete;
|
||||||
import org.hibernate.sql.Insert;
|
import org.hibernate.sql.Insert;
|
||||||
|
@ -3943,7 +3944,10 @@ public abstract class AbstractEntityPersister
|
||||||
|
|
||||||
public void afterReassociate(Object entity, SessionImplementor session) {
|
public void afterReassociate(Object entity, SessionImplementor session) {
|
||||||
//if ( hasLazyProperties() ) {
|
//if ( hasLazyProperties() ) {
|
||||||
if ( FieldInterceptionHelper.isInstrumented( entity ) ) {
|
InstrumentationService instrumentationService = session.getFactory()
|
||||||
|
.getServiceRegistry()
|
||||||
|
.getService( InstrumentationService.class );
|
||||||
|
if ( instrumentationService.isInstrumented( entity ) ) {
|
||||||
FieldInterceptor interceptor = FieldInterceptionHelper.extractFieldInterceptor( entity );
|
FieldInterceptor interceptor = FieldInterceptionHelper.extractFieldInterceptor( entity );
|
||||||
if ( interceptor != null ) {
|
if ( interceptor != null ) {
|
||||||
interceptor.setSession( session );
|
interceptor.setSession( session );
|
||||||
|
|
|
@ -55,6 +55,7 @@ import org.hibernate.metamodel.binding.BasicAttributeBinding;
|
||||||
import org.hibernate.metamodel.binding.EntityBinding;
|
import org.hibernate.metamodel.binding.EntityBinding;
|
||||||
import org.hibernate.metamodel.domain.Attribute;
|
import org.hibernate.metamodel.domain.Attribute;
|
||||||
import org.hibernate.metamodel.domain.SingularAttribute;
|
import org.hibernate.metamodel.domain.SingularAttribute;
|
||||||
|
import org.hibernate.service.instrumentation.spi.InstrumentationService;
|
||||||
import org.hibernate.tuple.IdentifierProperty;
|
import org.hibernate.tuple.IdentifierProperty;
|
||||||
import org.hibernate.tuple.PropertyFactory;
|
import org.hibernate.tuple.PropertyFactory;
|
||||||
import org.hibernate.tuple.StandardProperty;
|
import org.hibernate.tuple.StandardProperty;
|
||||||
|
@ -131,6 +132,7 @@ public class EntityMetamodel implements Serializable {
|
||||||
|
|
||||||
private final EntityMode entityMode;
|
private final EntityMode entityMode;
|
||||||
private final EntityTuplizer entityTuplizer;
|
private final EntityTuplizer entityTuplizer;
|
||||||
|
private boolean lazyAvailable;
|
||||||
|
|
||||||
public EntityMetamodel(PersistentClass persistentClass, SessionFactoryImplementor sessionFactory) {
|
public EntityMetamodel(PersistentClass persistentClass, SessionFactoryImplementor sessionFactory) {
|
||||||
this.sessionFactory = sessionFactory;
|
this.sessionFactory = sessionFactory;
|
||||||
|
@ -146,8 +148,9 @@ public class EntityMetamodel implements Serializable {
|
||||||
|
|
||||||
versioned = persistentClass.isVersioned();
|
versioned = persistentClass.isVersioned();
|
||||||
|
|
||||||
boolean lazyAvailable = persistentClass.hasPojoRepresentation() &&
|
InstrumentationService instrumentationService = sessionFactory.getServiceRegistry().getService( InstrumentationService.class );
|
||||||
FieldInterceptionHelper.isInstrumented( persistentClass.getMappedClass() );
|
lazyAvailable = persistentClass.hasPojoRepresentation() &&
|
||||||
|
instrumentationService.isInstrumented( persistentClass.getMappedClass() );
|
||||||
boolean hasLazy = false;
|
boolean hasLazy = false;
|
||||||
|
|
||||||
propertySpan = persistentClass.getPropertyClosureSpan();
|
propertySpan = persistentClass.getPropertyClosureSpan();
|
||||||
|
@ -373,12 +376,14 @@ public class EntityMetamodel implements Serializable {
|
||||||
boolean hasPojoRepresentation = false;
|
boolean hasPojoRepresentation = false;
|
||||||
Class<?> mappedClass = null;
|
Class<?> mappedClass = null;
|
||||||
Class<?> proxyInterfaceClass = null;
|
Class<?> proxyInterfaceClass = null;
|
||||||
boolean lazyAvailable = false;
|
lazyAvailable = false;
|
||||||
if ( entityBinding.getEntity().getClassReferenceUnresolved() != null ) {
|
if ( entityBinding.getEntity().getClassReferenceUnresolved() != null ) {
|
||||||
hasPojoRepresentation = true;
|
hasPojoRepresentation = true;
|
||||||
mappedClass = entityBinding.getEntity().getClassReference();
|
mappedClass = entityBinding.getEntity().getClassReference();
|
||||||
proxyInterfaceClass = entityBinding.getProxyInterfaceType().getValue();
|
proxyInterfaceClass = entityBinding.getProxyInterfaceType().getValue();
|
||||||
lazyAvailable = FieldInterceptionHelper.isInstrumented( mappedClass );
|
InstrumentationService instrumentationService = sessionFactory.getServiceRegistry()
|
||||||
|
.getService( InstrumentationService.class );
|
||||||
|
lazyAvailable = instrumentationService.isInstrumented( mappedClass );
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasLazy = false;
|
boolean hasLazy = false;
|
||||||
|
@ -935,4 +940,11 @@ public class EntityMetamodel implements Serializable {
|
||||||
public EntityMode getEntityMode() {
|
public EntityMode getEntityMode() {
|
||||||
return entityMode;
|
return entityMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not this class can be lazy (ie intercepted)
|
||||||
|
*/
|
||||||
|
public boolean isInstrumented() {
|
||||||
|
return lazyAvailable;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,12 +76,14 @@ public class PojoEntityTuplizer extends AbstractEntityTuplizer {
|
||||||
private final boolean lifecycleImplementor;
|
private final boolean lifecycleImplementor;
|
||||||
private final Set lazyPropertyNames = new HashSet();
|
private final Set lazyPropertyNames = new HashSet();
|
||||||
private final ReflectionOptimizer optimizer;
|
private final ReflectionOptimizer optimizer;
|
||||||
|
private final boolean isInstrumented;
|
||||||
|
|
||||||
public PojoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) {
|
public PojoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) {
|
||||||
super( entityMetamodel, mappedEntity );
|
super( entityMetamodel, mappedEntity );
|
||||||
this.mappedClass = mappedEntity.getMappedClass();
|
this.mappedClass = mappedEntity.getMappedClass();
|
||||||
this.proxyInterface = mappedEntity.getProxyInterface();
|
this.proxyInterface = mappedEntity.getProxyInterface();
|
||||||
this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedClass );
|
this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedClass );
|
||||||
|
this.isInstrumented = entityMetamodel.isInstrumented();
|
||||||
|
|
||||||
Iterator iter = mappedEntity.getPropertyClosureIterator();
|
Iterator iter = mappedEntity.getPropertyClosureIterator();
|
||||||
while ( iter.hasNext() ) {
|
while ( iter.hasNext() ) {
|
||||||
|
@ -118,6 +120,7 @@ public class PojoEntityTuplizer extends AbstractEntityTuplizer {
|
||||||
this.mappedClass = mappedEntity.getEntity().getClassReference();
|
this.mappedClass = mappedEntity.getEntity().getClassReference();
|
||||||
this.proxyInterface = mappedEntity.getProxyInterfaceType().getValue();
|
this.proxyInterface = mappedEntity.getProxyInterfaceType().getValue();
|
||||||
this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedClass );
|
this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedClass );
|
||||||
|
this.isInstrumented = entityMetamodel.isInstrumented();
|
||||||
|
|
||||||
for ( AttributeBinding property : mappedEntity.getAttributeBindingClosure() ) {
|
for ( AttributeBinding property : mappedEntity.getAttributeBindingClosure() ) {
|
||||||
if ( property.isLazy() ) {
|
if ( property.isLazy() ) {
|
||||||
|
@ -520,7 +523,7 @@ public class PojoEntityTuplizer extends AbstractEntityTuplizer {
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public boolean isInstrumented() {
|
public boolean isInstrumented() {
|
||||||
return FieldInterceptionHelper.isInstrumented( getMappedClass() );
|
return isInstrumented;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue