List of usage examples for javax.transaction Status STATUS_ACTIVE
int STATUS_ACTIVE
To view the source code for javax.transaction Status STATUS_ACTIVE.
Click Source Link
From source file:org.apache.ofbiz.entity.transaction.TransactionUtil.java
public static String getTransactionStateString(int state) { /*/*from w w w. java2 s. com*/ * javax.transaction.Status * STATUS_ACTIVE 0 * STATUS_MARKED_ROLLBACK 1 * STATUS_PREPARED 2 * STATUS_COMMITTED 3 * STATUS_ROLLEDBACK 4 * STATUS_UNKNOWN 5 * STATUS_NO_TRANSACTION 6 * STATUS_PREPARING 7 * STATUS_COMMITTING 8 * STATUS_ROLLING_BACK 9 */ switch (state) { case Status.STATUS_ACTIVE: return "Transaction Active (" + state + ")"; case Status.STATUS_COMMITTED: return "Transaction Committed (" + state + ")"; case Status.STATUS_COMMITTING: return "Transaction Committing (" + state + ")"; case Status.STATUS_MARKED_ROLLBACK: return "Transaction Marked Rollback (" + state + ")"; case Status.STATUS_NO_TRANSACTION: return "No Transaction (" + state + ")"; case Status.STATUS_PREPARED: return "Transaction Prepared (" + state + ")"; case Status.STATUS_PREPARING: return "Transaction Preparing (" + state + ")"; case Status.STATUS_ROLLEDBACK: return "Transaction Rolledback (" + state + ")"; case Status.STATUS_ROLLING_BACK: return "Transaction Rolling Back (" + state + ")"; case Status.STATUS_UNKNOWN: return "Transaction Status Unknown (" + state + ")"; default: return "Not a valid state code (" + state + ")"; } }
From source file:org.apache.ojb.broker.core.PersistenceBrokerFactorySyncImpl.java
private Transaction searchForValidTx() throws SystemException { Transaction tx = txMan.getTransaction(); if (tx != null) { int status = tx.getStatus(); if (status != Status.STATUS_ACTIVE && status != Status.STATUS_NO_TRANSACTION) { throw new PBFactoryException("Transaction synchronization failed - wrong" + " status of external JTA tx. Expected was an 'active' or 'no transaction'" + ", found status is '" + getStatusFlagAsString(status) + "'"); }//from w w w . j av a 2 s .c o m } return tx; }
From source file:org.apache.ojb.odmg.JTATxManager.java
/** * Do synchronization of the given J2EE ODMG Transaction *///from w w w .j a v a 2 s . c o m private void registerSynchronization(TransactionImpl odmgTrans, Transaction transaction) { // todo only need for development if (odmgTrans == null || transaction == null) { log.error("One of the given parameters was null --> cannot do synchronization!" + " omdg transaction was null: " + (odmgTrans == null) + ", external transaction was null: " + (transaction == null)); return; } int status = -1; // default status. try { status = transaction.getStatus(); if (status != Status.STATUS_ACTIVE) { throw new OJBRuntimeException( "Transaction synchronization failed - wrong status of external container tx: " + getStatusString(status)); } } catch (SystemException e) { throw new OJBRuntimeException("Can't read status of external tx", e); } try { //Sequence of the following method calls is significant // 1. register the synchronization with the ODMG notion of a transaction. transaction.registerSynchronization((J2EETransactionImpl) odmgTrans); // 2. mark the ODMG transaction as being in a JTA Transaction // Associate external transaction with the odmg transaction. txRepository.set(new TxBuffer(odmgTrans, transaction)); } catch (Exception e) { log.error("Cannot associate PersistenceBroker with running Transaction", e); throw new OJBRuntimeException( "Transaction synchronization failed - wrong status of external container tx", e); } }
From source file:org.apache.ojb.odmg.JTATxManager.java
private static String getStatusString(int status) { switch (status) { case Status.STATUS_ACTIVE: return "STATUS_ACTIVE"; case Status.STATUS_COMMITTED: return "STATUS_COMMITTED"; case Status.STATUS_COMMITTING: return "STATUS_COMMITTING"; case Status.STATUS_MARKED_ROLLBACK: return "STATUS_MARKED_ROLLBACK"; case Status.STATUS_NO_TRANSACTION: return "STATUS_NO_TRANSACTION"; case Status.STATUS_PREPARED: return "STATUS_PREPARED"; case Status.STATUS_PREPARING: return "STATUS_PREPARING"; case Status.STATUS_ROLLEDBACK: return "STATUS_ROLLEDBACK"; case Status.STATUS_ROLLING_BACK: return "STATUS_ROLLING_BACK"; case Status.STATUS_UNKNOWN: return "STATUS_UNKNOWN"; default:// w w w . j ava 2 s. c om return "NO STATUS FOUND"; } }
From source file:org.apache.ojb.odmg.JTATxManager.java
/** * Abort an active extern transaction associated with the given PB. *///from w w w . j a v a 2 s .com public void abortExternalTx(TransactionImpl odmgTrans) { if (log.isDebugEnabled()) log.debug("abortExternTransaction was called"); if (odmgTrans == null) return; TxBuffer buf = (TxBuffer) txRepository.get(); Transaction extTx = buf != null ? buf.getExternTx() : null; try { if (extTx != null && extTx.getStatus() == Status.STATUS_ACTIVE) { if (log.isDebugEnabled()) { log.debug("Set extern transaction to rollback"); } extTx.setRollbackOnly(); } } catch (Exception ignore) { } txRepository.set(null); }
From source file:org.apache.ojb.odmg.TransactionImpl.java
/** * Determine whether the transaction is open or not. A transaction is open if * a call has been made to <code>begin</code> , but a subsequent call to * either <code>commit</code> or <code>abort</code> has not been made. * @return True if the transaction is open, otherwise false. *//*from w w w. j a v a2s.co m*/ public boolean isOpen() { return (getStatus() == Status.STATUS_ACTIVE || getStatus() == Status.STATUS_MARKED_ROLLBACK || getStatus() == Status.STATUS_PREPARED || getStatus() == Status.STATUS_PREPARING || getStatus() == Status.STATUS_COMMITTING); }
From source file:org.apache.ojb.odmg.TransactionImpl.java
/** * Prepare does the actual work of moving the changes at the object level * into storage (the underlying rdbms for instance). prepare Can be called multiple times, and * does not release locks.//from w w w.jav a2 s .com * * @throws TransactionAbortedException if the transaction has been aborted * for any reason. * @throws IllegalStateException Method called if transaction is * not in the proper state to perform this operation * @throws TransactionNotInProgressException if the transaction is closed. */ protected void prepareCommit() throws TransactionAbortedException, LockNotGrantedException { if (txStatus == Status.STATUS_MARKED_ROLLBACK) { throw new TransactionAbortedExceptionOJB("Prepare Transaction: tx already marked for rollback"); } if (txStatus != Status.STATUS_ACTIVE) { throw new IllegalStateException("Prepare Transaction: tx status is not 'active', status is " + TxUtil.getStatusString(txStatus)); } try { txStatus = Status.STATUS_PREPARING; doWriteObjects(false); txStatus = Status.STATUS_PREPARED; } catch (RuntimeException e) { log.error("Could not prepare for commit", e); txStatus = Status.STATUS_MARKED_ROLLBACK; throw e; } }
From source file:org.apache.ojb.odmg.TransactionImpl.java
/** * Abort and close the transaction. Calling abort abandons all persistent * object modifications and releases the associated locks. Aborting a * transaction does not restore the state of modified transient objects *//* w w w. j a v a 2 s . c o m*/ public void abort() { /* do nothing if already rolledback */ if (txStatus == Status.STATUS_NO_TRANSACTION || txStatus == Status.STATUS_UNKNOWN || txStatus == Status.STATUS_ROLLEDBACK) { log.info("Nothing to abort, tx is not active - status is " + TxUtil.getStatusString(txStatus)); return; } // check status of tx if (txStatus != Status.STATUS_ACTIVE && txStatus != Status.STATUS_PREPARED && txStatus != Status.STATUS_MARKED_ROLLBACK) { throw new IllegalStateException( "Illegal state for abort call, state was '" + TxUtil.getStatusString(txStatus) + "'"); } if (log.isEnabledFor(Logger.INFO)) { log.info("Abort transaction was called on tx " + this); } try { try { doAbort(); } catch (Exception e) { log.error("Error while abort transaction, will be skipped", e); } // used in managed environments, ignored in non-managed this.implementation.getTxManager().abortExternalTx(this); try { if (hasBroker() && getBroker().isInTransaction()) { getBroker().abortTransaction(); } } catch (Exception e) { log.error("Error while do abort used broker instance, will be skipped", e); } } finally { txStatus = Status.STATUS_ROLLEDBACK; // cleanup things, e.g. release all locks doClose(); } }
From source file:org.apache.ojb.odmg.TransactionImpl.java
/** * Start a transaction. Calling <code>begin</code> multiple times on the same * transaction object, without an intervening call to <code>commit</code> or * <code>abort</code> , causes the exception <code> * TransactionInProgressException</code> to be thrown on the second and * subsequent calls. Operations executed before a transaction has been opened, * or before reopening after a transaction is aborted or committed, have * undefined results; these may throw a <code> * TransactionNotInProgressException</code> exception. *///from ww w. j av a 2s.c om public synchronized void begin() { checkForBegin(); if (log.isDebugEnabled()) log.debug("Begin transaction was called on tx " + this); // initialize the ObjectEnvelope table objectEnvelopeTable = new ObjectEnvelopeTable(this); // register transaction implementation.getTxManager().registerTx(this); // mark tx as active (open) txStatus = Status.STATUS_ACTIVE; }
From source file:org.bytesoft.bytejta.TransactionRecoveryImpl.java
private void recoverCoordinator(Transaction transaction) throws CommitRequiredException, RollbackRequiredException, SystemException { switch (transaction.getTransactionStatus()) { case Status.STATUS_ACTIVE: case Status.STATUS_MARKED_ROLLBACK: case Status.STATUS_PREPARING: case Status.STATUS_ROLLING_BACK: case Status.STATUS_UNKNOWN: transaction.recoveryRollback();//from ww w.jav a2 s.c o m transaction.forgetQuietly(); break; case Status.STATUS_PREPARED: case Status.STATUS_COMMITTING: transaction.recoveryCommit(); transaction.forgetQuietly(); break; case Status.STATUS_COMMITTED: case Status.STATUS_ROLLEDBACK: transaction.forgetQuietly(); break; default: logger.debug("Current transaction has already been completed."); } }