#2710 - Update PersistRequestBean with checkAllMutableProperties() and checkAnyMutableProperties()

This commit is contained in:
Rob Bygrave
2022-06-13 18:58:38 +12:00
parent 8301fd5e74
commit e29d83a379
2 changed files with 24 additions and 8 deletions
@@ -147,10 +147,9 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
// 'stateless update' - set loaded properties as dirty
intercept.setNewBeanForUpdate();
statelessUpdate = true;
}
if (!intercept.isDirty()) {
// check if mutable scalar properties are dirty
beanDescriptor.checkMutableProperties(intercept);
} else if (!intercept.isDirty()) {
// check if any mutable scalar properties are dirty
beanDescriptor.checkAnyMutableProperties(intercept);
}
}
this.concurrencyMode = beanDescriptor.concurrencyMode(intercept);
@@ -1205,8 +1204,8 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
private void executeUpdate() {
setTenantId();
if (controller == null || controller.preUpdate(this)) {
// check dirty state for mutable scalar properties (like DbJson, Hstore)
beanDescriptor.checkMutableProperties(intercept);
// check dirty state for all mutable scalar properties (like DbJson, Hstore)
beanDescriptor.checkAllMutableProperties(intercept);
if (beanPersistListener != null) {
updatedProperties = updatedProperties();
}
@@ -3140,9 +3140,9 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType, SpiBeanType {
}
/**
* Check for mutable scalar types and mark as dirty if necessary.
* Check all mutable scalar types and mark as dirty if necessary.
*/
public void checkMutableProperties(EntityBeanIntercept ebi) {
public void checkAllMutableProperties(EntityBeanIntercept ebi) {
for (BeanProperty beanProperty : propertiesMutable) {
int propertyIndex = beanProperty.propertyIndex();
if (ebi.isLoadedProperty(propertyIndex)) {
@@ -3156,6 +3156,23 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType, SpiBeanType {
}
}
/**
* Return true if any mutable properties are dirty.
*/
public boolean checkAnyMutableProperties(EntityBeanIntercept ebi) {
for (BeanProperty beanProperty : propertiesMutable) {
int propertyIndex = beanProperty.propertyIndex();
if (ebi.isLoadedProperty(propertyIndex)) {
Object value = beanProperty.getValue(ebi.getOwner());
if (beanProperty.checkMutable(value, ebi.isDirtyProperty(propertyIndex), ebi)) {
ebi.markPropertyAsChanged(propertyIndex);
return true;
}
}
}
return false;
}
public ConcurrencyMode concurrencyMode(EntityBeanIntercept ebi) {
if (!hasVersionProperty(ebi)) {
return ConcurrencyMode.NONE;