Java Code Examples for javax.transaction.Status#STATUS_NO_TRANSACTION
The following examples show how to use
javax.transaction.Status#STATUS_NO_TRANSACTION .
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: TxUtils.java From ironjacamar with Eclipse Public License 1.0 | 6 votes |
/** * Is the transaction completed * @param tx The transaction * @return True if completed; otherwise false */ public static boolean isCompleted(Transaction tx) { if (tx == null) return true; try { int status = tx.getStatus(); return status == Status.STATUS_COMMITTED || status == Status.STATUS_ROLLEDBACK || status == Status.STATUS_NO_TRANSACTION; } catch (SystemException error) { throw new RuntimeException("Error during isCompleted()", error); } }
Example 2
Source File: NodeListener.java From JPPF with Apache License 2.0 | 6 votes |
/** * Terminate the transaction and return an exception if any occurred. * @return Exception if any error occurred. */ @Override public Exception call() { try { final UserTransactionImp utx = new UserTransactionImp(); if (utx.getStatus() == Status.STATUS_NO_TRANSACTION) output("WARNING: endTransaction() called outside a tx"); else { output("INFO: transaction " + (rollback ? "rollback" : "commit")); if (rollback) utx.rollback(); else utx.commit(); } return null; } catch (final Exception e) { return e; } }
Example 3
Source File: BasicTransactionAssistanceFactoryImpl.java From genericconnector with Apache License 2.0 | 6 votes |
/** before calling this method, please ensure you have called {@link TransactionConfigurator#setup(String, CommitRollbackCallback)} */ @Override public TransactionAssistant getTransactionAssistant() throws ResourceException { //enlist a new resource into the transaction. it will be delisted, when its closed. final CommitRollbackCallback commitRollbackCallback = TransactionConfigurator.getCommitRollbackCallback(jndiName); MicroserviceXAResource ms = new MicroserviceXAResource(jndiName, commitRollbackCallback); UserTransactionManager utm = getTM(); try { if(utm.getStatus() == Status.STATUS_NO_TRANSACTION){ throw new ResourceException("no transaction found. please start one before getting the transaction assistant. status was: " + utm.getStatus()); } Transaction tx = utm.getTransaction(); tx.enlistResource(ms); return new AtomikosTransactionAssistantImpl(ms); } catch (Exception e) { throw new ResourceException("Unable to get transaction status", e); } }
Example 4
Source File: TimerData.java From tomee with Apache License 2.0 | 6 votes |
private void registerTimerDataSynchronization() throws TimerStoreException { if (synchronizationRegistered) { return; } try { final Transaction transaction = timerService.getTransactionManager().getTransaction(); final int status = transaction == null ? Status.STATUS_NO_TRANSACTION : transaction.getStatus(); if (transaction != null && status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK) { transaction.registerSynchronization(new TimerDataSynchronization()); synchronizationRegistered = true; return; } } catch (final Exception e) { log.warning("Unable to register timer data transaction synchronization", e); } // there either wasn't a transaction or registration failed... call transactionComplete directly transactionComplete(true); }
Example 5
Source File: TransactionSynchronizationRegistryImpl.java From lams with GNU General Public License v2.0 | 6 votes |
/** * {@inheritDoc} */ public int getTransactionStatus() { TransactionImpl tx = registry.getTransaction(); if (tx == null) return Status.STATUS_NO_TRANSACTION; try { return tx.getStatus(); } catch (Throwable t) { return Status.STATUS_UNKNOWN; } }
Example 6
Source File: JtaRetryInterceptor.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected boolean calledInsideTransaction() { try { return transactionManager.getStatus() != Status.STATUS_NO_TRANSACTION; } catch (SystemException e) { throw new ActivitiException("Could not determine the current status of the transaction manager: " + e.getMessage(), e); } }
Example 7
Source File: JtaTransactionInterceptor.java From snakerflow with Apache License 2.0 | 5 votes |
protected TransactionStatus getTransaction() { UserTransaction userTransaction = JtaTransactionHelper .lookupJeeUserTransaction(); int status = JtaTransactionHelper .getUserTransactionStatus(userTransaction); if(log.isInfoEnabled()) { log.info("begin transaction=" + status); } if (status == Status.STATUS_ACTIVE) { return new TransactionStatus(null, false); } if ((status != Status.STATUS_NO_TRANSACTION) && (status != Status.STATUS_COMMITTED) && (status != Status.STATUS_ROLLEDBACK)) { throw new SnakerException("无效的事务状态:" + status); } Transaction suspendedTransaction = null; if ((status == Status.STATUS_ACTIVE) || (status == Status.STATUS_COMMITTED) || (status == Status.STATUS_ROLLEDBACK)) { suspendedTransaction = JtaTransactionHelper.suspend(); } try { JtaTransactionHelper.begin(); return new TransactionStatus(null, true); } catch (RuntimeException e) { throw e; } finally { if (suspendedTransaction != null) { JtaTransactionHelper.resume(suspendedTransaction); } } }
Example 8
Source File: JtaTransactionInterceptor.java From snakerflow with Apache License 2.0 | 5 votes |
protected void rollback(TransactionStatus status) { UserTransaction userTransaction = JtaTransactionHelper .lookupJeeUserTransaction(); int txStatus = JtaTransactionHelper .getUserTransactionStatus(userTransaction); if(log.isInfoEnabled()) { log.info("rollback transaction=" + txStatus); } if ((txStatus != Status.STATUS_NO_TRANSACTION) && (txStatus != Status.STATUS_COMMITTED) && (txStatus != Status.STATUS_ROLLEDBACK)) { JtaTransactionHelper.rollback(); } }
Example 9
Source File: JtaTransactionManager.java From seed with Mozilla Public License 2.0 | 5 votes |
private PropagationResult handlePropagation(Propagation propagation) throws SystemException { switch (propagation) { case MANDATORY: if (userTransaction.getStatus() != Status.STATUS_ACTIVE) { throw SeedException.createNew( TransactionErrorCode.TRANSACTION_NEEDED_WHEN_USING_PROPAGATION_MANDATORY); } return new PropagationResult(false, false); case NEVER: if (userTransaction.getStatus() != Status.STATUS_NO_TRANSACTION) { throw SeedException.createNew( TransactionErrorCode.NO_TRANSACTION_ALLOWED_WHEN_USING_PROPAGATION_NEVER); } return new PropagationResult(false, false); case NOT_SUPPORTED: return new PropagationResult(false, true); case REQUIRED: return new PropagationResult(userTransaction.getStatus() != Status.STATUS_ACTIVE, false); case REQUIRES_NEW: return new PropagationResult(true, true); case SUPPORTS: return new PropagationResult(false, false); default: throw SeedException.createNew(TransactionErrorCode.PROPAGATION_NOT_SUPPORTED).put("propagation", propagation); } }
Example 10
Source File: BeanManagedUserTransactionStrategy.java From deltaspike with Apache License 2.0 | 5 votes |
protected boolean isTransactionAllowedToRollback() throws SystemException { //if the following gets changed, it needs to be tested with different constellations //(normal exception, timeout,...) as well as servers return this.getTransactionStatus() != Status.STATUS_COMMITTED && this.getTransactionStatus() != Status.STATUS_NO_TRANSACTION && this.getTransactionStatus() != Status.STATUS_UNKNOWN; }
Example 11
Source File: DSSXATransactionManager.java From micro-integrator with Apache License 2.0 | 5 votes |
public boolean isInDTX() { TransactionManager txManager = getTransactionManager(); if (txManager == null) { return false; } try { return txManager.getStatus() != Status.STATUS_NO_TRANSACTION; } catch (Exception e) { log.error("Error at 'hasNoActiveTransaction'", e); return false; } }
Example 12
Source File: TransactionInvocationHandlersTest.java From development with Apache License 2.0 | 5 votes |
@Override public void commit() { status = Status.STATUS_NO_TRANSACTION; stubCalls.add("commit()"); if (failCommit) { throw new RollbackException(); } }
Example 13
Source File: JtaTransactionManager.java From java-technology-stack with MIT License | 5 votes |
@Override protected boolean isExistingTransaction(Object transaction) { JtaTransactionObject txObject = (JtaTransactionObject) transaction; try { return (txObject.getUserTransaction().getStatus() != Status.STATUS_NO_TRANSACTION); } catch (SystemException ex) { throw new TransactionSystemException("JTA failure on getStatus", ex); } }
Example 14
Source File: JtaTransactionManager.java From spring-analysis-note with MIT License | 5 votes |
@Override protected boolean isExistingTransaction(Object transaction) { JtaTransactionObject txObject = (JtaTransactionObject) transaction; try { return (txObject.getUserTransaction().getStatus() != Status.STATUS_NO_TRANSACTION); } catch (SystemException ex) { throw new TransactionSystemException("JTA failure on getStatus", ex); } }
Example 15
Source File: JtaRetryInterceptor.java From flowable-engine with Apache License 2.0 | 5 votes |
protected boolean calledInsideTransaction() { try { return transactionManager.getStatus() != Status.STATUS_NO_TRANSACTION; } catch (SystemException e) { throw new FlowableException("Could not determine the current status of the transaction manager: " + e.getMessage(), e); } }
Example 16
Source File: TransactionInvocationHandlersTest.java From development with Apache License 2.0 | 4 votes |
@Override public void rollback() throws RollbackException { status = Status.STATUS_NO_TRANSACTION; stubCalls.add("rollback()"); }
Example 17
Source File: MdwTransactionManager.java From mdw with Apache License 2.0 | 4 votes |
@Override public int getStatus() throws SystemException { return transaction==null?Status.STATUS_NO_TRANSACTION:transaction.getStatus(); }
Example 18
Source File: XAShardingTransactionManager.java From shardingsphere with Apache License 2.0 | 4 votes |
@SneakyThrows @Override public boolean isInTransaction() { return Status.STATUS_NO_TRANSACTION != xaTransactionManager.getTransactionManager().getStatus(); }
Example 19
Source File: SpringAwareUserTransaction.java From alfresco-core with GNU Lesser General Public License v3.0 | 4 votes |
/** * Gets the current transaction info, or null if none exists. * <p> * A check is done to ensure that the transaction info on the stack is exactly * the same instance used when this transaction was started. * The internal status is also checked against the transaction info. * These checks ensure that the transaction demarcation is done correctly and that * thread safety is adhered to. * * @return Returns the current transaction */ private TransactionInfo getTransactionInfo() { // a few quick self-checks if (threadId < 0 && internalStatus != Status.STATUS_NO_TRANSACTION) { throw new RuntimeException("Transaction has been started but there is no thread ID"); } else if (threadId >= 0 && internalStatus == Status.STATUS_NO_TRANSACTION) { throw new RuntimeException("Transaction has not been started but a thread ID has been recorded"); } TransactionInfo txnInfo = null; try { txnInfo = TransactionAspectSupport.currentTransactionInfo(); // we are in a transaction } catch (NoTransactionException e) { // No transaction. It is possible that the transaction threw an exception during commit. } // perform checks for active transactions if (internalStatus == Status.STATUS_ACTIVE) { if (Thread.currentThread().getId() != threadId) { // the internally stored transaction info (retrieved in begin()) should match the info // on the thread throw new RuntimeException("UserTransaction may not be accessed by multiple threads"); } else if (txnInfo == null) { // internally we recorded a transaction starting, but there is nothing on the thread throw new RuntimeException("Transaction boundaries have been made to overlap in the stack"); } else if (txnInfo != internalTxnInfo) { // the transaction info on the stack isn't the one we started with throw new RuntimeException("UserTransaction begin/commit mismatch"); } } return txnInfo; }
Example 20
Source File: TransactionManagerImpl.java From ByteTCC with GNU Lesser General Public License v3.0 | 4 votes |
public int getStatus() throws SystemException { Transaction transaction = this.getTransaction(); return transaction == null ? Status.STATUS_NO_TRANSACTION : transaction.getTransactionStatus(); }