HHH-3910 - custom dirty flag tracking

This commit is contained in:
Steve Ebersole 2012-01-25 12:38:57 -06:00
parent 34c2fa4409
commit 72e382b045
3 changed files with 15 additions and 17 deletions

View File

@ -33,8 +33,12 @@ import org.hibernate.engine.spi.SessionImplementor;
/** /**
* Helper class for dealing with enhanced entity classes. * Helper class for dealing with enhanced entity classes.
* *
* These operations are expensive. When under a SessionFactory, try and use (or guard with) * These operations are expensive. They are only meant to be used when code does not have access to a
* {@link org.hibernate.service.instrumentation.spi.InstrumentationService#isInstrumented} * SessionFactory (namely from the instrumentation tasks). When code has access to a SessionFactory,
* {@link org.hibernate.bytecode.spi.EntityInstrumentationMetadata} should be used instead to query the
* instrumentation state. EntityInstrumentationMetadata is accessed from the
* {@link org.hibernate.persister.entity.EntityPersister} via the
* {@link org.hibernate.persister.entity.EntityPersister#getInstrumentationMetadata()} method.
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@ -96,20 +100,6 @@ public class FieldInterceptionHelper {
return interceptor; return interceptor;
} }
public static void clearDirty(Object entity) {
FieldInterceptor interceptor = extractFieldInterceptor( entity );
if ( interceptor != null ) {
interceptor.clearDirty();
}
}
public static void markDirty(Object entity) {
FieldInterceptor interceptor = extractFieldInterceptor( entity );
if ( interceptor != null ) {
interceptor.dirty();
}
}
private static interface Delegate { private static interface Delegate {
public boolean isInstrumented(Class classToCheck); public boolean isInstrumented(Class classToCheck);
public FieldInterceptor extractInterceptor(Object entity); public FieldInterceptor extractInterceptor(Object entity);

View File

@ -223,7 +223,7 @@ public final class EntityEntry implements Serializable {
*/ */
public void postUpdate(Object entity, Object[] updatedState, Object nextVersion) { public void postUpdate(Object entity, Object[] updatedState, Object nextVersion) {
this.loadedState = updatedState; this.loadedState = updatedState;
setLockMode(LockMode.WRITE); setLockMode( LockMode.WRITE );
if ( getPersister().isVersioned() ) { if ( getPersister().isVersioned() ) {
this.version = nextVersion; this.version = nextVersion;
@ -234,6 +234,10 @@ public final class EntityEntry implements Serializable {
if ( interceptor != null ) { if ( interceptor != null ) {
interceptor.clearDirty(); interceptor.clearDirty();
} }
persistenceContext.getSession()
.getFactory()
.getCustomEntityDirtinessStrategy()
.resetDirty( entity, (Session) persistenceContext.getSession() );
} }
notifyLoadedStateUpdated(); notifyLoadedStateUpdated();

View File

@ -249,6 +249,10 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
.extractInterceptor( event.getEntity() ) .extractInterceptor( event.getEntity() )
.clearDirty(); .clearDirty();
} }
event.getSession()
.getFactory()
.getCustomEntityDirtinessStrategy()
.resetDirty( event.getEntity(), event.getSession() );
return false; return false;
} }
} }