HHH-6735 Let Core use InstrumentationService instead of FieldIinterceptionHelper directly

This commit is contained in:
Emmanuel Bernard 2011-10-17 16:12:05 +02:00
parent 2357dcc442
commit aef27fec41
6 changed files with 43 additions and 13 deletions

View File

@ -35,6 +35,7 @@ import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.entity.UniqueKeyLoadable;
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
@ -256,8 +257,8 @@ public final class EntityEntry implements Serializable {
public boolean requiresDirtyCheck(Object entity) {
return isModifiableEntity() && (
getPersister().hasMutableProperties() ||
!FieldInterceptionHelper.isInstrumented( entity ) ||
FieldInterceptionHelper.extractFieldInterceptor( entity).isDirty()
!getPersister().getFactory().getServiceRegistry().getService( InstrumentationService.class ).isInstrumented(entity) ||
FieldInterceptionHelper.extractFieldInterceptor(entity).isDirty()
);
}

View File

@ -42,6 +42,7 @@ import org.hibernate.engine.internal.Versioning;
import org.hibernate.engine.spi.CascadingAction;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.Status;
import org.hibernate.event.spi.EventSource;
@ -50,6 +51,7 @@ import org.hibernate.id.IdentifierGeneratorHelper;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.service.instrumentation.spi.InstrumentationService;
import org.hibernate.type.Type;
import org.hibernate.type.TypeHelper;
@ -339,7 +341,10 @@ public abstract class AbstractSaveEventListener extends AbstractReassociateEvent
}
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(
entity,
persister.getEntityName(),

View File

@ -35,6 +35,7 @@ import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.engine.internal.Cascade;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.event.spi.EventSource;
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.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
import org.hibernate.service.instrumentation.spi.InstrumentationService;
import org.hibernate.type.ForeignKeyDirection;
import org.hibernate.type.Type;
import org.hibernate.type.TypeHelper;
@ -493,15 +495,18 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
copyValues(persister, entity, target, source, copyCache);
//copyValues works by reflection, so explicitly mark the entity instance dirty
markInterceptorDirty( entity, target );
markInterceptorDirty( entity, target, persister.getFactory() );
event.setResult(result);
}
}
private void markInterceptorDirty(final Object entity, final Object target) {
if ( FieldInterceptionHelper.isInstrumented( entity ) ) {
private void markInterceptorDirty(final Object entity, final Object target, SessionFactoryImplementor factory) {
InstrumentationService instrumentationService = factory
.getServiceRegistry()
.getService( InstrumentationService.class );
if ( instrumentationService.isInstrumented( entity ) ) {
FieldInterceptor interceptor = FieldInterceptionHelper.extractFieldInterceptor( target );
if ( interceptor != null ) {
interceptor.dirty();

View File

@ -104,6 +104,7 @@ import org.hibernate.metamodel.relational.DerivedValue;
import org.hibernate.metamodel.relational.Value;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.property.BackrefPropertyAccessor;
import org.hibernate.service.instrumentation.spi.InstrumentationService;
import org.hibernate.sql.Alias;
import org.hibernate.sql.Delete;
import org.hibernate.sql.Insert;
@ -3943,7 +3944,10 @@ public abstract class AbstractEntityPersister
public void afterReassociate(Object entity, SessionImplementor session) {
//if ( hasLazyProperties() ) {
if ( FieldInterceptionHelper.isInstrumented( entity ) ) {
InstrumentationService instrumentationService = session.getFactory()
.getServiceRegistry()
.getService( InstrumentationService.class );
if ( instrumentationService.isInstrumented( entity ) ) {
FieldInterceptor interceptor = FieldInterceptionHelper.extractFieldInterceptor( entity );
if ( interceptor != null ) {
interceptor.setSession( session );

View File

@ -55,6 +55,7 @@ import org.hibernate.metamodel.binding.BasicAttributeBinding;
import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.domain.Attribute;
import org.hibernate.metamodel.domain.SingularAttribute;
import org.hibernate.service.instrumentation.spi.InstrumentationService;
import org.hibernate.tuple.IdentifierProperty;
import org.hibernate.tuple.PropertyFactory;
import org.hibernate.tuple.StandardProperty;
@ -131,6 +132,7 @@ public class EntityMetamodel implements Serializable {
private final EntityMode entityMode;
private final EntityTuplizer entityTuplizer;
private boolean lazyAvailable;
public EntityMetamodel(PersistentClass persistentClass, SessionFactoryImplementor sessionFactory) {
this.sessionFactory = sessionFactory;
@ -146,8 +148,9 @@ public class EntityMetamodel implements Serializable {
versioned = persistentClass.isVersioned();
boolean lazyAvailable = persistentClass.hasPojoRepresentation() &&
FieldInterceptionHelper.isInstrumented( persistentClass.getMappedClass() );
InstrumentationService instrumentationService = sessionFactory.getServiceRegistry().getService( InstrumentationService.class );
lazyAvailable = persistentClass.hasPojoRepresentation() &&
instrumentationService.isInstrumented( persistentClass.getMappedClass() );
boolean hasLazy = false;
propertySpan = persistentClass.getPropertyClosureSpan();
@ -373,12 +376,14 @@ public class EntityMetamodel implements Serializable {
boolean hasPojoRepresentation = false;
Class<?> mappedClass = null;
Class<?> proxyInterfaceClass = null;
boolean lazyAvailable = false;
if ( entityBinding.getEntity().getClassReferenceUnresolved() != null ) {
lazyAvailable = false;
if ( entityBinding.getEntity().getClassReferenceUnresolved() != null ) {
hasPojoRepresentation = true;
mappedClass = entityBinding.getEntity().getClassReference();
proxyInterfaceClass = entityBinding.getProxyInterfaceType().getValue();
lazyAvailable = FieldInterceptionHelper.isInstrumented( mappedClass );
InstrumentationService instrumentationService = sessionFactory.getServiceRegistry()
.getService( InstrumentationService.class );
lazyAvailable = instrumentationService.isInstrumented( mappedClass );
}
boolean hasLazy = false;
@ -935,4 +940,11 @@ public class EntityMetamodel implements Serializable {
public EntityMode getEntityMode() {
return entityMode;
}
/**
* Whether or not this class can be lazy (ie intercepted)
*/
public boolean isInstrumented() {
return lazyAvailable;
}
}

View File

@ -76,12 +76,14 @@ public class PojoEntityTuplizer extends AbstractEntityTuplizer {
private final boolean lifecycleImplementor;
private final Set lazyPropertyNames = new HashSet();
private final ReflectionOptimizer optimizer;
private final boolean isInstrumented;
public PojoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) {
super( entityMetamodel, mappedEntity );
this.mappedClass = mappedEntity.getMappedClass();
this.proxyInterface = mappedEntity.getProxyInterface();
this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedClass );
this.isInstrumented = entityMetamodel.isInstrumented();
Iterator iter = mappedEntity.getPropertyClosureIterator();
while ( iter.hasNext() ) {
@ -118,6 +120,7 @@ public class PojoEntityTuplizer extends AbstractEntityTuplizer {
this.mappedClass = mappedEntity.getEntity().getClassReference();
this.proxyInterface = mappedEntity.getProxyInterfaceType().getValue();
this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedClass );
this.isInstrumented = entityMetamodel.isInstrumented();
for ( AttributeBinding property : mappedEntity.getAttributeBindingClosure() ) {
if ( property.isLazy() ) {
@ -520,7 +523,7 @@ public class PojoEntityTuplizer extends AbstractEntityTuplizer {
* {@inheritDoc}
*/
public boolean isInstrumented() {
return FieldInterceptionHelper.isInstrumented( getMappedClass() );
return isInstrumented;
}
/**