This is the WSO2 Data Services Server documentation version 2.6.3

Boxcarring Demo

By enabling the boxcarring option, a service will contain "begin_boxcar", "end_boxcar" and "abort_boxcar" control operations. Boxcarring is roughly analogous to transactions we see in database systems. The usage of boxcarring can be demonstrated by executing the following operations using the TryIt tool.

For this demonstration, we use an employee with employeeNumber=1002 which already exists in the system.

1. Run employeesByNumber operation with the employeeNumber 1002. Output is as follows:

2. Run the "begin_boxcar" operation and the service will switch to a boxcarring session.

3. Run the "incrementEmployeeSalary" operation and give the values "1000" for increment and "1002" for the employeeNumber fields.

4. Open up a different type of a browser for the service to have a fresh session, so it won't be in the same boxcarring session as earlier. After switching browsers, run the "employeesByNumber" operation with employeeNumber=1002 to check the employee information.

5. Note that the salary is not incremented. The reason is that the request made earlier in boxcarring mode is not executed immediately. It is executed when the boxcarring session ends.

6. Go back to the original browser, run the "incrementEmployeeSalary" operation and give the values "500" for increment and "1002" for the employeeNumber fields. Then, run the "end_boxcar" operation.

7. Next, in any of the two browsers, run the "employeesByNumber" operation with employeeNumber=1002 to check the information. The output will be similar to the following:

As we can see, both "incrementEmployeeSalary" operations are executed at once when the boxcarring session ends with "end_boxcar", resulting in the salary value to 3500. If there's any error in any of the operations inside a boxcarring session, none of the operations will be executed and the service calls will roll-back. A boxcarring session can also be explicitly canceled by calling the "abort_boxcar" operation.