mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#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:
@@ -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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user