Java Code Examples for org.springframework.transaction.TransactionStatus#isRollbackOnly()
The following examples show how to use
org.springframework.transaction.TransactionStatus#isRollbackOnly() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransactionHandlerInterceptor.java From rice with Educational Community License v2.0 | 6 votes |
/** * Completes the request transaction if needed. * * @param ex any exception that might have been thrown, will cause a rollback */ protected void completeTransaction(Exception ex) { TransactionStatus status = context.get(); if (status == null) { return; } try { if (!status.isCompleted()) { if (ex == null && !status.isRollbackOnly()) { txManager.commit(status); } else { txManager.rollback(status); } } } finally { context.remove(); } }
Example 2
Source File: SpringAwareUserTransaction.java From alfresco-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * This status is a combination of the internal status, as recorded during explicit operations, * and the status provided by the Spring support. * * @see Status */ public synchronized int getStatus() throws SystemException { TransactionInfo txnInfo = getTransactionInfo(); // if the txn info is null, then we are outside a transaction if (txnInfo == null) { return internalStatus; // this is checked in getTransactionInfo } // normally the internal status is correct, but we only need to double check // for the case where the transaction was marked for rollback, or rolledback // in a deeper transaction TransactionStatus txnStatus = txnInfo.getTransactionStatus(); if (internalStatus == Status.STATUS_ROLLEDBACK) { // explicitly rolled back at some point return internalStatus; } else if (txnStatus.isRollbackOnly()) { // marked for rollback at some point in the stack return Status.STATUS_MARKED_ROLLBACK; } else { // just rely on the internal status return internalStatus; } }
Example 3
Source File: HibernateJtaTransactionManagerAdapter.java From gorm-hibernate5 with Apache License 2.0 | 5 votes |
protected static int convertToJtaStatus(TransactionStatus status) { if (status != null) { if (status.isCompleted()) { return Status.STATUS_UNKNOWN; } else if (status.isRollbackOnly()) { return Status.STATUS_MARKED_ROLLBACK; } else { return Status.STATUS_ACTIVE; } } else { return Status.STATUS_NO_TRANSACTION; } }
Example 4
Source File: TransactionalInterceptor.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { if (null != transactionManager) { TransactionStatus tx = (TransactionStatus) TransactionSynchronizationManager.unbindResource(TX_KEY); if (tx.isRollbackOnly()) { transactionManager.rollback(tx); } else { transactionManager.commit(tx); } } super.afterCompletion(request, response, handler, ex); }
Example 5
Source File: JtaUtil.java From iaf with Apache License 2.0 | 4 votes |
public static String displayTransactionStatus(TransactionStatus txStatus) { String result; result="txName ["+TransactionSynchronizationManager.getCurrentTransactionName()+"]"; if (txStatus!=null) { result+=" status new ["+txStatus.isNewTransaction()+"]"; result+=" status completeted ["+txStatus.isCompleted()+"]"; result+=" status rollbackOnly ["+txStatus.isRollbackOnly()+"]"; result+=" status hasSavepoint ["+txStatus.hasSavepoint()+"]"; } else { result+=" currently not in a transaction"; } result+=" isolation ["+TransactionSynchronizationManager.getCurrentTransactionIsolationLevel()+"]"; result+=" active ["+TransactionSynchronizationManager.isActualTransactionActive()+"]"; boolean syncActive=TransactionSynchronizationManager.isSynchronizationActive(); result+=" synchronization active ["+syncActive+"]"; result+="\n"; Map<Object, Object> resources = TransactionSynchronizationManager.getResourceMap(); result += "resources:\n"; if (resources==null) { result+=" map is null\n"; } else { for (Iterator<Object> it=resources.keySet().iterator(); it.hasNext();) { Object key = it.next(); Object resource = resources.get(key); result += ClassUtils.nameOf(key)+"("+key+"): "+ClassUtils.nameOf(resource)+"("+resource+")\n"; if (resource instanceof JmsResourceHolder) { JmsResourceHolder jrh = (JmsResourceHolder)resource; result+=" connection: "+jrh.getConnection()+", session: "+jrh.getSession()+"\n"; } } } if (syncActive) { List<TransactionSynchronization> synchronizations = TransactionSynchronizationManager.getSynchronizations(); result += "synchronizations:\n"; for (int i=0; i<synchronizations.size(); i++) { TransactionSynchronization synchronization = synchronizations.get(i); result += ClassUtils.nameOf(synchronization)+"("+synchronization+")\n"; } } return result; }