Skip to content

Commit

Permalink
Batch is now automatically deleted after committed.
Browse files Browse the repository at this point in the history
  • Loading branch information
essiembre committed Dec 11, 2013
1 parent e96bbc1 commit 6328bd6
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
* operations are cached in memory until the commit batch size is reached, then
* the operations cached so far are sent.
* <p/>
* After being committed, the documents are automatically removed from the
* queue.
* <p/>
* If you need to map original document fields with target repository fields,
* consider using {@link AbstractMappedCommitter}.
*
Expand Down Expand Up @@ -99,7 +102,7 @@ protected void commitComplete() {
batch = getBatchToCommit();
}
if (batch != null) {
commitBatch(batch);
commitAndCleanBatch(batch);
}
}
}
Expand All @@ -109,6 +112,19 @@ protected void commitComplete() {
* @param batch the group of operations
*/
protected abstract void commitBatch(List<ICommitOperation> batch);

/**
* Commits documents and delete them from queue when done.
* @param batch the bath of operations to commit.
*/
private void commitAndCleanBatch(List<ICommitOperation> batch) {
commitBatch(batch);
// Delete queued documents after commit
for (ICommitOperation op : batch) {
op.delete();
}
batch.clear();
}

private void cacheOperationAndCommitIfReady(ICommitOperation operation) {
operations.add(operation);
Expand All @@ -119,7 +135,7 @@ private void cacheOperationAndCommitIfReady(ICommitOperation operation) {
}
}
if (batch != null) {
commitBatch(batch);
commitAndCleanBatch(batch);
}
}

Expand Down

0 comments on commit 6328bd6

Please sign in to comment.