mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
#88 - v4 - Breaking API Change - BeanPersistRequest.getOldValues() replaced with ... Map<String,ValuePair> getUpdatedValues()
This commit is contained in:
1 parent
fc628d336d
commit
2344f57f84
13 files changed
+377
-86
No files matched your search
@@ -1,9 +1,11 @@
|
||||
package com.avaje.ebeaninternal.server.core;
|
||||
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.avaje.ebean.BeanState;
|
||||
import com.avaje.ebean.ValuePair;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.bean.EntityBeanIntercept;
|
||||
|
||||
@@ -12,9 +14,9 @@ import com.avaje.ebean.bean.EntityBeanIntercept;
|
||||
*/
|
||||
public class DefaultBeanState implements BeanState {
|
||||
|
||||
final EntityBean entityBean;
|
||||
private final EntityBean entityBean;
|
||||
|
||||
final EntityBeanIntercept intercept;
|
||||
private final EntityBeanIntercept intercept;
|
||||
|
||||
public DefaultBeanState(EntityBean entityBean){
|
||||
this.entityBean = entityBean;
|
||||
@@ -42,7 +44,11 @@ public class DefaultBeanState implements BeanState {
|
||||
}
|
||||
|
||||
public Set<String> getChangedProps() {
|
||||
return intercept.getChangedPropertyNames();
|
||||
return intercept.getDirtyPropertyNames();
|
||||
}
|
||||
|
||||
public Map<String,ValuePair> getDirtyValues() {
|
||||
return intercept.getDirtyValues();
|
||||
}
|
||||
|
||||
public boolean isReadOnly() {
|
||||
@@ -69,5 +75,4 @@ public class DefaultBeanState implements BeanState {
|
||||
intercept.setReference();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,7 +5,9 @@ import java.util.Map;
|
||||
|
||||
import com.avaje.ebean.ValuePair;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.bean.EntityBeanIntercept;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
|
||||
|
||||
/**
|
||||
@@ -30,17 +32,16 @@ public class DiffHelp {
|
||||
*/
|
||||
public Map<String, ValuePair> diff(Object a, Object b, BeanDescriptor<?> desc) {
|
||||
|
||||
boolean oldValues = false;
|
||||
Map<String, ValuePair> map = new LinkedHashMap<String, ValuePair>();
|
||||
|
||||
if (b == null) {
|
||||
// get the old values from a
|
||||
if (a instanceof EntityBean) {
|
||||
EntityBean eb = (EntityBean) a;
|
||||
b = null;//FIXME eb._ebean_getIntercept().getOldValues();
|
||||
oldValues = true;
|
||||
return ((EntityBean) a)._ebean_getIntercept().getDirtyValues();
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
Map<String, ValuePair> map = new LinkedHashMap<String, ValuePair>();
|
||||
|
||||
// if (b == null) {
|
||||
// return map;
|
||||
@@ -70,8 +71,7 @@ public class DiffHelp {
|
||||
* determined to be different as is added to the map.
|
||||
* </p>
|
||||
*/
|
||||
private void diffEmbedded(Object a, Object b, BeanDescriptor<?> desc, Map<String, ValuePair> map,
|
||||
boolean oldValues) {
|
||||
private void diffEmbedded(Object a, Object b, BeanDescriptor<?> desc, Map<String, ValuePair> map, boolean oldValues) {
|
||||
|
||||
// BeanPropertyAssocOne<?>[] emb = desc.propertiesEmbedded();
|
||||
//
|
||||
|
||||
@@ -2,9 +2,12 @@ package com.avaje.ebeaninternal.server.core;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.OptimisticLockException;
|
||||
|
||||
import com.avaje.ebean.ValuePair;
|
||||
import com.avaje.ebean.annotation.ConcurrencyMode;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.bean.EntityBeanIntercept;
|
||||
@@ -79,6 +82,8 @@ public class PersistRequestBean<T> extends PersistRequest implements BeanPersist
|
||||
private boolean statelessUpdate;
|
||||
private boolean deleteMissingChildren;
|
||||
private boolean updateNullProperties;
|
||||
|
||||
private final Set<String> dirtyPropertyNames;
|
||||
|
||||
public PersistRequestBean(SpiEbeanServer server, T bean, Object parentBean, BeanManager<T> mgr,
|
||||
SpiTransaction t, PersistExecute persistExecute) {
|
||||
@@ -89,6 +94,8 @@ public class PersistRequestBean<T> extends PersistRequest implements BeanPersist
|
||||
this.beanManager = mgr;
|
||||
this.beanDescriptor = mgr.getBeanDescriptor();
|
||||
this.beanPersistListener = beanDescriptor.getPersistListener();
|
||||
this.dirtyPropertyNames = (beanPersistListener == null) ? null : intercept.getDirtyPropertyNames();
|
||||
|
||||
this.bean = bean;
|
||||
this.parentBean = parentBean;
|
||||
|
||||
@@ -101,9 +108,23 @@ public class PersistRequestBean<T> extends PersistRequest implements BeanPersist
|
||||
// this is ok to not use isNewOrDirty() as used for updates only
|
||||
this.isDirty = intercept.isDirty();
|
||||
}
|
||||
|
||||
|
||||
public void setNotNullAsLoaded() {
|
||||
@Override
|
||||
public Set<String> getLoadedProperties() {
|
||||
return intercept.getLoadedPropertyNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getUpdatedProperties() {
|
||||
return intercept.getDirtyPropertyNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ValuePair> getUpdatedValues() {
|
||||
return intercept.getDirtyValues();
|
||||
}
|
||||
|
||||
public void setNotNullAsLoaded() {
|
||||
BeanProperty[] props = beanDescriptor.propertiesNonMany();
|
||||
for (int i=0; i< props.length; i++) {
|
||||
BeanProperty prop = props[i];
|
||||
@@ -163,7 +184,7 @@ public class PersistRequestBean<T> extends PersistRequest implements BeanPersist
|
||||
return beanPersistListener.inserted(bean);
|
||||
|
||||
case UPDATE:
|
||||
return beanPersistListener.updated(bean);//, getUpdatedProperties());
|
||||
return beanPersistListener.updated(bean, dirtyPropertyNames);
|
||||
|
||||
case DELETE:
|
||||
return beanPersistListener.deleted(bean);
|
||||
@@ -558,7 +579,7 @@ public class PersistRequestBean<T> extends PersistRequest implements BeanPersist
|
||||
* update.
|
||||
*/
|
||||
public boolean isAddToUpdate(BeanProperty prop) {
|
||||
return intercept.isChangedProperty(prop.getPropertyIndex());
|
||||
return intercept.isDirtyProperty(prop.getPropertyIndex());
|
||||
}
|
||||
|
||||
public List<DerivedRelationshipData> getDerivedRelationships() {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.avaje.ebean.event.BeanPersistListener;
|
||||
|
||||
@@ -11,6 +12,7 @@ import com.avaje.ebean.event.BeanPersistListener;
|
||||
public class ChainedBeanPersistListener<T> implements BeanPersistListener<T> {
|
||||
|
||||
private final List<BeanPersistListener<T>> list;
|
||||
|
||||
private final BeanPersistListener<T>[] chain;
|
||||
|
||||
/**
|
||||
@@ -109,10 +111,10 @@ public class ChainedBeanPersistListener<T> implements BeanPersistListener<T> {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updated(T bean) {
|
||||
public boolean updated(T bean, Set<String> updatedProperties) {
|
||||
boolean notifyCluster = false;
|
||||
for (int i = 0; i < chain.length; i++) {
|
||||
if (chain[i].updated(bean)) {
|
||||
if (chain[i].updated(bean, updatedProperties)) {
|
||||
notifyCluster = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class GenerateDmlRequest {
|
||||
return true;
|
||||
}
|
||||
if (changesOnly) {
|
||||
return ebi.isChangedProperty(prop.getPropertyIndex());
|
||||
return ebi.isDirtyProperty(prop.getPropertyIndex());
|
||||
} else {
|
||||
return ebi.isLoadedProperty(prop.getPropertyIndex());
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import com.avaje.ebeaninternal.api.SpiUpdatePlan;
|
||||
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
|
||||
import com.avaje.ebeaninternal.server.persist.dmlbind.Bindable;
|
||||
import com.avaje.ebeaninternal.server.persist.dmlbind.BindableId;
|
||||
import com.avaje.ebeaninternal.server.persist.dmlbind.BindableList;
|
||||
@@ -115,20 +114,10 @@ public final class UpdateMeta {
|
||||
// we can use a cached UpdatePlan for the changed properties
|
||||
|
||||
EntityBeanIntercept ebi = persistRequest.getEntityBeanIntercept();
|
||||
int hash = ebi.getChangedPropertiesHash();
|
||||
int hash = ebi.getDirtyPropertyHash();
|
||||
|
||||
BeanDescriptor<?> beanDescriptor = persistRequest.getBeanDescriptor();
|
||||
|
||||
BeanPropertyAssocOne<?>[] propertiesEmbedded = beanDescriptor.propertiesEmbedded();
|
||||
for (int i=0; i< propertiesEmbedded.length; i++) {
|
||||
EntityBean embeddedBean = (EntityBean)propertiesEmbedded[i].getValue(persistRequest.getEntityBean());
|
||||
if (embeddedBean == null) {
|
||||
hash = hash * 31;
|
||||
} else {
|
||||
hash = hash * 31 + embeddedBean._ebean_getIntercept().getChangedPropertiesHash();
|
||||
}
|
||||
}
|
||||
|
||||
BeanProperty versionProperty = beanDescriptor.getVersionProperty();
|
||||
if (versionProperty != null) {
|
||||
if (ebi.isLoadedProperty(versionProperty.getPropertyIndex())) {
|
||||
|
||||
Reference in new issue
Block a user