mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#296 - ENH: Add to transaction setUpdateAllLoadedProperties() - force update all properties api
This commit is contained in:
@@ -97,6 +97,17 @@ public interface Transaction extends Closeable {
|
||||
*/
|
||||
void setPersistCascade(boolean persistCascade);
|
||||
|
||||
/**
|
||||
* Set to true when you want all loaded properties to be included in the update
|
||||
* (rather than just the changed properties).
|
||||
* <p>
|
||||
* You might set this when using JDBC batch in order to get multiple updates
|
||||
* with slightly different sets of changed properties into the same statement
|
||||
* and hence better JDBC batch performance.
|
||||
* </p>
|
||||
*/
|
||||
void setUpdateAllLoadedProperties(boolean updateAllLoadedProperties);
|
||||
|
||||
/**
|
||||
* Turn on or off statement batching. Statement batching can be transparent
|
||||
* for drivers and databases that support getGeneratedKeys. Otherwise you may
|
||||
|
||||
@@ -608,7 +608,7 @@ public final class EntityBeanIntercept implements Serializable {
|
||||
} else if (embeddedDirty != null && embeddedDirty[i]) {
|
||||
// an embedded property has been changed - recurse
|
||||
EntityBean embeddedBean = (EntityBean)owner._ebean_getField(i);
|
||||
embeddedBean._ebean_getIntercept().addDirtyPropertyValues(dirtyValues, getProperty(i)+".");
|
||||
embeddedBean._ebean_getIntercept().addDirtyPropertyValues(dirtyValues, getProperty(i) + ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -638,6 +638,20 @@ public final class EntityBeanIntercept implements Serializable {
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a loaded property hash.
|
||||
*/
|
||||
public int getLoadedPropertyHash() {
|
||||
int hash = 37;
|
||||
int len = getPropertyLength();
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (isLoadedProperty(i)) {
|
||||
hash = hash * 31 + (i+1);
|
||||
}
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the set of property names for changed properties.
|
||||
*/
|
||||
|
||||
@@ -152,6 +152,16 @@ public class ScopedTransaction implements SpiTransaction {
|
||||
transaction.setPersistCascade(persistCascade);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUpdateAllLoadedProperties(boolean updateAllLoaded) {
|
||||
transaction.setUpdateAllLoadedProperties(updateAllLoaded);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpdateAllLoadedProperties() {
|
||||
return transaction.isUpdateAllLoadedProperties();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBatchMode(boolean useBatch) {
|
||||
transaction.setBatchMode(useBatch);
|
||||
|
||||
@@ -99,6 +99,11 @@ public interface SpiTransaction extends Transaction {
|
||||
*/
|
||||
String getId();
|
||||
|
||||
/**
|
||||
* Return true if this transaction has updateAllLoadedProperties set.
|
||||
*/
|
||||
boolean isUpdateAllLoadedProperties();
|
||||
|
||||
/**
|
||||
* Return the batchSize specifically set for this transaction or 0.
|
||||
* <p>
|
||||
|
||||
@@ -641,10 +641,14 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the property value has changed and if so include it in the update.
|
||||
* Return true if the property should be included in the update.
|
||||
*/
|
||||
public boolean isAddToUpdate(BeanProperty prop) {
|
||||
return intercept.isDirtyProperty(prop.getPropertyIndex());
|
||||
if (transaction.isUpdateAllLoadedProperties()) {
|
||||
return intercept.isLoadedProperty(prop.getPropertyIndex());
|
||||
} else {
|
||||
return intercept.isDirtyProperty(prop.getPropertyIndex());
|
||||
}
|
||||
}
|
||||
|
||||
public List<DerivedRelationshipData> getDerivedRelationships() {
|
||||
|
||||
@@ -110,12 +110,17 @@ public final class UpdateMeta {
|
||||
|
||||
private SpiUpdatePlan getDynamicUpdatePlan(ConcurrencyMode mode, PersistRequestBean<?> persistRequest) {
|
||||
|
||||
|
||||
// we can use a cached UpdatePlan for the changed properties
|
||||
|
||||
|
||||
EntityBeanIntercept ebi = persistRequest.getEntityBeanIntercept();
|
||||
int hash = ebi.getDirtyPropertyHash();
|
||||
|
||||
|
||||
int hash;
|
||||
if (persistRequest.getTransaction().isUpdateAllLoadedProperties()) {
|
||||
hash = ebi.getLoadedPropertyHash();
|
||||
} else {
|
||||
hash = ebi.getDirtyPropertyHash();
|
||||
}
|
||||
|
||||
BeanDescriptor<?> beanDescriptor = persistRequest.getBeanDescriptor();
|
||||
|
||||
BeanProperty versionProperty = beanDescriptor.getVersionProperty();
|
||||
|
||||
@@ -91,6 +91,8 @@ public class JdbcTransaction implements SpiTransaction {
|
||||
|
||||
protected boolean localReadOnly;
|
||||
|
||||
protected boolean updateAllLoadedProperties;
|
||||
|
||||
protected PersistBatch oldBatchMode;
|
||||
|
||||
protected PersistBatch batchMode;
|
||||
@@ -393,6 +395,15 @@ public class JdbcTransaction implements SpiTransaction {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUpdateAllLoadedProperties(boolean updateAllLoadedProperties) {
|
||||
this.updateAllLoadedProperties = updateAllLoadedProperties;
|
||||
}
|
||||
|
||||
public boolean isUpdateAllLoadedProperties() {
|
||||
return updateAllLoadedProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBatchMode(boolean batchMode) {
|
||||
if (!isActive()) {
|
||||
|
||||
Reference in New Issue
Block a user