in lagerta-core/src/main/java/com/epam/lagerta/base/jdbc/committer/JDBCCommitter.java [64:94]
private void executeBatches(Iterator<String> cachesIterator,
Iterator<List> keysIterator,
Iterator<List<?>> valuesIterator,
Connection conn) throws SQLException {
while (cachesIterator.hasNext() && keysIterator.hasNext() && valuesIterator.hasNext()) {
String currentCache = cachesIterator.next();
Iterator<?> currentKeys = keysIterator.next().iterator();
Iterator<?> currentValues = valuesIterator.next().iterator();
EntityDescriptor entityDescriptor = entityDescriptors.get(currentCache);
if (entityDescriptor == null) {
throw new RuntimeException("Not found cacheDescriptor for cache: " + currentCache);
}
try (PreparedStatement statement = conn.prepareStatement(entityDescriptor.getUpsertQuery())) {
int elementsInBatch = 0;
while (currentKeys.hasNext() && currentValues.hasNext()) {
Object currentKey = currentKeys.next();
Object currentValue = currentValues.next();
entityDescriptor.addValuesToBatch(currentKey, currentValue, statement);
if (++elementsInBatch >= BATCH_SIZE) {
statement.executeBatch();
elementsInBatch = 0;
}
}
if (elementsInBatch != 0) {
statement.executeBatch();
}
}
}
}