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.
public BatchResult batch(List<ICommandData> commandDatas);
||An array of batch results matching exactly the order of commands send.
Product product1 = new Product();
PutCommandData put1 = new PutCommandData("products/999", null, RavenJObject.fromObject(product1), new RavenJObject());
Supplier supplier = new 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));
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.
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.