use of org.datanucleus.flush.FlushNonReferential in project datanucleus-rdbms by datanucleus.
the class FlushReferential method execute.
/* (non-Javadoc)
* @see org.datanucleus.FlushOrdered#execute(org.datanucleus.ExecutionContext, java.util.List, java.util.List, org.datanucleus.flush.OperationQueue)
*/
@Override
public List<NucleusOptimisticException> execute(ExecutionContext ec, List<ObjectProvider> primaryOPs, List<ObjectProvider> secondaryOPs, OperationQueue opQueue) {
List<NucleusOptimisticException> flushExcps = null;
// Phase 1 : Find all objects that have no relations or external FKs and process first
Set<ObjectProvider> unrelatedOPs = null;
if (primaryOPs != null) {
Iterator<ObjectProvider> opIter = primaryOPs.iterator();
while (opIter.hasNext()) {
ObjectProvider op = opIter.next();
if (!op.isEmbedded() && isClassSuitableForBatching(ec, op.getClassMetaData())) {
if (unrelatedOPs == null) {
unrelatedOPs = new HashSet<>();
}
unrelatedOPs.add(op);
opIter.remove();
}
}
}
if (secondaryOPs != null) {
Iterator<ObjectProvider> opIter = secondaryOPs.iterator();
while (opIter.hasNext()) {
ObjectProvider op = opIter.next();
if (!op.isEmbedded() && isClassSuitableForBatching(ec, op.getClassMetaData())) {
if (unrelatedOPs == null) {
unrelatedOPs = new HashSet<>();
}
unrelatedOPs.add(op);
opIter.remove();
}
}
}
if (unrelatedOPs != null) {
// Process DELETEs, then INSERTs, then UPDATEs
FlushNonReferential groupedFlush = new FlushNonReferential();
flushExcps = groupedFlush.flushDeleteInsertUpdateGrouped(unrelatedOPs, ec);
}
// Phase 2 : Fallback to FlushOrdered handling for remaining objects
List<NucleusOptimisticException> excps = super.execute(ec, primaryOPs, secondaryOPs, opQueue);
// Return any exceptions
if (excps != null) {
if (flushExcps == null) {
flushExcps = excps;
} else {
flushExcps.addAll(excps);
}
}
return flushExcps;
}
Aggregations