Java Code Examples for javax.transaction.Status#STATUS_UNKNOWN

The following examples show how to use javax.transaction.Status#STATUS_UNKNOWN . 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: TransactionImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 6 votes vote down vote up
public synchronized void participantRollback() throws IllegalStateException, RollbackRequiredException, SystemException {

		if (this.transactionStatus == Status.STATUS_UNKNOWN) {
			throw new IllegalStateException();
		} else if (this.transactionStatus == Status.STATUS_NO_TRANSACTION) {
			throw new IllegalStateException();
		} else if (this.transactionStatus == Status.STATUS_COMMITTED) {
			throw new IllegalStateException();
		} else if (this.transactionStatus == Status.STATUS_ROLLEDBACK) {
			return;
		}

		if (this.transactionContext.isRecoveried()) {
			this.recover(); // Execute recoveryInit if transaction is recovered from tx-log.
			this.invokeParticipantRollback();
		} else {
			this.invokeParticipantRollback();
		}

	}
 
Example 2
Source File: JTATransaction.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public boolean wasCommitted() throws TransactionException {

		//if (!begun || commitFailed) return false;

		final int status;
		try {
			status = ut.getStatus();
		}
		catch (SystemException se) {
			log.error("Could not determine transaction status", se);
			throw new TransactionException("Could not determine transaction status: ", se);
		}
		if (status==Status.STATUS_UNKNOWN) {
			throw new TransactionException("Could not determine transaction status");
		}
		else {
			return status==Status.STATUS_COMMITTED;
		}
	}
 
Example 3
Source File: CMTTransaction.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public boolean wasRolledBack() throws TransactionException {

		if (!begun) return false;

		final int status;
		try {
			status = getTransaction().getStatus();
		}
		catch (SystemException se) {
			log.error("Could not determine transaction status", se);
			throw new TransactionException("Could not determine transaction status", se);
		}
		if (status==Status.STATUS_UNKNOWN) {
			throw new TransactionException("Could not determine transaction status");
		}
		else {
			return JTAHelper.isRollback(status);
		}
	}
 
Example 4
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 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: TransactionSynchronizationRegistryImpl.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@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 7
Source File: JtaTransactionCoordinatorImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
	public void afterCompletion(boolean successful, boolean delayed) {
		if ( !transactionCoordinatorOwner.isActive() ) {
			return;
		}

		final int statusToSend =  successful ? Status.STATUS_COMMITTED : Status.STATUS_UNKNOWN;
		synchronizationRegistry.notifySynchronizationsAfterTransactionCompletion( statusToSend );

//		afterCompletionAction.doAction( this, statusToSend );

		transactionCoordinatorOwner.afterTransactionCompletion( successful, delayed );

		for ( TransactionObserver observer : observers() ) {
			observer.afterCompletion( successful, delayed );
		}

		synchronizationRegistered = false;
	}
 
Example 8
Source File: TransactionImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public synchronized void rollback() throws IllegalStateException, RollbackRequiredException, SystemException {
	if (this.transactionStatus == Status.STATUS_UNKNOWN) {
		throw new IllegalStateException();
	} else if (this.transactionStatus == Status.STATUS_NO_TRANSACTION) {
		throw new IllegalStateException();
	} else if (this.transactionStatus == Status.STATUS_COMMITTED) /* should never happen */ {
		throw new IllegalStateException();
	} else if (this.transactionStatus == Status.STATUS_ROLLEDBACK) /* should never happen */ {
		logger.debug("Current transaction has already been rolled back.");
	} else {
		this.fireRollback();
	}
}
 
Example 9
Source File: JtaStatusHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Extract the status code from the current {@link javax.transaction.Transaction} associated with the
 * given {@link TransactionManager}
 *
 * @param transactionManager The {@link TransactionManager} from which to extract the status.
 *
 * @return The transaction status
 *
 * @throws TransactionException If the {@link TransactionManager} reports the status as unknown
 */
public static int getStatus(TransactionManager transactionManager) {
	try {
		final int status = transactionManager.getStatus();
		if ( status == Status.STATUS_UNKNOWN ) {
			throw new TransactionException( "TransactionManager reported transaction status as unknwon" );
		}
		return status;
	}
	catch ( SystemException se ) {
		throw new TransactionException( "Could not determine transaction status", se );
	}
}
 
