HHH-7292 - Changed the EntityEntry to check the CustomDirtynessStrategy first to determine if the entity needs to continue with the dirty check. Previously if the entity had mutable properties then it would bypass the custom dirty check.

To maintain legacy functionality still checking the mutable properties before checking the instrumented dirtyFlg (if applicable)

Added a Date property to the "Thing" test entity to verify that with mutable properties that the CustomDirtynessStrategy is still called.
This commit is contained in:
Shawn Clowater 2012-05-26 20:22:26 -06:00 committed by Steve Ebersole
parent fe7a5d74c5
commit 29103357a9
2 changed files with 22 additions and 10 deletions

View File

@ -288,22 +288,26 @@ public final class EntityEntry implements Serializable {
*/ */
public boolean requiresDirtyCheck(Object entity) { public boolean requiresDirtyCheck(Object entity) {
return isModifiableEntity() return isModifiableEntity()
&& ( getPersister().hasMutableProperties() || ! isUnequivocallyNonDirty( entity ) ); && ( ! isUnequivocallyNonDirty( entity ) );
} }
@SuppressWarnings( {"SimplifiableIfStatement"}) @SuppressWarnings( {"SimplifiableIfStatement"})
private boolean isUnequivocallyNonDirty(Object entity) { private boolean isUnequivocallyNonDirty(Object entity) {
if ( getPersister().getInstrumentationMetadata().isInstrumented() ) {
// the entity must be instrumented (otherwise we cant check dirty flag) and the dirty flag is false
return ! getPersister().getInstrumentationMetadata().extractInterceptor( entity ).isDirty();
}
final CustomEntityDirtinessStrategy customEntityDirtinessStrategy = final CustomEntityDirtinessStrategy customEntityDirtinessStrategy =
persistenceContext.getSession().getFactory().getCustomEntityDirtinessStrategy(); persistenceContext.getSession().getFactory().getCustomEntityDirtinessStrategy();
if ( customEntityDirtinessStrategy.canDirtyCheck( entity, getPersister(), (Session) persistenceContext.getSession() ) ) { if ( customEntityDirtinessStrategy.canDirtyCheck( entity, getPersister(), (Session) persistenceContext.getSession() ) ) {
return ! customEntityDirtinessStrategy.isDirty( entity, getPersister(), (Session) persistenceContext.getSession() ); return ! customEntityDirtinessStrategy.isDirty( entity, getPersister(), (Session) persistenceContext.getSession() );
} }
if ( getPersister().hasMutableProperties() ) {
return false;
}
if ( getPersister().getInstrumentationMetadata().isInstrumented() ) {
// the entity must be instrumented (otherwise we cant check dirty flag) and the dirty flag is false
return ! getPersister().getInstrumentationMetadata().extractInterceptor( entity ).isDirty();
}
return false; return false;
} }

View File

@ -23,8 +23,7 @@
*/ */
package org.hibernate.test.dirtiness; package org.hibernate.test.dirtiness;
import java.util.HashMap; import java.util.*;
import java.util.Map;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
@ -43,6 +42,7 @@ public class Thing {
private Long id; private Long id;
private String name; private String name;
private Date mutableProperty;
public Thing() { public Thing() {
} }
@ -69,6 +69,14 @@ public class Thing {
this.name = name; this.name = name;
} }
public Date getMutableProperty() {
return mutableProperty;
}
public void setMutableProperty(Date mutableProperty) {
this.mutableProperty = mutableProperty;
}
@Transient @Transient
Map<String,Object> changedValues = new HashMap<String, Object>(); Map<String,Object> changedValues = new HashMap<String, Object>();
} }