see on GitHub

Batches: How to send multiple commands using a batch?

To send multiple operations in a single request, reducing the number of remote calls and allowing several operations to share same transaction, Batch should be used.

Syntax

public BatchResult[] batch(List<ICommandData> commandDatas);

Parameters
An array of following commands:
- PutCommandData
- DeleteCommandData
- PatchCommandData
- ScriptedPatchCommandData
ICommandData Commands to process.
Return Value
BatchResult[] An array of batch results matching exactly the order of commands send.

Example

Product product1 = new Product();
product1.setName("My Product");
product1.setSupplier("suppliers/999");
PutCommandData put1 = new PutCommandData("products/999", null, RavenJObject.fromObject(product1), new RavenJObject());

Supplier supplier = new Supplier();
supplier.setName("My Supplier");
PutCommandData put2 = new PutCommandData("suppliers/999", null, RavenJObject.fromObject(supplier), new RavenJObject());

DeleteCommandData delete = new DeleteCommandData("products/2", null);

BatchResult[] results = store.getDatabaseCommands().batch(Arrays.<ICommandData> asList(put1, put2, delete));

Concurrency

If an ETag is specified in the command, that ETag is compared to the current ETag on the document on the server. If the ETag does not match, a 409 Conflict status code will be returned from the server, causing a ConcurrencyException to be thrown. In such a case, the entire operation fails and non of the updates that were attempted will succeed.

Transactions

All the operations in the batch will succeed or fail as a transaction. Other users will not be able to see any of the changes until the entire batch completes.