entity,
select) : select;
sourceNode.performQueries(Collections.singletonList(query), observer);
ResultIterator result = observer.getResultIterator();
InsertBatchQuery insert = new InsertBatchQuery(entity, INSERT_BATCH_SIZE);
try {
// Split insertions into the same table into batches.
// This will allow to process tables of arbitrary size
// and not run out of memory.
int currentRow = 0;
// even if we don't use intermediate batch commits, we still need to
// estimate batch insert size
int batchSize = insertBatchSize > 0 ? insertBatchSize : INSERT_BATCH_SIZE;
while (result.hasNextRow()) {
if (insertBatchSize > 0
&& currentRow > 0
&& currentRow % insertBatchSize == 0) {
// end of the batch detected... commit and start a new insert
// query
destinationNode.performQueries(
Collections.singletonList((Query) insert),
insertObserver);
insert = new InsertBatchQuery(entity, batchSize);
insertObserver.clear();
}
currentRow++;
Map<String, Object> nextRow = (DataRow) result.nextRow();
insert.add(nextRow);
}
// commit remaining batch if needed
if (insert.size() > 0) {
destinationNode.performQueries(
Collections.singletonList((Query) insert),
insertObserver);
}