本文整理匯總了Java中javax.transaction.Transaction.setRollbackOnly方法的典型用法代碼示例。如果您正苦於以下問題:Java Transaction.setRollbackOnly方法的具體用法?Java Transaction.setRollbackOnly怎麽用?Java Transaction.setRollbackOnly使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.transaction.Transaction
的用法示例。
在下文中一共展示了Transaction.setRollbackOnly方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleFault
import javax.transaction.Transaction; //導入方法依賴的package包/類
@Override
public void handleFault(Exchange exchange) {
// if no TM is available, there's nothing to do
if (_transactionManager == null) {
return;
}
try {
Property rollbackOnFaultProperty = exchange.getContext().getProperty(Exchange.ROLLBACK_ON_FAULT);
if (rollbackOnFaultProperty != null && rollbackOnFaultProperty.getValue() != null
&& Boolean.class.cast(rollbackOnFaultProperty.getValue())) {
Transaction transaction = getCurrentTransaction();
if (transaction != null) {
transaction.setRollbackOnly();
}
}
handleAfter(exchange);
} catch (Exception e) {
_log.error(e);
}
}
示例2: transactionRolledbackByHandler
import javax.transaction.Transaction; //導入方法依賴的package包/類
@Test
public void transactionRolledbackByHandler() throws Exception {
PolicyUtil.require(exchange, TransactionPolicy.PROPAGATES_TRANSACTION);
PolicyUtil.require(exchange, TransactionPolicy.MANAGED_TRANSACTION_GLOBAL);
exchange.setPhase(ExchangePhase.IN);
Assert.assertEquals(null, tm.getTransaction());
handler.handleMessage(exchange);
Transaction tx = tm.getTransaction();
Assert.assertEquals(Status.STATUS_ACTIVE, tx.getStatus());
Assert.assertTrue(PolicyUtil.isProvided(exchange, TransactionPolicy.PROPAGATES_TRANSACTION));
Assert.assertTrue(PolicyUtil.isProvided(exchange, TransactionPolicy.MANAGED_TRANSACTION_GLOBAL));
tx.setRollbackOnly();
exchange.setPhase(ExchangePhase.OUT);
handler.handleMessage(exchange);
Assert.assertEquals(Status.STATUS_ROLLEDBACK, tx.getStatus());
}
示例3: doTask
import javax.transaction.Transaction; //導入方法依賴的package包/類
@Override
public final void doTask(final String command) {
print("Received command => " + command);
Transaction t = null;
try {
t = getCurrentTransaction();
} catch (Exception e) {
print("Failed to get current transcation");
}
if (t == null) {
print("No active transaction");
return;
}
_storeA.store(command);
if (command.contains(ROLLBACK)) {
try {
if (++_rollbackCounter % 4 != 0) {
t.setRollbackOnly();
print("Marked transaction to rollback!");
} else {
print("Rollbacks completed - will be committed");
}
} catch (Exception ex) {
print("Failed to rollback transaction: " + ex.toString());
}
}
}
示例4: doTask
import javax.transaction.Transaction; //導入方法依賴的package包/類
@Override
public final void doTask(final String command) {
print("Received command => " + command);
Transaction t = null;
try {
t = getCurrentTransaction();
} catch (Exception e) {
print("Failed to get current transcation");
}
if (t == null) {
print("No active transaction");
return;
}
_storeB.store(command);
if (command.contains(ROLLBACK)) {
try {
if (++_rollbackCounter % 4 != 0) {
t.setRollbackOnly();
print("Marked transaction to rollback!");
} else {
print("Rollbacks completed - will be committed");
}
} catch (Exception ex) {
print("Failed to rollback transaction: " + ex.toString());
}
}
}
示例5: markTransactionAsRollbackOnly
import javax.transaction.Transaction; //導入方法依賴的package包/類
private void markTransactionAsRollbackOnly(Method method) throws Exception {
Transaction currentTx = _transactionManager.getTransaction();
if (_logger.isDebugEnabled()) {
_logger.debug(String.format("%s is marking the transaction as rollback only: currentTx=%s, startedTx=%s, suspendedTx=%s",
Thread.currentThread().getName(), currentTx, _startedTx, _suspendedTx));
}
if (_startedTx != null) {
if (currentTx != null && currentTx.equals(_startedTx)) {
currentTx.setRollbackOnly();
} else {
// Suspend any bad transaction - there is bug somewhere, but we will try to tidy things up
JCALogger.ROOT_LOGGER.currentTransactionIsNotSameAsThe(currentTx, _startedTx.toString());
Transaction origTx = _transactionManager.suspend();
try {
_transactionManager.resume(_startedTx);
_startedTx.setRollbackOnly();
} finally {
// Resume any suspended transaction
if (origTx != null) {
try {
_transactionManager.suspend();
_transactionManager.resume(origTx);
} catch (Throwable t) {
JCALogger.ROOT_LOGGER.messageEndpointFailedToResumeOldTransaction(_delegate.toString(), origTx.toString());
}
}
}
}
} else if (_messageEndpointFactory.isDeliveryTransacted(method)
&& currentTx != null && currentTx.getStatus() == Status.STATUS_ACTIVE) {
// Set rollback only flag on a source managed Tx
currentTx.setRollbackOnly();
}
}