Example 10
Source File: JtaStatusHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Extract the status code from a {@link UserTransaction}
 *
 * @param userTransaction The {@link UserTransaction} from which to extract the status.
 *
 * @return The transaction status
 *
 * @throws TransactionException If the {@link UserTransaction} reports the status as unknown
 */
public static int getStatus(UserTransaction userTransaction) {
	try {
		final int status = userTransaction.getStatus();
		if ( status == Status.STATUS_UNKNOWN ) {
			throw new TransactionException( "UserTransaction reported transaction status as unknown" );
		}
		return status;
	}
	catch ( SystemException se ) {
		throw new TransactionException( "Could not determine transaction status", se );
	}
}
 
Example 11
Source File: JdbcResourceLocalTransactionCoordinatorImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void afterCompletionCallback(boolean successful) {
	log.tracef( "ResourceLocalTransactionCoordinatorImpl#afterCompletionCallback(%s)", successful );
	final int statusToSend = successful ? Status.STATUS_COMMITTED : Status.STATUS_UNKNOWN;
	synchronizationRegistry.notifySynchronizationsAfterTransactionCompletion( statusToSend );

	transactionCoordinatorOwner.afterTransactionCompletion( successful, false );
	for ( TransactionObserver observer : observers() ) {
		observer.afterCompletion( successful, false );
	}
}
 
Example 12
Source File: DummyTransaction.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void rollback() throws IllegalStateException, SystemException {

		status = Status.STATUS_ROLLING_BACK;

// Synch.beforeCompletion() should *not* be called for rollbacks
//		for ( int i=0; i<synchronizations.size(); i++ ) {
//			Synchronization s = (Synchronization) synchronizations.get(i);
//			s.beforeCompletion();
//		}
		
		status = Status.STATUS_ROLLEDBACK;
		
		try {
			connection.rollback();
			connection.close();
		}
		catch (SQLException sqle) {
			status = Status.STATUS_UNKNOWN;
			throw new SystemException();
		}
		
		for ( int i=0; i<synchronizations.size(); i++ ) {
			Synchronization s = (Synchronization) synchronizations.get(i);
			s.afterCompletion(status);
		}
		
		//status = Status.STATUS_NO_TRANSACTION;
		transactionManager.endCurrent(this);
	}
 
Example 13
Source File: TransactionImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get rollback only
 * @return The value
 */
boolean getRollbackOnly()
{
   if (status == Status.STATUS_UNKNOWN)
      throw new IllegalStateException("Status unknown");

   return status == Status.STATUS_MARKED_ROLLBACK;
}
 
Example 14
Source File: TransactionImpl.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void rollback() throws IllegalStateException,
                              SystemException
{
   if (status == Status.STATUS_UNKNOWN)
      throw new IllegalStateException("Status unknown");

   finish(false);
}
 
Example 15
Source File: TransactionImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void registerSynchronization(Synchronization sync) throws RollbackException,
                                                                 IllegalStateException,
                                                                 SystemException
{
   if (status == Status.STATUS_UNKNOWN)
      throw new IllegalStateException("Status unknown");

   syncs.add(sync);
}
 
Example 16
Source File: TransactionImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean delistResource(XAResource xaRes, int flag) throws IllegalStateException,
                                                                 SystemException
{
   if (status == Status.STATUS_UNKNOWN)
      throw new IllegalStateException("Status unknown");

   if (status != Status.STATUS_ACTIVE && status != Status.STATUS_MARKED_ROLLBACK)
      throw new IllegalStateException("Status not valid");

   return true;
}
 
Example 17
Source File: TransactionImpl.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean enlistResource(XAResource xaRes) throws RollbackException,
                                                       IllegalStateException,
                                                       SystemException
{
   if (status == Status.STATUS_UNKNOWN)
      throw new IllegalStateException("Status unknown");

   return true;
}
 
Example 18
Source File: TransactionImpl.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get rollback only
 * @return The value
 */
boolean getRollbackOnly()
{
   if (status == Status.STATUS_UNKNOWN)
      throw new IllegalStateException("Status unknown");

   return status == Status.STATUS_MARKED_ROLLBACK;
}
 
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: NoJtaPlatform.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getCurrentStatus() throws SystemException {
	return Status.STATUS_UNKNOWN;
}