Sho SHIMIZU
Committed by Gerrit Code Review

Change the return type of commit() to indicate the result

Change-Id: I4658a89fb0a496baa929579ab7800d00e842d685
...@@ -56,9 +56,9 @@ public interface TransactionContext { ...@@ -56,9 +56,9 @@ public interface TransactionContext {
56 * Commits a transaction that was previously started thereby making its changes permanent 56 * Commits a transaction that was previously started thereby making its changes permanent
57 * and externally visible. 57 * and externally visible.
58 * 58 *
59 - * @throws TransactionException if transaction fails to commit 59 + * @return true if this transaction succeeded, otherwise false.
60 */ 60 */
61 - void commit(); 61 + boolean commit();
62 62
63 /** 63 /**
64 * Aborts any changes made in this transaction context and discarding all locally cached updates. 64 * Aborts any changes made in this transaction context and discarding all locally cached updates.
......
...@@ -86,7 +86,7 @@ public class DefaultTransactionContext implements TransactionContext { ...@@ -86,7 +86,7 @@ public class DefaultTransactionContext implements TransactionContext {
86 86
87 @SuppressWarnings("unchecked") 87 @SuppressWarnings("unchecked")
88 @Override 88 @Override
89 - public void commit() { 89 + public boolean commit() {
90 // TODO: rework commit implementation to be more intuitive 90 // TODO: rework commit implementation to be more intuitive
91 checkState(isOpen, TX_NOT_OPEN_ERROR); 91 checkState(isOpen, TX_NOT_OPEN_ERROR);
92 CommitResponse response = null; 92 CommitResponse response = null;
...@@ -95,10 +95,11 @@ public class DefaultTransactionContext implements TransactionContext { ...@@ -95,10 +95,11 @@ public class DefaultTransactionContext implements TransactionContext {
95 txMaps.values().forEach(m -> updates.addAll(m.prepareDatabaseUpdates())); 95 txMaps.values().forEach(m -> updates.addAll(m.prepareDatabaseUpdates()));
96 Transaction transaction = new DefaultTransaction(transactionId, updates); 96 Transaction transaction = new DefaultTransaction(transactionId, updates);
97 response = Futures.getUnchecked(database.prepareAndCommit(transaction)); 97 response = Futures.getUnchecked(database.prepareAndCommit(transaction));
98 - } finally { 98 + return response.success();
99 - if (response != null && !response.success()) { 99 + } catch (Exception e) {
100 abort(); 100 abort();
101 - } 101 + return false;
102 + } finally {
102 isOpen = false; 103 isOpen = false;
103 } 104 }
104 } 105 }
......