| [Documentation Home] | [Release Note]
Batch Processing Sample
Batch processing is used when a specific in-only operation must be ran sequencially with different parameter sets. Here we will be demonstrating a data service where batch processing is enabled, and the necessory batch operations are automatically created.
The sample data service "BatchRequestSample" should be deployed as per the instructions mentioned in Deploying Samples section.
Running the Sample
The sample service can be run using the "tryit" tool, which is bundled with WSO2 Data Services Server, or a code-generated java client sample using this service is demonstrated in the Data Services Clients Sample section.
The command line application is used here to present the functionality of batch processing. As shown in Data Services Clients Sample, run the command "ant batch_request", to run the sample. The output will resemble the following.
Figure 1: Batch process operation invocation.
The sample tests batch processing by executing a batch operation with three parameter tests, which means, it's effectively executing three consecutive operations. The operation is to add a new employee to the database. Here we will be executing the batch operation and check for the existance of the three newly added entries. A requirement of batch operations are, if one invocation fails, then all the other operations in the batch should fail. This can be seen here, where the sets of three employee entries are either inserted together, or neither of them haven been inserted. In this sample, a validator is used for checking if a valid email address is given when adding a new employee entry to the database, if the email is invalid, that operation invocation would fail.
There are such four batch requests done here, the summary of them are explained below.
- All the parameters have been added properly, and all operations executed successfully, thus when checking for the existance of entries with ids "180000", "180001", "180002", all returns true.
- Here the requests with ids "180003" is executed successfully, but when it reaches "180004", a validation error occurs since the email address is invalid, and all the service invocation in that batch request is rolled back. So in the next section when checking for the existance of the employee ids belonging to this batch request, no one would have been added to the database, this is as predicted because all the operations in a batch operation is executed in a single transaction.
- In this instance, the 3'rd operation in the batch request is not given an email address, and this causes a validation error, thus the transaction is rolled back and all the ids "180006", "180007" and "180008" are not executed.
- The requests here are all given valid parameters, same as in the 1'st request, so all the records "180009", "180010" and "180011" are added successfully.
So with the above demonstration, we have showed how the batch operations behave in a transactional manner.