Java Code Examples for javax.transaction.Status#STATUS_COMMITTED

The following examples show how to use javax.transaction.Status#STATUS_COMMITTED . 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: MemoryTimerStore.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public void afterCompletion(final int status) {
    checkThread();

    // if the tx was not committed, there is nothign to update
    if (status != Status.STATUS_COMMITTED) {
        return;
    }

    // add the new work
    taskStore.putAll(add);

    // remove work
    taskStore.keySet().removeAll(remove);

    tasksByTransaction.remove(tansactionReference.get());
}
 
Example 2
Source File: TransactionRecoveryImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void recoverParticipant(Transaction transaction)
		throws CommitRequiredException, RollbackRequiredException, SystemException {
	CompensableManager compensableManager = this.beanFactory.getCompensableManager();

	try {
		compensableManager.associateThread(transaction);

		switch (transaction.getTransactionStatus()) {
		case Status.STATUS_COMMITTED:
		case Status.STATUS_ROLLEDBACK:
			transaction.forgetQuietly();
			break;
		default: // ignore
		}
	} finally {
		compensableManager.desociateThread();
	}

}
 
Example 3
Source File: TransactionImpl.java    From clearpool with GNU General Public License v3.0 6 votes vote down vote up
private void tryCommit() throws HeuristicMixedException, SystemException {
  this.status = Status.STATUS_COMMITTING;
  ResourceCarry carryTemp = null;
  Iterator<ResourceCarry> itr = this.resList.iterator();
  while (itr.hasNext()) {
    ResourceCarry carry = itr.next();
    this.beforeCompletion();
    try {
      carry.xaRes.commit(carry.xid, false);
    } catch (XAException e) {
      LOGGER.error("commit XA error(code=" + e.errorCode + "): ", e);
      carryTemp = carry;
      break;
    }
    this.afterCompletion(Status.STATUS_COMMITTED);
  }
  if (carryTemp == null) {
    this.status = Status.STATUS_COMMITTED;
    return;
  }
  this.rollbackMixed(carryTemp, itr);
}
 
Example 4
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 5
Source File: CompensableTransactionImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
public synchronized void rollback() throws IllegalStateException, 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 6
Source File: JtaTransactionInterceptor.java    From snakerflow with Apache License 2.0 5 votes vote down vote up
protected TransactionStatus getTransaction() {
	UserTransaction userTransaction = JtaTransactionHelper
			.lookupJeeUserTransaction();
	int status = JtaTransactionHelper
			.getUserTransactionStatus(userTransaction);
   	if(log.isInfoEnabled()) {
   		log.info("begin transaction=" + status);
   	}
	if (status == Status.STATUS_ACTIVE) {
		return new TransactionStatus(null, false);
	}

	if ((status != Status.STATUS_NO_TRANSACTION)
			&& (status != Status.STATUS_COMMITTED)
			&& (status != Status.STATUS_ROLLEDBACK)) {
		throw new SnakerException("无效的事务状态:" + status);
	}

	Transaction suspendedTransaction = null;
	if ((status == Status.STATUS_ACTIVE)
			|| (status == Status.STATUS_COMMITTED)
			|| (status == Status.STATUS_ROLLEDBACK)) {
		suspendedTransaction = JtaTransactionHelper.suspend();
	}

	try {
		JtaTransactionHelper.begin();
		return new TransactionStatus(null, true);
	} catch (RuntimeException e) {
		throw e;
	} finally {
		if (suspendedTransaction != null) {
			JtaTransactionHelper.resume(suspendedTransaction);
		}
	}
}
 
Example 7
Source File: DeleteAllInBatchesTransactionalCommand.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void afterCompletion(int status)
{
    if (status != Status.STATUS_COMMITTED)
    {
        batchSize[0] /= 2;
    }
}
 
