Java Code Examples for javax.transaction.Status#STATUS_MARKED_ROLLBACK

The following examples show how to use javax.transaction.Status#STATUS_MARKED_ROLLBACK . 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: JackRabbitUserTransaction.java    From mycollab with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * @see javax.transaction.UserTransaction#rollback
 */
@Override
public void rollback() throws IllegalStateException, SecurityException, SystemException {

    if (status != Status.STATUS_ACTIVE && status != Status.STATUS_MARKED_ROLLBACK) {

        throw new IllegalStateException("Transaction not active");
    }

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

        status = Status.STATUS_ROLLING_BACK;
        xares.rollback(xid);
        status = Status.STATUS_ROLLEDBACK;

    } catch (XAException e) {
        final SystemException systemException = new SystemException("Unable to commit transaction: " + "XA_ERR="
                + e.errorCode);
        systemException.initCause(e);
        throw systemException;
    }
}
 
Example 2
Source File: GlobalTransactionTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void testSetRollbackOnly() {
  try {
    utx.begin();
    utx.setRollbackOnly();
    Transaction txn = tm.getTransaction();
    if (txn.getStatus() != Status.STATUS_MARKED_ROLLBACK) {
      utx.rollback();
      fail("testSetRollbackonly failed");
    }
    utx.rollback();
  }
  catch (Exception e) {
    fail("exception in testSetRollbackonly due to " + e);
    e.printStackTrace();
  }
}
 
Example 3
Source File: TransactionImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 6 votes vote down vote up
public synchronized void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
		SecurityException, IllegalStateException, CommitRequiredException, SystemException {

	if (this.transactionStatus == Status.STATUS_ACTIVE) {
		this.fireCommit();
	} else if (this.transactionStatus == Status.STATUS_MARKED_ROLLBACK) {
		this.fireRollback();
		throw new HeuristicRollbackException();
	} else if (this.transactionStatus == Status.STATUS_ROLLEDBACK) /* should never happen */ {
		throw new RollbackException();
	} else if (this.transactionStatus == Status.STATUS_COMMITTED) /* should never happen */ {
		logger.debug("Current transaction has already been committed.");
	} else {
		throw new IllegalStateException();
	}

}
 
Example 4
Source File: TransactionManagerImpl.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_ROLLEDBACK ||
       tx.getStatus() == Status.STATUS_MARKED_ROLLBACK)
      throw new RollbackException();

   registry.commitTransaction();
}
 
Example 5
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 6
Source File: ManagedBeanTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
private boolean inTransaction() {
    try {
        final TransactionManager transactionManager = SystemInstance.get().getComponent(TransactionManager.class);
        final int status = transactionManager.getStatus();
        return status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK;
    } catch (final SystemException e) {
        throw new RuntimeException(e);
    }
}
 
Example 7
Source File: AuthenticationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void tearDown() throws Exception
{
    if ((userTransaction.getStatus() == Status.STATUS_ACTIVE) || (userTransaction.getStatus() == Status.STATUS_MARKED_ROLLBACK))
    {
        userTransaction.rollback();
    }
    AuthenticationUtil.clearCurrentSecurityContext();
    super.tearDown();
}
 
Example 8
Source File: TransactionContext.java    From tomee 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 9
Source File: ManagedTransaction.java    From requery with Apache License 2.0 5 votes vote down vote up
@Override
public void afterCompletion(int status) {
    switch (status) {
        case Status.STATUS_ROLLEDBACK:
        case Status.STATUS_MARKED_ROLLBACK:
        case Status.STATUS_ROLLING_BACK:
            rollback();
            close();
            break;
    }
    completed = true;
}
 
Example 10
Source File: CompensableTransactionImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
public synchronized void setRollbackOnly() throws IllegalStateException, SystemException {
	if (this.transactionContext.isCompensating()) {
		this.setTransactionRollbackOnlyQuietly();
	} else if (this.transactionStatus == Status.STATUS_ACTIVE) {
		this.transactionStatus = Status.STATUS_MARKED_ROLLBACK;
		this.setTransactionRollbackOnlyQuietly();
		this.transactionContext.setRollbackOnly(true);
	} else if (this.transactionStatus == Status.STATUS_MARKED_ROLLBACK) {
		this.setTransactionRollbackOnlyQuietly();
		this.transactionContext.setRollbackOnly(true);
	} else {
		this.setTransactionRollbackOnlyQuietly();
	}
}
 
