Example usage for org.eclipse.jgit.lib BatchRefUpdate setAtomic

List of usage examples for org.eclipse.jgit.lib BatchRefUpdate setAtomic

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib BatchRefUpdate setAtomic.

Prototype

public BatchRefUpdate setAtomic(boolean atomic) 

Source Link

Document

Request that all updates in this batch be performed atomically.

Usage

From source file:com.google.gerrit.server.project.DeleteRef.java

License:Apache License

private void deleteMultipleRefs(Repository r) throws OrmException, IOException, ResourceConflictException {
    BatchRefUpdate batchUpdate = r.getRefDatabase().newBatchUpdate();
    batchUpdate.setAtomic(false);
    List<String> refs = prefix == null ? refsToDelete
            : refsToDelete.stream().map(ref -> ref.startsWith(prefix) ? ref : prefix + ref).collect(toList());
    for (String ref : refs) {
        batchUpdate.addCommand(createDeleteCommand(resource, r, ref));
    }// w  ww  .  j  a va 2  s.c o  m
    try (RevWalk rw = new RevWalk(r)) {
        batchUpdate.execute(rw, NullProgressMonitor.INSTANCE);
    }
    StringBuilder errorMessages = new StringBuilder();
    for (ReceiveCommand command : batchUpdate.getCommands()) {
        if (command.getResult() == Result.OK) {
            postDeletion(resource, command);
        } else {
            appendAndLogErrorMessage(errorMessages, command);
        }
    }
    if (errorMessages.length() > 0) {
        throw new ResourceConflictException(errorMessages.toString());
    }
}