Example 8
Source File: TXStateProxy.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public final void afterCompletion(int status) {
  // System.err.println("start afterCompletion");
  final long opStart = CachePerfStats.getStatTime();
  final long lifeTime;
  switch (status) {
    case Status.STATUS_COMMITTED:
      // System.err.println("begin commit in afterCompletion");
      try {
        this.txManager.clearTXState();
        // commit phase1 already done in beforeCompletion()
        TXManagerImpl.TXContext context = TXManagerImpl.currentTXContext();
        if (context != null) {
          // always wait for commit replies JTA transactions
          context.setWaitForPhase2Commit();
          commitPhase2(context, null);
        }
      } catch (TransactionInDoubtException error) {
        Assert.fail("Gemfire Transaction " + getTransactionId()
            + " afterCompletion failed due to TransactionInDoubtException: "
            + error);
      }
      lifeTime = opStart - getBeginTime();
      this.txManager.noteCommitSuccess(opStart, lifeTime, this, false);
      break;
    case Status.STATUS_ROLLEDBACK:
      this.txManager.clearTXState();
      rollback(null);
      lifeTime = opStart - getBeginTime();
      this.txManager.noteRollbackSuccess(opStart, lifeTime, this, false);
      break;
    default:
      Assert.fail("Unknown JTA Synchronization status " + status);
  }
}
 
Example 9
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 10
Source File: TransactionManagerImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void rollback() throws IllegalStateException, SecurityException, SystemException {
	Transaction transaction = this.getTransactionQuietly(); // this.desociateThread();

	if (transaction == null) {
		throw new IllegalStateException();
	} else if (transaction.getTransactionStatus() == Status.STATUS_ROLLEDBACK) {
		this.desociateThread();
		return;
	} else if (transaction.getTransactionStatus() == Status.STATUS_COMMITTED) {
		this.desociateThread();
		throw new SystemException();
	}

	this.rollback(transaction);
}
 
Example 11
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 12
Source File: UserTransactionMock.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void commit() throws
        SecurityException, IllegalStateException {
    if (status != Status.STATUS_ACTIVE) {
        throw new IllegalStateException("Can only commit an active transaction");
    }
    status = Status.STATUS_COMMITTED;
}
 
Example 13
Source File: MockTransactionManagerService.java    From incubator-batchee with Apache License 2.0 5 votes vote down vote up
@Override
public void commit()
{
    switch (txStatus) {
        case Status.STATUS_ACTIVE:
            txStatus = Status.STATUS_COMMITTED;
            break;
        case Status.STATUS_ROLLEDBACK:
        case Status.STATUS_MARKED_ROLLBACK:
            throw new TransactionManagementException(new RollbackException());
        default :
            throw new TransactionManagementException(new IllegalStateException("no mock-tx on current thread"));
    }
}
 
Example 14
Source File: GetMethodRegressionTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@After
public void tearDown() throws Exception
{
    if ((null != transaction) && (Status.STATUS_ROLLEDBACK != transaction.getStatus()) && (Status.STATUS_COMMITTED != transaction.getStatus()))
    {
        transaction.rollback();
    }

    AuthenticationUtil.clearCurrentSecurityContext();
}
 
Example 15
Source File: CompensableTransactionImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
public synchronized void participantCommit(boolean opc) throws RollbackException, HeuristicMixedException,
		HeuristicRollbackException, SecurityException, IllegalStateException, CommitRequiredException, SystemException {

	// Recover if transaction is recovered from tx-log.
	this.recoverIfNecessary();

	if (this.transactionStatus != Status.STATUS_COMMITTED) {
		this.fireCommit(); // TODO
	}

}
 
Example 16
Source File: CacheUpdater.java    From FHIR with Apache License 2.0 5 votes vote down vote up
/**
  * Writes candidate cache entries to the appropriate cache after being notified by
  * the Trx Synchronization service that the transaction on the current thread 
  * has successfully committed.
  */
@Override
public void afterCompletion(int completionStatus) {
    final String METHODNAME = "afterCompletion";
    log.entering(CLASSNAME, METHODNAME);
    
    if (completionStatus == Status.STATUS_COMMITTED) {
        this.commitCacheCandidates();
    }
            
    this.clearCacheCandidates();
    
    log.exiting(CLASSNAME, METHODNAME);
}
 
Example 17
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 18
Source File: MdwTransactionManager.java    From mdw with Apache License 2.0 4 votes vote down vote up
@Override
public Transaction getTransaction() throws SystemException {
    if (transaction==null) return null;
    if (transaction.status==Status.STATUS_COMMITTED) return null;
    return transaction;
}
 
Example 19
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_COMMITTED;
}
 
Example 20
Source File: JtaStatusHelper.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Does the given status code indicate a committed transaction?
 *
 * @param status The transaction status code to check
 *
 * @return True if the code indicates a roll back; false otherwise.
 */
public static boolean isCommitted(int status) {
	return status == Status.STATUS_COMMITTED;
}