#357 - batch insertAll has no effect when tx commited

This commit is contained in:
Robin Bygrave
2015-07-30 04:23:02 +12:00
parent 19f40cb2e5
commit a5e94f6ae2
3 changed files with 72 additions and 3 deletions
@@ -24,6 +24,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* Property mapped to a List Set or Map.
@@ -180,9 +181,27 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
help.add(bc, detailBean);
}
public boolean isEmptyBeanCollection(EntityBean bean) {
/**
* Return true if this is considered 'empty' from a save perspective.
*/
public boolean isEmptyBeanCollection(EntityBean bean, boolean insertedParent) {
Object val = getValue(bean);
return val == null || (val instanceof BeanCollection<?>) && ((BeanCollection<?>) val).isEmptyAndUntouched();
if (val == null) {
return true;
}
if ((val instanceof BeanCollection<?>)) {
return ((BeanCollection<?>) val).isEmptyAndUntouched();
}
if (insertedParent) {
// check 'vanilla' collection types
if (val instanceof Collection<?>){
return ((Collection<?>) val).isEmpty();
}
if (val instanceof Map<?,?>) {
return ((Map<?,?>) val).isEmpty();
}
}
return false;
}
/**
@@ -573,7 +573,7 @@ public final class DefaultPersister implements Persister {
BeanPropertyAssocMany<?>[] manys = desc.propertiesManySave();
for (int i = 0; i < manys.length; i++) {
// check that property is loaded and not empty uninitialised collection
if (request.isLoadedProperty(manys[i]) && !manys[i].isEmptyBeanCollection(parentBean)) {
if (request.isLoadedProperty(manys[i]) && !manys[i].isEmptyBeanCollection(parentBean, insertedParent)) {
saveMany(new SaveManyPropRequest(insertedParent, manys[i], parentBean, request), insertMode);
if (!insertedParent) {
request.addUpdatedManyProperty(manys[i]);