Example 11
Source File: UserTransactionWrapper.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getRollbackOnly() {
    try {
        return ut.getStatus() == Status.STATUS_MARKED_ROLLBACK;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 12
Source File: MockTransactionManagerService.java    From incubator-batchee with Apache License 2.0 5 votes vote down vote up
@Override
public void rollback()
{
    switch (txStatus) {
        case Status.STATUS_ACTIVE:
            txStatus = Status.STATUS_ROLLEDBACK;
            break;
        case Status.STATUS_ROLLEDBACK:
        case Status.STATUS_MARKED_ROLLBACK:
            break;
        default :
            throw new TransactionManagementException(new IllegalStateException("no mock-tx on current thread"));
    }
}
 
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 registerSynchronization(Synchronization sync)
		throws RollbackException, IllegalStateException, SystemException {

	if (this.transactionStatus == Status.STATUS_MARKED_ROLLBACK) {
		throw new RollbackException();
	} else if (this.transactionStatus == Status.STATUS_ACTIVE) {
		this.synchronizationList.registerSynchronizationQuietly(sync);
		logger.debug("{}> register-sync: sync= {}"//
				, ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), sync);
	} else {
		throw new IllegalStateException();
	}

}
 
Example 14
Source File: TransactionalInterceptorBase.java    From quarkus with Apache License 2.0 5 votes vote down vote up
protected void endTransaction(TransactionManager tm, Transaction tx, RunnableWithException afterEndTransaction)
        throws Exception {
    if (tx != tm.getTransaction()) {
        throw new RuntimeException(jtaLogger.i18NLogger.get_wrong_tx_on_thread());
    }

    if (tx.getStatus() == Status.STATUS_MARKED_ROLLBACK) {
        tm.rollback();
    } else {
        tm.commit();
    }

    afterEndTransaction.run();
}
 
Example 15
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 16
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 17
Source File: DeleteMethodTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
@After
public void tearDown() throws Exception
{
    method = null;
    request = null;
    response = null;

    if (txn.getStatus() == Status.STATUS_MARKED_ROLLBACK)
    {
        txn.rollback();
    }
    else
    {
        txn.commit();
    }
    
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
 
    nodeService.deleteNode(versionableDoc);

    // As per MNT-10037 try to create a node and delete it in the next txn
    txn = transactionService.getUserTransaction();
    txn.begin();

    Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
    String nodeName = "leak-session-doc-" + GUID.generate();
    properties.put(ContentModel.PROP_NAME, nodeName);

    NodeRef nodeRef = nodeService.createNode(companyHomeNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(ContentModel.USER_MODEL_URI, nodeName),
            ContentModel.TYPE_CONTENT, properties).getChildRef();
    contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true).putContent("WebDAVTestContent");

    txn.commit();

    txn = transactionService.getUserTransaction();
    txn.begin();

    nodeService.deleteNode(nodeRef);

    txn.commit();

    AuthenticationUtil.clearCurrentSecurityContext();
}
 
Example 18
Source File: TransactionInvocationHandlersTest.java    From development with Apache License 2.0 4 votes vote down vote up
@Override
public void setRollbackOnly() {
    status = Status.STATUS_MARKED_ROLLBACK;
    stubCalls.add("setRollbackOnly()");
}
 
Example 19
Source File: DummyTransaction.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void setRollbackOnly() throws IllegalStateException, SystemException {
	status = Status.STATUS_MARKED_ROLLBACK;
}
 
Example 20
Source File: SessionFactoryUtils.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Register a JTA synchronization for the given Session, if any.
 * @param sessionHolder the existing thread-bound SessionHolder, if any
 * @param session the Session to register
 * @param sessionFactory the SessionFactory that the Session was created with
 * @param jdbcExceptionTranslator SQLExcepionTranslator to use for flushing the
 * Session on transaction synchronization (may be {@code null})
 */
private static void registerJtaSynchronization(Session session, SessionFactory sessionFactory,
		SQLExceptionTranslator jdbcExceptionTranslator, 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(sessionFactory, session);
	if (jtaTm != null) {
		try {
			Transaction jtaTx = jtaTm.getTransaction();
			if (jtaTx != null) {
				int jtaStatus = jtaTx.getStatus();
				if (jtaStatus == Status.STATUS_ACTIVE || jtaStatus == Status.STATUS_MARKED_ROLLBACK) {
					logger.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(jtaTx, session);
					}
					else {
						holderToUse.addSession(jtaTx, session);
					}
					jtaTx.registerSynchronization(
							new SpringJtaSynchronizationAdapter(
									new SpringSessionSynchronization(holderToUse, sessionFactory, jdbcExceptionTranslator, true),
									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);
		}
	}
}