List of usage examples for javax.transaction Status STATUS_MARKED_ROLLBACK
int STATUS_MARKED_ROLLBACK
To view the source code for javax.transaction Status STATUS_MARKED_ROLLBACK.
Click Source Link
From source file:com.impetus.kundera.persistence.jta.KunderaJTAUserTransaction.java
@Override public void begin() throws NotSupportedException, SystemException { log.info("beginning JTA transaction"); isTransactionInProgress = true;//from ww w . ja v a2s . c om Transaction tx = threadLocal.get(); if (tx != null) { if ((tx.getStatus() == Status.STATUS_MARKED_ROLLBACK)) { throw new NotSupportedException("Nested Transaction not supported!"); } } Integer timer = timerThead.get(); threadLocal.set(new KunderaTransaction(timer != null ? timer : DEFAULT_TIME_OUT)); }
From source file:org.grails.orm.hibernate.GrailsSessionContext.java
protected void registerJtaSynchronization(Session session, SessionHolder sessionHolder) { // JTA synchronization is only possible with a javax.transaction.TransactionManager. // We'll check the Hibernate SessionFactory: If a TransactionManagerLookup is specified // in Hibernate configuration, it will contain a TransactionManager reference. TransactionManager jtaTm = getJtaTransactionManager(session); if (jtaTm == null) { return;/* ww w. ja v a 2 s . c o m*/ } try { Transaction jtaTx = jtaTm.getTransaction(); if (jtaTx == null) { return; } int jtaStatus = jtaTx.getStatus(); if (jtaStatus != Status.STATUS_ACTIVE && jtaStatus != Status.STATUS_MARKED_ROLLBACK) { return; } LOG.debug("Registering JTA transaction synchronization for new Hibernate Session"); SessionHolder holderToUse = sessionHolder; // Register JTA Transaction with existing SessionHolder. // Create a new SessionHolder if none existed before. if (holderToUse == null) { holderToUse = new SessionHolder(session); } else { // it's up to the caller to manage concurrent sessions // holderToUse.addSession(session); } jtaTx.registerSynchronization( new SpringJtaSynchronizationAdapter(createSpringSessionSynchronization(holderToUse), jtaTm)); holderToUse.setSynchronizedWithTransaction(true); if (holderToUse != sessionHolder) { TransactionSynchronizationManager.bindResource(sessionFactory, holderToUse); } } catch (Throwable ex) { throw new DataAccessResourceFailureException( "Could not register synchronization with JTA TransactionManager", ex); } }
From source file:org.alfresco.util.transaction.SpringAwareUserTransaction.java
/** * This status is a combination of the internal status, as recorded during explicit operations, * and the status provided by the Spring support. * // w w w . jav a 2 s. c o m * @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; } }
From source file:org.alfresco.util.transaction.SpringAwareUserTransaction.java
public synchronized void setRollbackOnly() throws IllegalStateException, SystemException { // just a check TransactionInfo txnInfo = getTransactionInfo(); int status = getStatus(); // check the status if (status == Status.STATUS_MARKED_ROLLBACK) { // this is acceptable } else if (status == Status.STATUS_NO_TRANSACTION) { throw new IllegalStateException("The transaction has not been started yet"); } else if (status == Status.STATUS_ROLLING_BACK || status == Status.STATUS_ROLLEDBACK) { throw new IllegalStateException("The transaction has already been rolled back"); } else if (status == Status.STATUS_COMMITTING || status == Status.STATUS_COMMITTED) { throw new IllegalStateException("The transaction has already been committed"); } else if (status != Status.STATUS_ACTIVE) { throw new IllegalStateException("The transaction is not active: " + status); }//from www. j a va 2 s . com // mark for rollback txnInfo.getTransactionStatus().setRollbackOnly(); // make sure that we record the fact that we have been marked for rollback internalStatus = Status.STATUS_MARKED_ROLLBACK; // done if (logger.isDebugEnabled()) { logger.debug("Set transaction status to rollback only: " + this); } }
From source file:org.alfresco.util.transaction.SpringAwareUserTransaction.java
/** * @throws IllegalStateException if a transaction was not started */// ww w .j a v a 2s .c o m public synchronized void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException { // perform checks TransactionInfo txnInfo = getTransactionInfo(); int status = getStatus(); // check the status if (status == Status.STATUS_NO_TRANSACTION) { throw new IllegalStateException("The transaction has not yet begun"); } else if (status == Status.STATUS_ROLLING_BACK || status == Status.STATUS_ROLLEDBACK) { throw new RollbackException("The transaction has already been rolled back"); } else if (status == Status.STATUS_MARKED_ROLLBACK) { throw new RollbackException("The transaction has already been marked for rollback"); } else if (status == Status.STATUS_COMMITTING || status == Status.STATUS_COMMITTED) { throw new IllegalStateException("The transaction has already been committed"); } else if (status != Status.STATUS_ACTIVE || txnInfo == null) { throw new IllegalStateException("No user transaction is active"); } if (!finalized) { try { // the status seems correct - we can try a commit commitTransactionAfterReturning(txnInfo); } catch (Throwable e) { if (logger.isDebugEnabled()) { logger.debug("Transaction didn't commit", e); } // commit failed internalStatus = Status.STATUS_ROLLEDBACK; RollbackException re = new RollbackException("Transaction didn't commit: " + e.getMessage()); // Stick the originating reason for failure into the exception. re.initCause(e); throw re; } finally { // make sure that we clean up the stack cleanupTransactionInfo(txnInfo); finalized = true; // clean up leaked transaction logging isBeginMatched = true; beginCallStack = null; } } // regardless of whether the transaction was finally committed or not, the status // as far as UserTransaction is concerned should be 'committed' // keep track that this UserTransaction was explicitly committed internalStatus = Status.STATUS_COMMITTED; // done if (logger.isDebugEnabled()) { logger.debug("Committed user transaction: " + this); } }
From source file:org.alfresco.filesys.alfresco.AlfrescoTxDiskDriver.java
/** * End an active transaction/*from www . j a v a2s.co m*/ * * @param sess SrvSession * @param tx Object */ public void endTransaction(SrvSession sess, Object tx) { // Check that the transaction object is valid if (tx == null) return; // Get the filesystem transaction FilesysTransaction filesysTx = (FilesysTransaction) tx; // Check if there is an active transaction if (filesysTx != null && filesysTx.hasTransaction()) { // Get the active transaction UserTransaction ftx = filesysTx.getTransaction(); try { // Commit or rollback the transaction if (ftx.getStatus() == Status.STATUS_MARKED_ROLLBACK || ftx.getStatus() == Status.STATUS_ROLLEDBACK || ftx.getStatus() == Status.STATUS_ROLLING_BACK) { // Transaction is marked for rollback ftx.rollback(); // DEBUG if (logger.isDebugEnabled()) logger.debug("End transaction (rollback)"); } else { // Commit the transaction ftx.commit(); // DEBUG if (logger.isDebugEnabled()) logger.debug("End transaction (commit)"); } } catch (Exception ex) { if (logger.isDebugEnabled()) logger.debug("Failed to end transaction, " + ex.getMessage()); // throw new AlfrescoRuntimeException("Failed to end transaction", ex); } finally { // Clear the current transaction sess.clearTransaction(); } } }
From source file:org.alfresco.filesys.alfresco.AlfrescoTxDiskDriver.java
/** * Create and start a transaction, if not already active * //from www . ja v a 2 s. com * @param sess SrvSession * @param readOnly boolean * @exception AlfrescoRuntimeException */ private final void beginTransaction(SrvSession sess, boolean readOnly) throws AlfrescoRuntimeException { // Do nothing if we are already in a retrying transaction Boolean inRetryingTransaction = m_inRetryingTransaction.get(); if (inRetryingTransaction != null && inRetryingTransaction) { return; } // Initialize the per session thread local that holds the transaction sess.initializeTransactionObject(); // Get the filesystem transaction FilesysTransaction filesysTx = (FilesysTransaction) sess.getTransactionObject().get(); if (filesysTx == null) { filesysTx = new FilesysTransaction(); sess.getTransactionObject().set(filesysTx); } // If there is an active transaction check that it is the required type if (filesysTx.hasTransaction()) { // Get the active transaction UserTransaction tx = filesysTx.getTransaction(); // Check if the current transaction is marked for rollback try { if (tx.getStatus() == Status.STATUS_MARKED_ROLLBACK || tx.getStatus() == Status.STATUS_ROLLEDBACK || tx.getStatus() == Status.STATUS_ROLLING_BACK) { // Rollback the current transaction tx.rollback(); } } catch (Exception ex) { } // Check if the transaction is a write transaction, if write has been requested if (readOnly == false && filesysTx.isReadOnly() == true) { // Commit the read-only transaction try { tx.commit(); } catch (Exception ex) { throw new AlfrescoRuntimeException( "Failed to commit read-only transaction, " + ex.getMessage()); } finally { // Clear the active transaction filesysTx.clearTransaction(); } } } // Create the transaction if (filesysTx.hasTransaction() == false) { try { // Create a new transaction UserTransaction userTrans = m_transactionService.getUserTransaction(readOnly); userTrans.begin(); // Store the transaction filesysTx.setTransaction(userTrans, readOnly); // DEBUG if (logger.isDebugEnabled()) logger.debug("Created transaction readOnly=" + readOnly); } catch (Exception ex) { throw new AlfrescoRuntimeException("Failed to create transaction, " + ex.getMessage()); } } // Store the transaction callback sess.setTransaction(this); }
From source file:org.alfresco.repo.search.impl.lucene.AbstractLuceneIndexerImpl.java
/** * Utility method to report errors about invalid state. * /*from w ww .j av a2 s .c om*/ * @return - an error based on status */ private String buildErrorString() { StringBuilder buffer = new StringBuilder(128); buffer.append("The indexer is unable to accept more work: "); switch (getStatus().getStatus()) { case Status.STATUS_COMMITTED: buffer.append("The indexer has been committed"); break; case Status.STATUS_COMMITTING: buffer.append("The indexer is committing"); break; case Status.STATUS_MARKED_ROLLBACK: buffer.append("The indexer is marked for rollback"); break; case Status.STATUS_PREPARED: buffer.append("The indexer is prepared to commit"); break; case Status.STATUS_PREPARING: buffer.append("The indexer is preparing to commit"); break; case Status.STATUS_ROLLEDBACK: buffer.append("The indexer has been rolled back"); break; case Status.STATUS_ROLLING_BACK: buffer.append("The indexer is rolling back"); break; case Status.STATUS_UNKNOWN: buffer.append("The indexer is in an unknown state"); break; default: break; } return buffer.toString(); }
From source file:org.alfresco.repo.search.impl.lucene.AbstractLuceneIndexerImpl.java
/** * Commit this index//from w w w .j a v a2 s . c o m * * @throws LuceneIndexException */ public void commit() throws LuceneIndexException { if (s_logger.isDebugEnabled()) { s_logger.debug(Thread.currentThread().getName() + " Starting Commit"); } switch (getStatus().getStatus()) { case Status.STATUS_COMMITTING: throw new LuceneIndexException("Unable to commit: Transaction is committing"); case Status.STATUS_COMMITTED: throw new LuceneIndexException("Unable to commit: Transaction is commited "); case Status.STATUS_ROLLING_BACK: throw new LuceneIndexException("Unable to commit: Transaction is rolling back"); case Status.STATUS_ROLLEDBACK: throw new LuceneIndexException("Unable to commit: Transaction is aleady rolled back"); case Status.STATUS_MARKED_ROLLBACK: throw new LuceneIndexException("Unable to commit: Transaction is marked for roll back"); case Status.STATUS_PREPARING: throw new LuceneIndexException("Unable to commit: Transaction is preparing"); case Status.STATUS_ACTIVE: // special case - commit from active prepare(); // drop through to do the commit; default: if (getStatus().getStatus() != Status.STATUS_PREPARED) { throw new LuceneIndexException("Index must be prepared to commit"); } try { setStatus(TransactionStatus.COMMITTING); if (isModified()) { doCommit(); } setStatus(TransactionStatus.COMMITTED); } catch (LuceneIndexException e) { // If anything goes wrong we try and do a roll back rollback(); if (s_logger.isDebugEnabled()) { s_logger.debug(Thread.currentThread().getName() + " Commit Failed", e); } throw new LuceneIndexException("Commit failed", e); } catch (Throwable t) { // If anything goes wrong we try and do a roll back rollback(); if (s_logger.isDebugEnabled()) { s_logger.debug(Thread.currentThread().getName() + " Commit Failed", t); } throw new LuceneIndexException("Commit failed", t); } finally { if (s_logger.isDebugEnabled()) { s_logger.debug(Thread.currentThread().getName() + " Ending Commit"); } // Make sure we tidy up // deleteDelta(); } break; } }
From source file:org.alfresco.repo.search.impl.lucene.AbstractLuceneIndexerImpl.java
/** * Prepare to commit At the moment this makes sure we have all the locks TODO: This is not doing proper * serialisation against the index as would a data base transaction. * /*w w w .j a v a2 s .com*/ * @return the tx state * @throws LuceneIndexException */ public int prepare() throws LuceneIndexException { if (s_logger.isDebugEnabled()) { s_logger.debug(Thread.currentThread().getName() + " Starting Prepare"); } switch (getStatus().getStatus()) { case Status.STATUS_COMMITTING: throw new IndexerException("Unable to prepare: Transaction is committing"); case Status.STATUS_COMMITTED: throw new IndexerException("Unable to prepare: Transaction is commited "); case Status.STATUS_ROLLING_BACK: throw new IndexerException("Unable to prepare: Transaction is rolling back"); case Status.STATUS_ROLLEDBACK: throw new IndexerException("Unable to prepare: Transaction is aleady rolled back"); case Status.STATUS_MARKED_ROLLBACK: throw new IndexerException("Unable to prepare: Transaction is marked for roll back"); case Status.STATUS_PREPARING: throw new IndexerException("Unable to prepare: Transaction is already preparing"); case Status.STATUS_PREPARED: throw new IndexerException("Unable to prepare: Transaction is already prepared"); default: try { setStatus(TransactionStatus.PREPARING); if (isModified()) { doPrepare(); if (s_logger.isDebugEnabled()) { s_logger.debug(Thread.currentThread().getName() + " Waiting to Finish Preparing"); } } setStatus(TransactionStatus.PREPARED); return isModified() ? XAResource.XA_OK : XAResource.XA_RDONLY; } catch (LuceneIndexException e) { setRollbackOnly(); if (s_logger.isDebugEnabled()) { s_logger.debug(Thread.currentThread().getName() + " Prepare Failed", e); } throw new LuceneIndexException("Index failed to prepare", e); } catch (Throwable t) { // If anything goes wrong we try and do a roll back rollback(); if (s_logger.isDebugEnabled()) { s_logger.debug(Thread.currentThread().getName() + " Prepare Failed", t); } throw new LuceneIndexException("Prepared failed", t); } finally { if (s_logger.isDebugEnabled()) { s_logger.debug(Thread.currentThread().getName() + " Ending Prepare"); } } } }