Java Code Examples for javax.transaction.Status#STATUS_ROLLING_BACK

The following examples show how to use javax.transaction.Status#STATUS_ROLLING_BACK . 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: UserTransactionImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void commit() throws RollbackException,
                            HeuristicMixedException,
                            HeuristicRollbackException,
                            SecurityException,
                            IllegalStateException,
                            SystemException
{
   Transaction tx = registry.getTransaction();

   if (tx == null)
      throw new SystemException();

   if (tx.getStatus() == Status.STATUS_ROLLING_BACK ||
       tx.getStatus() == Status.STATUS_ROLLEDBACK ||
       tx.getStatus() == Status.STATUS_MARKED_ROLLBACK)
      throw new RollbackException();

   registry.commitTransaction();
}
 
Example 2
Source File: TracingTransactionInterceptor.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * @param txStatus
 * @return String
 */
private static final String toString(int txStatus) {
    switch (txStatus) {
        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: return "unknown status: " + txStatus;
    }
}
 
Example 3
Source File: MithraRemoteTransactionProxy.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void rollback() throws MithraTransactionException
{
    if (this.proxyStatus == Status.STATUS_ACTIVE)
    {
        this.proxyStatus = Status.STATUS_ROLLING_BACK;
        this.delistAll(XAResource.TMFAIL);
        this.rollbackAllXaResources();
        this.handleCacheRollback();
        this.proxyStatus = Status.STATUS_ROLLEDBACK;
        this.notificationEvents.clear();
        afterCompletion();
    }
    else
    {
        throw new MithraTransactionException("Cannot rollback with proxyStatus " + getJtaTransactionStatusDescription(this.proxyStatus));
    }
}
 
Example 4
Source File: UserTransactionImpl.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void commit() throws RollbackException,
                            HeuristicMixedException,
                            HeuristicRollbackException,
                            SecurityException,
                            IllegalStateException,
                            SystemException
{
   Transaction tx = registry.getTransaction();

   if (tx == null)
      throw new SystemException();

   if (tx.getStatus() == Status.STATUS_ROLLING_BACK ||
       tx.getStatus() == Status.STATUS_ROLLEDBACK ||
       tx.getStatus() == Status.STATUS_MARKED_ROLLBACK)
      throw new RollbackException();

   registry.commitTransaction();
}
 
Example 5
Source File: TransactionRecoveryImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void recoverParticipant(Transaction transaction)
		throws CommitRequiredException, RollbackRequiredException, SystemException {

	TransactionImpl transactionImpl = (TransactionImpl) transaction;
	switch (transaction.getTransactionStatus()) {
	case Status.STATUS_PREPARED:
	case Status.STATUS_COMMITTING:
		break;
	case Status.STATUS_COMMITTED:
	case Status.STATUS_ROLLEDBACK:
		break;
	case Status.STATUS_ACTIVE:
	case Status.STATUS_MARKED_ROLLBACK:
	case Status.STATUS_PREPARING:
	case Status.STATUS_UNKNOWN:
	case Status.STATUS_ROLLING_BACK:
	default:
		transactionImpl.recoveryRollback();
		transactionImpl.forgetQuietly();
	}
}
 
Example 6
Source File: JtaTransaction.java    From cdi with Apache License 2.0 6 votes vote down vote up
private String statusToString(int status) {
    switch (status) {
        case Status.STATUS_ACTIVE:
            return "Active";
        case Status.STATUS_COMMITTED:
            return "Committed";
        case Status.STATUS_COMMITTING:
            return "Commiting";
        case Status.STATUS_MARKED_ROLLBACK:
            return "Marked for rollback";
        case Status.STATUS_NO_TRANSACTION:
            return "No transaction";
        case Status.STATUS_PREPARED:
            return "Prepared";
        case Status.STATUS_PREPARING:
            return "Preparing";
        case Status.STATUS_ROLLEDBACK:
            return "Rolled back";
        case Status.STATUS_ROLLING_BACK:
            return "Rolling back";
        case Status.STATUS_UNKNOWN:
            return "Unknown";
        default:
            return null;
    }
}
 
Example 7
Source File: TransactionImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public synchronized void recover() throws SystemException {
	if (transactionStatus == Status.STATUS_PREPARING) {
		this.recover4PreparingStatus();
	} else if (transactionStatus == Status.STATUS_COMMITTING) {
		this.recover4CommittingStatus();
	} else if (transactionStatus == Status.STATUS_ROLLING_BACK) {
		this.recover4RollingBackStatus();
	}
}
 
Example 8
Source File: AbstractLuceneIndexerImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Roll back the index changes (this just means they are never added)
 * 
 * @throws LuceneIndexException
 */
