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 {
* Commits a transaction that was previously started thereby making its changes permanent
* and externally visible.
*
* @throws TransactionException if transaction fails to commit
* @return true if this transaction succeeded, otherwise false.
*/
void commit();
boolean commit();
/**
* Aborts any changes made in this transaction context and discarding all locally cached updates.
......
......@@ -86,7 +86,7 @@ public class DefaultTransactionContext implements TransactionContext {
@SuppressWarnings("unchecked")
@Override
public void commit() {
public boolean commit() {
// TODO: rework commit implementation to be more intuitive
checkState(isOpen, TX_NOT_OPEN_ERROR);
CommitResponse response = null;
......@@ -95,10 +95,11 @@ public class DefaultTransactionContext implements TransactionContext {
txMaps.values().forEach(m -> updates.addAll(m.prepareDatabaseUpdates()));
Transaction transaction = new DefaultTransaction(transactionId, updates);
response = Futures.getUnchecked(database.prepareAndCommit(transaction));
return response.success();
} catch (Exception e) {
abort();
return false;
} finally {
if (response != null && !response.success()) {
abort();
}
isOpen = false;
}
}
......