@Override public boolean cancel() { return delegate.cancel(); }
@CheckReturnValue @SuppressWarnings("checkstyle:IllegalCatch") protected <D extends Datastore, X extends WriteTransaction, W, R, E extends Exception> FluentFuture<R> applyWithNewTransactionAndSubmit( final Class<D> datastoreType, final Supplier<X> txSupplier, final BiFunction<Class<D>, X, W> txWrapper, final InterruptibleCheckedFunction<W, R, E> txFunction, final BiFunction<X, W, FluentFuture<?>> txSubmitter) { X realTx = txSupplier.get(); W wrappedTx = txWrapper.apply(datastoreType, realTx); R result; try { // We must store the result before submitting the transaction; if we inline the next line in the // transform lambda, that's not guaranteed result = txFunction.apply(wrappedTx); } catch (Exception e) { // catch Exception for both the <E extends Exception> thrown by accept() as well as any RuntimeException if (!realTx.cancel()) { LOG.error("Transaction.cancel() returned false - this should never happen (here)"); } return FluentFutures.immediateFailedFluentFuture(e); } return txSubmitter.apply(realTx, wrappedTx).transform(v -> result, MoreExecutors.directExecutor()); }
@CheckReturnValue private FluentFuture<? extends CommitInfo> commit(final WriteTransaction realTx, final WriteTrackingTransaction wrappedTx) { if (wrappedTx.isWritten()) { // The transaction contains changes, commit it return realTx.commit(); } // The transaction only handled reads, cancel it realTx.cancel(); return CommitInfo.emptyFluentFuture(); } }