Terracotta 10.3 | TCStore API Developer Guide | Transactions Extension | Transaction Execution
 
Transaction Execution
The simplest way to execute a transaction is using one of the TransactionController.execute methods. The parameters to these methods define the transaction workload and the resources that take part in the transaction.
Long numberOfEmployees =
transactionController.execute(employeeReader, // 1
reader -> reader.records().count()); // 2

Long numberOfEmployeesAndCustomers =
transactionController.execute(employeeReader, customerReader, // 3
(empReader, custReader) ->
empReader.records().count() + custReader.records().count()); // 4

transactionController.execute(employeeWriterReader, // 5
(TransactionalTask<DatasetWriterReader<Integer>>) writerReader ->
writerReader.on(1).delete()); // 6
1
TransactionController.execute here takes a DatasetReader as the resource that takes part in the transaction.
2
The TransactionalAction instance is conveniently expressed here as a lambda expression. The action is executed atomically with respect to the enrolled resources and its return value is then returned from TransactionController.execute(…​).
3
Here two DatasetReader instances are passed in as resources.
4
The TransactionalBiAction defines a transaction over the two passed in resources. And the result is returned by the TransactionController.execute(…​).
5
Additional overloads of TransactionController.execute(…​) take DatasetWriterReader instances as resources.
6
A TransactionalTask has no return value and is therefore only available for execution against writer-reader resources.
There are overloads of TransactionController.execute(…​) defined to handle all one and two dataset transactions. More complicated transactions require a transaction context to be built.

Copyright © 2010-2019 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.