public void rollback() throws LuceneIndexException
{
    switch (getStatus().getStatus())
    {

    case Status.STATUS_COMMITTED:
        throw new IndexerException("Unable to roll back: Transaction is committed ");
    case Status.STATUS_ROLLING_BACK:
        throw new IndexerException("Unable to roll back: Transaction is rolling back");
    case Status.STATUS_ROLLEDBACK:
        throw new IndexerException("Unable to roll back: Transaction is already rolled back");
    case Status.STATUS_COMMITTING:
        // Can roll back during commit
    default:
        try
        {
            setStatus(TransactionStatus.ROLLINGBACK);
            doRollBack();
            setStatus(TransactionStatus.ROLLEDBACK);
        }
        catch (IOException e)
        {
            throw new LuceneIndexException("rollback failed ", e);
        }
        break;
    }
}
 
Example 9
Source File: CompensableTransactionImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
public synchronized void recover() throws SystemException {
	if (this.transactionStatus == Status.STATUS_PREPARED //
			|| this.transactionStatus == Status.STATUS_COMMITTING) {
		this.recoverNativeResource(true);
		this.recoverRemoteResource(true);
	} else if (this.transactionStatus == Status.STATUS_PREPARING //
			|| this.transactionStatus == Status.STATUS_ROLLING_BACK) {
		this.recoverNativeResource(false);
		this.recoverRemoteResource(false);
	}
}
 
Example 10
Source File: TransactionContext.java    From openwebbeans-meecrowave with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isActive() {
    try {
        final int status = transactionManager.getTransaction().getStatus();
        return status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK
                || status == Status.STATUS_PREPARED || status == Status.STATUS_PREPARING
                || status == Status.STATUS_COMMITTING || status == Status.STATUS_ROLLING_BACK
                || status == Status.STATUS_UNKNOWN;
    } catch (final Throwable e) {
        return false;
    }
}
 
Example 11
Source File: TxUtils.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts a transaction status to a text representation
 * 
 * @param status The status index
 * @return status as String or "STATUS_INVALID(value)"
 * @see javax.transaction.Status
 */
public static String getStatusAsString(int status)
{
   if (status >= Status.STATUS_ACTIVE && status <= Status.STATUS_ROLLING_BACK)
   {
      return TX_STATUS_STRINGS[status];
   }
   else
   {
      return "STATUS_INVALID(" + status + ")";
   }
}
 
Example 12
Source File: StatusTranslator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static TransactionStatus translate(int status) {
	TransactionStatus transactionStatus = null;
	switch ( status ) {
		case Status.STATUS_ACTIVE:
			transactionStatus = TransactionStatus.ACTIVE;
			break;
		case Status.STATUS_PREPARED:
			transactionStatus = TransactionStatus.ACTIVE;
			break;
		case Status.STATUS_PREPARING:
			transactionStatus = TransactionStatus.ACTIVE;
			break;
		case Status.STATUS_COMMITTING:
			transactionStatus = TransactionStatus.COMMITTING;
			break;
		case Status.STATUS_ROLLING_BACK:
			transactionStatus = TransactionStatus.ROLLING_BACK;
			break;
		case Status.STATUS_NO_TRANSACTION:
			transactionStatus = TransactionStatus.NOT_ACTIVE;
			break;
		case Status.STATUS_COMMITTED:
			transactionStatus = TransactionStatus.COMMITTED;
			break;
		case Status.STATUS_ROLLEDBACK:
			transactionStatus = TransactionStatus.ROLLED_BACK;
			break;
		case Status.STATUS_MARKED_ROLLBACK:
			transactionStatus = TransactionStatus.MARKED_ROLLBACK;
			break;
		default:
			break;
	}
	if ( transactionStatus == null ) {
		throw new TransactionException( "TransactionManager reported transaction status as unknwon" );
	}
	return transactionStatus;
}
 
Example 13
Source File: TxUtils.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Converts a transaction status to a text representation
 * 
 * @param status The status index
 * @return status as String or "STATUS_INVALID(value)"
 * @see javax.transaction.Status
 */
public static String getStatusAsString(int status)
{
   if (status >= Status.STATUS_ACTIVE && status <= Status.STATUS_ROLLING_BACK)
   {
      return TX_STATUS_STRINGS[status];
   }
   else
   {
      return "STATUS_INVALID(" + status + ")";
   }
}
 
