@Override public void abort() throws SQLException { if (txContext == null || !isTransactionRunning()) { return; } try { txContext.abort(); } catch (TransactionFailureException e) { throw new SQLExceptionInfo.Builder( SQLExceptionCode.TRANSACTION_FAILED) .setMessage(e.getMessage()).setRootCause(e).build() .buildException(); } }
@Override public void commit() throws SQLException { if (txContext == null || !isTransactionRunning()) { return; } try { txContext.finish(); } catch (TransactionFailureException e) { if (e instanceof TransactionConflictException) { throw new SQLExceptionInfo.Builder( SQLExceptionCode.TRANSACTION_CONFLICT_EXCEPTION) .setMessage(e.getMessage()).setRootCause(e).build() .buildException(); } throw new SQLExceptionInfo.Builder( SQLExceptionCode.TRANSACTION_FAILED) .setMessage(e.getMessage()).setRootCause(e).build() .buildException(); } }
@Override public void begin() throws SQLException { if (txContext == null) { throw new SQLExceptionInfo.Builder( SQLExceptionCode.NULL_TRANSACTION_CONTEXT).build() .buildException(); } try { txContext.start(); } catch (TransactionFailureException e) { throw new SQLExceptionInfo.Builder( SQLExceptionCode.TRANSACTION_FAILED) .setMessage(e.getMessage()).setRootCause(e).build() .buildException(); } }
private void postCommit() throws TransactionFailureException { TransactionFailureException cause = null; for (TransactionAware txAware : txAwares) { try { txAware.postTxCommit(); } catch (Throwable t) { TransactionFailureException tfe = createTransactionFailure("perform post-commit for", txAware, t); LOG.warn(tfe.getMessage()); if (cause == null) { cause = tfe; } else { cause.addSuppressed(tfe); } } } if (cause != null) { throw cause; } }
private void persist() throws TransactionFailureException { for (TransactionAware txAware : txAwares) { boolean success = false; Throwable cause = null; try { success = txAware.commitTx(); } catch (Throwable e) { cause = e; } if (!success) { TransactionFailureException tfe = createTransactionFailure("persist changes of", txAware, cause); LOG.warn(tfe.getMessage()); // abort will throw that exception abort(tfe); } } }
/** * This is a helper for {@link #start()} and {@link #start(int)}. * * Passes the current transaction to {@link TransactionAware#startTx(Transaction)} for each registered * TransactionAware. If an exception is encountered, the transaction will be aborted and a * {@code TransactionFailureException} wrapping the root cause will be thrown. * * @throws TransactionFailureException if an exception occurs starting the transaction with any registered * TransactionAware */ private void startAllTxAwares() throws TransactionFailureException { for (TransactionAware txAware : txAwares) { try { txAware.startTx(currentTx); } catch (Throwable t) { try { txClient.abort(currentTx); TransactionFailureException tfe = createTransactionFailure("start", txAware, t); LOG.warn(tfe.getMessage()); throw tfe; } finally { currentTx = null; } } } }
private void checkForConflicts() throws TransactionFailureException { Collection<byte[]> changes = Lists.newArrayList(); for (TransactionAware txAware : txAwares) { try { changes.addAll(txAware.getTxChanges()); } catch (Throwable t) { TransactionFailureException tfe = createTransactionFailure("retrieve changes from", txAware, t); LOG.warn(tfe.getMessage()); // abort will throw that exception abort(tfe); } } try { txClient.canCommitOrThrow(currentTx, changes); } catch (TransactionFailureException e) { abort(e); // abort will rethrow this exception } catch (Throwable e) { String message = String.format("Exception from canCommit for transaction %d.", currentTx.getTransactionId()); abort(new TransactionFailureException(message, e)); // abort will throw that exception } }
"Make sure that no other programs are using this dataset at the same time."); } catch (TransactionFailureException e) { throw new DataSetException("Transaction failure: " + e.getMessage(), e.getCause()); } catch (RuntimeException e) {
"Make sure that no other programs are using this dataset at the same time."); } catch (TransactionFailureException e) { throw new DataSetException("Transaction failure: " + e.getMessage(), e.getCause()); } catch (RuntimeException e) {
@Override public void abort() throws SQLException { if (txContext == null || !isTransactionRunning()) { return; } try { txContext.abort(); } catch (TransactionFailureException e) { throw new SQLExceptionInfo.Builder( SQLExceptionCode.TRANSACTION_FAILED) .setMessage(e.getMessage()).setRootCause(e).build() .buildException(); } }
@Override public void abort() throws SQLException { if (txContext == null || !isTransactionRunning()) { return; } try { txContext.abort(); } catch (TransactionFailureException e) { throw new SQLExceptionInfo.Builder( SQLExceptionCode.TRANSACTION_FAILED) .setMessage(e.getMessage()).setRootCause(e).build() .buildException(); } }
@Override public void commit() throws SQLException { if (txContext == null || !isTransactionRunning()) { return; } try { txContext.finish(); } catch (TransactionFailureException e) { if (e instanceof TransactionConflictException) { throw new SQLExceptionInfo.Builder( SQLExceptionCode.TRANSACTION_CONFLICT_EXCEPTION) .setMessage(e.getMessage()).setRootCause(e).build() .buildException(); } throw new SQLExceptionInfo.Builder( SQLExceptionCode.TRANSACTION_FAILED) .setMessage(e.getMessage()).setRootCause(e).build() .buildException(); } }
@Override public void commit() throws SQLException { if (txContext == null || !isTransactionRunning()) { return; } try { txContext.finish(); } catch (TransactionFailureException e) { if (e instanceof TransactionConflictException) { throw new SQLExceptionInfo.Builder( SQLExceptionCode.TRANSACTION_CONFLICT_EXCEPTION) .setMessage(e.getMessage()).setRootCause(e).build() .buildException(); } throw new SQLExceptionInfo.Builder( SQLExceptionCode.TRANSACTION_FAILED) .setMessage(e.getMessage()).setRootCause(e).build() .buildException(); } }
} catch (Throwable t) { TransactionFailureException tfe = createTransactionFailure("roll back changes in", txAware, t); LOG.warn(tfe.getMessage()); if (cause == null) { cause = tfe;
@Override public void begin() throws SQLException { if (txContext == null) { throw new SQLExceptionInfo.Builder( SQLExceptionCode.NULL_TRANSACTION_CONTEXT).build() .buildException(); } try { txContext.start(); } catch (TransactionFailureException e) { throw new SQLExceptionInfo.Builder( SQLExceptionCode.TRANSACTION_FAILED) .setMessage(e.getMessage()).setRootCause(e).build() .buildException(); } }
@Override public void begin() throws SQLException { if (txContext == null) { throw new SQLExceptionInfo.Builder( SQLExceptionCode.NULL_TRANSACTION_CONTEXT).build() .buildException(); } try { txContext.start(); } catch (TransactionFailureException e) { throw new SQLExceptionInfo.Builder( SQLExceptionCode.TRANSACTION_FAILED) .setMessage(e.getMessage()).setRootCause(e).build() .buildException(); } }