@Override public void startTx(Transaction tx) { for (TransactionAware txAware : this) { txAware.startTx(tx); } }
@Override public void startTx(Transaction tx) { for (TransactionAware txAware : this) { txAware.startTx(tx); } }
/** * Adds a new transaction-aware to participate in the transaction. * @param txAware the new transaction-aware */ public boolean addTransactionAware(TransactionAware txAware) { // If the txAware is newly added, call startTx as well if there is an active transaction boolean added = txAwares.add(txAware); if (added && currentTx != null) { txAware.startTx(currentTx); } return added; }
/** * Adds a new transaction-aware to participate in the transaction. * @param txAware the new transaction-aware */ public boolean addTransactionAware(TransactionAware txAware) { // If the txAware is newly added, call startTx as well if there is an active transaction boolean added = txAwares.add(txAware); if (added && currentTx != null) { txAware.startTx(currentTx); } return added; }
/** * Starts a new transaction. Calling this will initiate a new transaction using the {@link TransactionSystemClient}, * and pass the returned 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 */ public void start() throws TransactionFailureException { currentTx = txClient.startShort(); for (TransactionAware txAware : txAwares) { try { txAware.startTx(currentTx); } catch (Throwable e) { String message = String.format("Unable to start transaction-aware '%s' for transaction %d. ", txAware.getTransactionAwareName(), currentTx.getTransactionId()); LOG.warn(message, e); txClient.abort(currentTx); throw new TransactionFailureException(message, e); } } }
/** * Starts a new transaction. Calling this will initiate a new transaction using the {@link TransactionSystemClient}, * and pass the returned 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 */ public void start() throws TransactionFailureException { currentTx = txClient.startShort(); for (TransactionAware txAware : txAwares) { try { txAware.startTx(currentTx); } catch (Throwable e) { String message = String.format("Unable to start transaction-aware '%s' for transaction %d. ", txAware.getTransactionAwareName(), currentTx.getTransactionId()); LOG.warn(message, e); txClient.abort(currentTx); throw new TransactionFailureException(message, e); } } }