Example 14
Source File: TransactionUtil.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public static String getTransactionStateString(int state) {
    /*
     * 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 + ")";
    }
}
 
Example 15
Source File: TransactionImpl.java    From clearpool with GNU General Public License v3.0 5 votes vote down vote up
private void tryRollback() throws SystemException {
  this.status = Status.STATUS_ROLLING_BACK;
  StringBuilder error = new StringBuilder();
  for (ResourceCarry carry : this.resList) {
    try {
      carry.xaRes.rollback(carry.xid);
    } catch (XAException e) {
      LOGGER.error("rollback error: ", e);
      try {
        carry.xaRes.forget(carry.xid);
      } catch (XAException ex) {
        error.append("can't roll back XAException: ");
        error.append(ex);
        error.append(" (error code = ");
        error.append(ex.errorCode);
        error.append(") ");
        error.append(ex.getMessage());
        error.append("\n");
      }
    }
  }
  this.status = Status.STATUS_ROLLEDBACK;
  if (error.length() > 0) {
    error.deleteCharAt(error.length() - 1);
    throw new SystemException(error.toString());
  }
}
 
Example 16
Source File: AbstractLuceneIndexerImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Commit this index
 * 
 * @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;
    }
}
 
Example 17
Source File: LazyUserTransaction.java    From lastaflute with Apache License 2.0 4 votes vote down vote up
protected static String buildLazyTxExp() {
    final int status;
    try {
        final TransactionManager manager = ContainerUtil.getComponent(TransactionManager.class); // for static use
        status = manager.getStatus();
    } catch (SystemException e) {
        throw new IllegalStateException("Failed to get status from transaction manager.", e);
    }
    final String statusExp;
    if (status == Status.STATUS_ACTIVE) {
        statusExp = "Active";
    } else if (status == Status.STATUS_MARKED_ROLLBACK) {
        statusExp = "MarkedRollback";
    } else if (status == Status.STATUS_PREPARED) {
        statusExp = "Prepared";
    } else if (status == Status.STATUS_COMMITTED) {
        statusExp = "Committed";
    } else if (status == Status.STATUS_ROLLEDBACK) {
        statusExp = "RolledBack";
    } else if (status == Status.STATUS_UNKNOWN) {
        statusExp = "Unknown";
    } else if (status == Status.STATUS_NO_TRANSACTION) {
        statusExp = "NoTransaction";
    } else if (status == Status.STATUS_PREPARING) {
        statusExp = "Preparing";
    } else if (status == Status.STATUS_COMMITTING) {
        statusExp = "Committing";
    } else if (status == Status.STATUS_ROLLING_BACK) {
        statusExp = "RollingBack";
    } else {
        statusExp = String.valueOf(status);
    }
    final StringBuilder sb = new StringBuilder();
    sb.append("[").append(statusExp).append("]");
    boolean secondOrMore = false;
    if (isLazyTransactionReadyLazy()) {
        sb.append(secondOrMore ? ", " : "").append("readyLazy");
        secondOrMore = true;
    }
    if (isLazyTransactionLazyBegun()) {
        sb.append(secondOrMore ? ", " : "").append("lazyBegun");
        secondOrMore = true;
    }
    if (isLazyTransactionRealBegun()) {
        sb.append(secondOrMore ? ", " : "").append("realBegun");
        secondOrMore = true;
    }
    final Integer hierarchyLevel = getCurrentHierarchyLevel();
    if (hierarchyLevel != null) {
        sb.append(secondOrMore ? ", " : "").append("hierarchy=").append(hierarchyLevel);
        secondOrMore = true;
    }
    final List<IndependentProcessor> lazyProcessList = getLazyProcessList();
    if (!lazyProcessList.isEmpty()) {
        sb.append(secondOrMore ? ", " : "").append("lazyProcesses=").append(lazyProcessList.size());
        secondOrMore = true;
    }
    final ForcedlyBegunResumer resumer = getForcedlyBegunResumer();
    if (resumer != null) {
        sb.append(secondOrMore ? ", " : "").append("resumer=").append(DfTypeUtil.toClassTitle(resumer));
        secondOrMore = true;
    }
    return sb.toString();
}
 
Example 18
Source File: MultiThreadedTx.java    From reladomo with Apache License 2.0 4 votes vote down vote up
@Override
public int getStatus(MultiThreadedTx tx)
{
    return Status.STATUS_ROLLING_BACK;
}
 
Example 19
Source File: AlfrescoTxDiskDriver.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
     * End an active transaction
     * 
     * @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();
          }
        }
    }
 
Example 20
Source File: JTAHelper.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static boolean isRollback(int status) {
	return status==Status.STATUS_MARKED_ROLLBACK ||
	       status==Status.STATUS_ROLLING_BACK ||
	       status==Status.STATUS_ROLLEDBACK;
}