[jbossts-issues] [JBoss JIRA] (JBTM-2458) Think of the possibility to improve Compensations API with lambdas
Gytis Trikleris (JIRA)
issues at jboss.org
Mon Jul 13 05:38:03 EDT 2015
[ https://issues.jboss.org/browse/JBTM-2458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13088755#comment-13088755 ]
Gytis Trikleris commented on JBTM-2458:
---------------------------------------
My first example:
{code}
public class BankingService {
@Inject
private AccountManager accountManager;
@Compensatable
public void transferMoney(String fromAccount, String toAccount, Double amount) {
accountManager.debitAccount(fromAccount, amount);
accountManager.creditAccount(toAccount, amount);
}
}
@Compensatable
public class AccountManager {
private static final String DATABASE_NAME = "accounts-database";
private static final String COLLECTION_NAME = "accounts-collection";
@Inject(db = DATABASE_NAME, collection = COLLECTION_NAME)
private MongoCollection collection;
public void creditAccount(String account, Double amount) {
Document filter = new Document("name", account);
Document update = new Document("$inc", amount);
Document undo = new Document("$inc", -1 * amount);
updateCollection(filter, update, undo);
}
public void debitAccount(String account, Double amount) {
Document filter = new Document("name", account);
Document update = new Document("$inc", -1 * amount);
Document undo = new Document("$inc", amount);
updateCollection(filter, update, undo);
}
private void updateCollection(Document filter, Document update, Document undo) {
CompensationHandler compensationHandler = () -> collection.updateOne(filter, undo);
ConfirmationHandler confirmationHandler = () -> System.out.println(filter + " was updated");
// v1
collection.onFailure(compensationHandler).onSuccess(confirmationHandler).updateOne(filter, update);
// v2
// collection.updateOne(filter, update, compensationHandler, confirmationHandler);
}
}
{code}
> Think of the possibility to improve Compensations API with lambdas
> ------------------------------------------------------------------
>
> Key: JBTM-2458
> URL: https://issues.jboss.org/browse/JBTM-2458
> Project: JBoss Transaction Manager
> Issue Type: Task
> Components: TXFramework
> Reporter: Gytis Trikleris
> Assignee: Gytis Trikleris
> Fix For: 5.next
>
>
> Emmanuel suggested to reduce verbosity in Compensations API by making it possible to use lambdas for handler implementation.
> We should try to think of the best API changes to introduce that.
> We could rewrite MongoDB quickstart to make it easier to visualise the difference.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
More information about the jbossts-issues
mailing list