some javadoc and refactored getOrigValue

This commit is contained in:
Roland Praml
2021-07-28 17:36:53 +02:00
parent b497b8635b
commit eb70c7e196
2 changed files with 18 additions and 7 deletions
@@ -470,6 +470,10 @@ public final class EntityBeanIntercept implements Serializable {
* Return the original value that was changed via an update.
*/
public Object getOrigValue(int propertyIndex) {
if ((flags[propertyIndex] & (FLAG_ORIG_VALUE_SET | FLAG_MUTABLE_HASH_SET)) == FLAG_MUTABLE_HASH_SET) {
// mutable hash set, but not ORIG_VALUE
setOriginalValue(propertyIndex, mutableHash[propertyIndex].get());
}
if (origValues == null) {
return null;
}
@@ -718,11 +722,6 @@ public final class EntityBeanIntercept implements Serializable {
String propName = (prefix == null ? getProperty(i) : prefix + getProperty(i));
Object newVal = owner._ebean_getField(i);
Object oldVal = getOrigValue(i);
if ((flags[i] & (FLAG_ORIG_VALUE_SET | FLAG_MUTABLE_HASH_SET)) == FLAG_MUTABLE_HASH_SET) {
// mutable hash set, but not ORIG_VALUE
oldVal = mutableHash[i].get();
setOriginalValue(i, oldVal);
}
if (notEqual(oldVal, newVal)) {
dirtyValues.put(propName, new ValuePair(newVal, oldVal));
}
@@ -1,14 +1,26 @@
package io.ebean.bean;
/**
* Interface to for mutable information in EntityBeanIntercept.
*/
public interface MutableHash {
/**
* Compares the given json to an internal value. Can be a MD5 hash or a plain JSON string.
* @return true if the value matches the hash.
*/
boolean isEqualToJson(String json);
/**
* Compares the given object to an internal value. This is an optional method, but required for proper changelog/beanState support.
* The implementation can serialize the object and compare it against the original json.
*/
default boolean isEqualToObject(Object obj) {
return true;
}
/**
* Creates a new instance from the internal json string. This is an optional method.
*/
default Object get() {
return null;
}