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) {
return isModifiableEntity()
&& ( getPersister().hasMutableProperties() || ! isUnequivocallyNonDirty( entity ) );
&& ( ! isUnequivocallyNonDirty( entity ) );
}
@SuppressWarnings( {"SimplifiableIfStatement"})
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 =
persistenceContext.getSession().getFactory().getCustomEntityDirtinessStrategy();
if ( customEntityDirtinessStrategy.canDirtyCheck( 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;
}

View File

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