#1730 - Fix for wrong JDBC batch sorting / ordering

This is a bit of a refactor that simplifies the ordering of
batch execution (BatchedBeanHolder ordering). In short we
batch by bean type and depth (rather than just type).

This means that there are some cases we are not optimal
(where we could batch by bean type in different depths)
but that is expected to be rare and problematic for
hierarchies of the same type.
This commit is contained in:
rob bygrave
2019-06-12 23:41:48 +12:00
parent 73ab2ee1fe
commit 7e768623e4
7 changed files with 126 additions and 136 deletions
@@ -0,0 +1,33 @@
package io.ebeaninternal.server.persist;
import java.util.HashMap;
import java.util.Map;
/**
* Helper to determine batch execution order for BatchedBeanHolders.
*/
class BatchDepthOrder {
private final Map<Integer, Counter> map = new HashMap<>();
/**
* Return the batch order for the given depth.
*/
int orderingFor(int depth) {
final Counter slot = map.computeIfAbsent(depth, integer -> new Counter());
return (depth * 100) + slot.increment();
}
void clear() {
map.clear();
}
private static class Counter {
int count;
public int increment() {
return count++;
}
}
}