Java Code Examples for javax.transaction.Status#STATUS_PREPARING

The following examples show how to use javax.transaction.Status#STATUS_PREPARING . 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: TransactionContext.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * The transaction scoped context is active when a transaction is active.
 */
@Override
public boolean isActive() {
    Transaction transaction = getCurrentTransaction();
    if (transaction == null) {
        return false;
    }

    try {
        int currentStatus = transaction.getStatus();
        return currentStatus == Status.STATUS_ACTIVE ||
                currentStatus == Status.STATUS_MARKED_ROLLBACK ||
                currentStatus == Status.STATUS_PREPARED ||
                currentStatus == Status.STATUS_UNKNOWN ||
                currentStatus == Status.STATUS_PREPARING ||
                currentStatus == Status.STATUS_COMMITTING ||
                currentStatus == Status.STATUS_ROLLING_BACK;
    } catch (SystemException e) {
        throw new RuntimeException("Error getting the status of the current transaction", e);
    }
}
 
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: 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 4
Source File: TransactionRecoveryImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected 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();
		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.");
	}
}
 
Example 5
Source File: ActiveMQRAManagedConnection.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void checkTransactionActive() throws JMSException {
   // don't bother looking at the transaction if there's an active XID
   if (!inManagedTx && tm != null) {
      try {
         Transaction tx = tm.getTransaction();
         if (tx != null) {
            int status = tx.getStatus();
            // Only allow states that will actually succeed
            if (status != Status.STATUS_ACTIVE && status != Status.STATUS_PREPARING && status != Status.STATUS_PREPARED && status != Status.STATUS_COMMITTING) {
               throw new javax.jms.IllegalStateException("Transaction " + tx + " not active");
            }
         }
      } catch (SystemException e) {
         JMSException jmsE = new javax.jms.IllegalStateException("Unexpected exception on the Transaction ManagerTransaction");
         jmsE.initCause(e);
         throw jmsE;
      }
   }
}
 
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: TransactionScopedEntityManager.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private boolean isInTransaction() {
    try {
        switch (transactionManager.getStatus()) {
            case Status.STATUS_ACTIVE:
            case Status.STATUS_COMMITTING:
            case Status.STATUS_MARKED_ROLLBACK:
            case Status.STATUS_PREPARED:
            case Status.STATUS_PREPARING:
                return true;
            default:
                return false;
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 8
Source File: TransactionImpl.java    From clearpool with GNU General Public License v3.0 5 votes vote down vote up
private boolean tryPrepared() {
  this.status = Status.STATUS_PREPARING;
  boolean preparedSuccess = true;
  for (ResourceCarry carry : this.resList) {
    try {
      int result = carry.xaRes.prepare(carry.xid);
      preparedSuccess &= result == XAResource.XA_OK;
    } catch (XAException e) {
      LOGGER.error("prepare XA error(code=" + e.errorCode + "): ", e);
      preparedSuccess = false;
    }
  }
  this.status = Status.STATUS_PREPARED;
  return preparedSuccess;
}
 
Example 9
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 10
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 11
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 12
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 13
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 14
Source File: AbstractLuceneIndexerImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Utility method to report errors about invalid state.
 * 
 * @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();
}
 
Example 15
Source File: JackRabbitUserTransaction.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @see javax.transaction.UserTransaction#commit
 */
@Override
public void commit() throws IllegalStateException, RollbackException, SecurityException, SystemException {

    if (status != Status.STATUS_ACTIVE) {
        throw new IllegalStateException("Transaction not active");
    }

    try {
        xares.end(xid, XAResource.TMSUCCESS);

        status = Status.STATUS_PREPARING;
        xares.prepare(xid);
        status = Status.STATUS_PREPARED;

        status = Status.STATUS_COMMITTING;
        xares.commit(xid, false);
        status = Status.STATUS_COMMITTED;

    } catch (XAException e) {

        if (e.errorCode >= XAException.XA_RBBASE && e.errorCode <= XAException.XA_RBEND) {
            RollbackException rollbackException = new RollbackException(e.toString());
            rollbackException.initCause(e);
            throw rollbackException;
        }

        final SystemException systemException = new SystemException("Unable to commit transaction: " + "XA_ERR="
                + e.errorCode);
        systemException.initCause(e);
        throw systemException;
    }
}
 
Example 16
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_PREPARING;
}
 
Example 17
Source File: MithraManager.java    From reladomo with Apache License 2.0 4 votes vote down vote up
private boolean isStatusActive(int status)
{
    return status == Status.STATUS_ACTIVE       || status == Status.STATUS_COMMITTING  ||
           status == Status.STATUS_PREPARED     || status == Status.STATUS_PREPARING   ||
           status == Status.STATUS_ROLLING_BACK || status == Status.STATUS_MARKED_ROLLBACK;
}
 
Example 18
Source File: TransactionRecoveryImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void recoverCoordinator(Transaction transaction)
		throws CommitRequiredException, RollbackRequiredException, SystemException {
	CompensableManager compensableManager = this.beanFactory.getCompensableManager();
	TransactionLock compensableLock = this.beanFactory.getCompensableLock();

	org.bytesoft.transaction.TransactionContext transactionContext = transaction.getTransactionContext();
	TransactionXid xid = transactionContext.getXid();

	boolean forgetRequired = false;
	boolean locked = false;
	try {
		compensableManager.associateThread(transaction);

		switch (transaction.getTransactionStatus()) {
		case Status.STATUS_ACTIVE:
		case Status.STATUS_MARKED_ROLLBACK:
		case Status.STATUS_PREPARING:
		case Status.STATUS_UNKNOWN: /* TODO */ {
			if (transactionContext.isPropagated() == false) {
				if ((locked = compensableLock.lockTransaction(xid, this.endpoint)) == false) {
					throw new SystemException(XAException.XAER_PROTO);
				}

				transaction.recoveryRollback();
				forgetRequired = true;
			}
			break;
		}
		case Status.STATUS_ROLLING_BACK: {
			if ((locked = compensableLock.lockTransaction(xid, this.endpoint)) == false) {
				throw new SystemException(XAException.XAER_PROTO);
			}

			transaction.recoveryRollback();
			forgetRequired = true;
			break;
		}
		case Status.STATUS_PREPARED:
		case Status.STATUS_COMMITTING: {
			if ((locked = compensableLock.lockTransaction(xid, this.endpoint)) == false) {
				throw new SystemException(XAException.XAER_PROTO);
			}

			transaction.recoveryCommit();
			forgetRequired = true;
			break;
		}
		case Status.STATUS_COMMITTED:
		case Status.STATUS_ROLLEDBACK:
			forgetRequired = true;
			break;
		default: // ignore
		}
	} finally {
		compensableManager.desociateThread();
		if (locked) {
			compensableLock.unlockTransaction(xid, this.endpoint);
		} // end-if (locked)
		if (forgetRequired) {
			transaction.forgetQuietly(); // forget transaction
		} // end-if (forgetRequired)
	}

}
 
Example 19
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 20
Source File: BeanManagedUserTransactionStrategy.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
protected boolean isTransactionReadyToCommit() throws SystemException
{
    return getTransactionStatus() == Status.STATUS_ACTIVE ||
            getTransactionStatus() == Status.STATUS_PREPARING ||
            getTransactionStatus() == Status.STATUS_PREPARED;
}