javax.transaction.HeuristicMixedException Java Examples

The following examples show how to use javax.transaction.HeuristicMixedException. 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: UserCompensableImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void compensableCommit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
		SecurityException, IllegalStateException, SystemException {
	CompensableManager tompensableManager = this.beanFactory.getCompensableManager();

	CompensableTransaction compensable = (CompensableTransaction) tompensableManager.getCompensableTransactionQuietly();
	if (compensable == null) {
		throw new IllegalStateException();
	}

	TransactionContext transactionContext = compensable.getTransactionContext();
	if (transactionContext.isCoordinator() == false) {
		throw new IllegalStateException();
	}

	this.invokeCompensableCommit(compensable);
}
 
Example #2
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 #3
Source File: DefaultTransaction.java    From piranha with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Commit the transaction.
 *
 * @throws RollbackException when a rollback error occurs.
 * @throws HeuristicMixedException when the heuristics were mixed.
 * @throws HeuristicRollbackException when a rollback error occurs.
 * @throws SecurityException when a security error occurs.
 * @throws IllegalStateException when the transaction is not active.
 * @throws SystemException when a serious error occurs.
 */
@Override
public synchronized void commit() throws RollbackException, HeuristicMixedException,
        HeuristicRollbackException, SecurityException,
        IllegalStateException, SystemException {
    handleBeforeCompletion();
    try {
        switch (status) {
            case Status.STATUS_COMMITTED:
                break;
            case Status.STATUS_MARKED_ROLLBACK: {
                rollback();
                throw new HeuristicRollbackException();
            }
            case Status.STATUS_ROLLEDBACK: {
                throw new RollbackException();
            }
            default: {
                status = Status.STATUS_COMMITTED;
            }
        }
    } finally {
        handleAfterCompletion();
    }
}
 
Example #4
Source File: JPAResource.java    From boost with Eclipse Public License 1.0 6 votes vote down vote up
public void createThing(StringBuilder builder)
        throws NamingException, NotSupportedException, SystemException, IllegalStateException, SecurityException,
        HeuristicMixedException, HeuristicRollbackException, RollbackException {
    Context ctx = new InitialContext();
    // Before getting an EntityManager, start a global transaction
    UserTransaction tran = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
    tran.begin();

    // Now get the EntityManager from JNDI
    EntityManager em = (EntityManager) ctx.lookup(JNDI_NAME);
    builder.append("Creating a brand new Thing with " + em.getDelegate().getClass()).append(newline);

    // Create a Thing object and persist it to the database
    Thing thing = new Thing();
    em.persist(thing);

    // Commit the transaction
    tran.commit();
    int id = thing.getId();
    builder.append("Created Thing " + id + ":  " + thing).append(newline);
}
 
Example #5
Source File: JPAResource.java    From boost with Eclipse Public License 1.0 6 votes vote down vote up
public void createThing(StringBuilder builder)
        throws NamingException, NotSupportedException, SystemException, IllegalStateException, SecurityException,
        HeuristicMixedException, HeuristicRollbackException, RollbackException {
    Context ctx = new InitialContext();
    // Before getting an EntityManager, start a global transaction
    UserTransaction tran = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
    tran.begin();

    // Now get the EntityManager from JNDI
    EntityManager em = (EntityManager) ctx.lookup(JNDI_NAME);
    builder.append("Creating a brand new Thing with " + em.getDelegate().getClass()).append(newline);

    // Create a Thing object and persist it to the database
    Thing thing = new Thing();
    em.persist(thing);

    // Commit the transaction
    tran.commit();
    int id = thing.getId();
    builder.append("Created Thing " + id + ":  " + thing).append(newline);
}
 
Example #6
Source File: ManagedTransaction.java    From requery with Apache License 2.0 6 votes vote down vote up
@Override
public void commit() {
    if (initiatedTransaction) {
        try {
            transactionListener.beforeCommit(entities.types());
            getUserTransaction().commit();
            transactionListener.afterCommit(entities.types());
        } catch (RollbackException | SystemException | HeuristicMixedException |
            HeuristicRollbackException e) {
            throw new TransactionException(e);
        }
    }
    try {
        entities.clear();
    } finally {
        close();
    }
}
 
Example #7
Source File: SimpleTransaction.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
        SecurityException, SystemException
{
    try
    {
        if (isRollBackOnly)
        {
            throw new RollbackException("Commit failed: Transaction marked for rollback");
        }

    }
    finally
    {
        transaction.set(null);
    }
}
 
Example #8
Source File: PeopleTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void createUsers() throws HeuristicRollbackException, RollbackException, HeuristicMixedException, SystemException, NotSupportedException
    {
        txn = transactionService.getUserTransaction();
        txn.begin();
        for (UserInfo user : userInfos)
        {
            String username = user.getUserName();
            NodeRef nodeRef = personService.getPersonOrNull(username);
            boolean create = nodeRef == null;
            if (create)
            {
                PropertyMap testUser = new PropertyMap();
                testUser.put(ContentModel.PROP_USERNAME, username);
                testUser.put(ContentModel.PROP_FIRSTNAME, user.getFirstName());
                testUser.put(ContentModel.PROP_LASTNAME, user.getLastName());
                testUser.put(ContentModel.PROP_EMAIL, user.getUserName() + "@acme.test");
                testUser.put(ContentModel.PROP_PASSWORD, "password");

                nodeRef = personService.createPerson(testUser);
            }
            userNodeRefs.add(nodeRef);
//            System.out.println((create ? "create" : "existing")+" user " + username + " nodeRef=" + nodeRef);
        }
        txn.commit();
    }
 
Example #9
Source File: JPAResource.java    From microprofile-sandbox with Apache License 2.0 6 votes vote down vote up
public void createThing(StringBuilder builder)
        throws NamingException, NotSupportedException, SystemException, IllegalStateException, SecurityException,
        HeuristicMixedException, HeuristicRollbackException, RollbackException {
    Context ctx = new InitialContext();
    // Before getting an EntityManager, start a global transaction
    UserTransaction tran = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
    tran.begin();

    // Now get the EntityManager from JNDI
    EntityManager em = (EntityManager) ctx.lookup(JNDI_NAME);
    builder.append("Creating a brand new Thing with " + em.getDelegate().getClass()).append(newline);

    // Create a Thing object and persist it to the database
    Thing thing = new Thing();
    em.persist(thing);

    // Commit the transaction
    tran.commit();
    int id = thing.getId();
    builder.append("Created Thing " + id + ":  " + thing).append(newline);
}
 
Example #10
Source File: JPAResource.java    From microprofile-sandbox with Apache License 2.0 6 votes vote down vote up
public void createThing(StringBuilder builder)
        throws NamingException, NotSupportedException, SystemException, IllegalStateException, SecurityException,
        HeuristicMixedException, HeuristicRollbackException, RollbackException {
    Context ctx = new InitialContext();
    // Before getting an EntityManager, start a global transaction
    UserTransaction tran = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
    tran.begin();

    // Now get the EntityManager from JNDI
    EntityManager em = (EntityManager) ctx.lookup(JNDI_NAME);
    builder.append("Creating a brand new Thing with " + em.getDelegate().getClass()).append(newline);

    // Create a Thing object and persist it to the database
    Thing thing = new Thing();
    em.persist(thing);

    // Commit the transaction
    tran.commit();
    int id = thing.getId();
    builder.append("Created Thing " + id + ":  " + thing).append(newline);
}
 
Example #11
Source File: SimpleTransactionStrategy.java    From ByteJTA with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void rollback(Xid xid)
		throws HeuristicMixedException, HeuristicCommitException, IllegalStateException, SystemException {
	try {
		this.terminator.rollback(xid);
	} catch (XAException xaex) {
		switch (xaex.errorCode) {
		case XAException.XA_HEURRB:
			break;
		case XAException.XA_HEURMIX:
			throw new HeuristicMixedException();
		case XAException.XA_HEURCOM:
			throw new HeuristicCommitException();
		default:
			logger.error("Unknown state in rollingback transaction phase.", xaex);
			throw new SystemException();
		}
	} catch (RuntimeException rex) {
		logger.error("Unknown state in rollingback transaction phase.", rex);
		throw new SystemException();
	}
}
 
Example #12
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 #13
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 #14
Source File: DumbTransactionFactory.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
public UserTransaction getUserTransaction() {
    return new UserTransaction() {
        public void begin() throws NotSupportedException, SystemException {
        }

        public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {
        }

        public int getStatus() throws SystemException {
            return TransactionUtil.STATUS_NO_TRANSACTION;
        }

        public void rollback() throws IllegalStateException, SecurityException, SystemException {
        }

        public void setRollbackOnly() throws IllegalStateException, SystemException {
        }

        public void setTransactionTimeout(int i) throws SystemException {
        }
    };
}
 
Example #15
Source File: LazyUserTransaction.java    From lastaflute with Apache License 2.0 6 votes vote down vote up
@Override
protected void doCommit() throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException, RollbackException,
        SecurityException, SystemException {
    if (canTerminateTransactionReally()) {
        if (logger.isDebugEnabled()) {
            logger.debug("#lazyTx ...Committing the transaction: {}", buildLazyTxExp());
        }
        superDoCommit();
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("#lazyTx *No commit because of non-begun transaction: {}", buildLazyTxExp());
        }
    }
    if (canLazyTransaction()) {
        decrementHierarchyLevel();
        resumeForcedlyBegunLazyTransactionIfNeeds(); // when nested transaction
    }
    if (isLazyTransactionReadyLazy() && isHerarchyLevelZero()) { // lazy transaction is supported only for root
        returnToReadyLazy();
    }
}
 
Example #16
Source File: CompensableTransactionImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 6 votes vote down vote up
public synchronized void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
		SecurityException, IllegalStateException, 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 #17
Source File: CompensableManagerImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void invokeTransactionCommitIfNotLocalTransaction(CompensableTransaction compensable) throws RollbackException,
		HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {

	Transaction transaction = compensable.getTransaction();
	org.bytesoft.transaction.TransactionContext transactionContext = transaction.getTransactionContext();
	TransactionParticipant transactionCoordinator = this.beanFactory.getTransactionNativeParticipant();

	TransactionXid transactionXid = transactionContext.getXid();
	try {
		transactionCoordinator.end(transactionContext, XAResource.TMSUCCESS);

		TransactionContext compensableContext = compensable.getTransactionContext();
		logger.error("{}> jta-transaction in try-phase cannot be xa transaction.",
				ByteUtils.byteArrayToString(compensableContext.getXid().getGlobalTransactionId()));

		transactionCoordinator.rollback(transactionXid);
		throw new HeuristicRollbackException();
	} catch (XAException xaEx) {
		transactionCoordinator.forgetQuietly(transactionXid);
		SystemException sysEx = new SystemException(xaEx.errorCode);
		sysEx.initCause(xaEx);
		throw sysEx;
	}
}
 
Example #18
Source File: UserCompensableImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void compensableRecoveryCommit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
		SecurityException, IllegalStateException, SystemException {
	CompensableManager compensableManager = this.beanFactory.getCompensableManager();
	CompensableTransaction compensable = compensableManager.getCompensableTransactionQuietly();
	if (compensable == null) {
		throw new IllegalStateException();
	}

	TransactionContext transactionContext = compensable.getTransactionContext();
	if (transactionContext.isCoordinator() == false) {
		throw new IllegalStateException();
	}
	this.invokeCompensableCommit(compensable);
}
 
Example #19
Source File: BulkImportTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void canVersionDocsWithoutSpecialInputFileNameExtension()
        throws HeuristicMixedException, IOException, SystemException,
        HeuristicRollbackException, NotSupportedException, RollbackException
{
    testCanVersionDocsWithoutSpecialInputFileNameExtension(file ->
        streamingNodeImporterFactory.getNodeImporter(resourceAsFile("classpath:bulkimport-autoversion/"+file)));
}
 
Example #20
Source File: CompensableManagerImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void invokeTransactionCommit(CompensableTransaction compensable) throws RollbackException,
		HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {
	Transaction transaction = compensable.getTransaction();
	boolean isLocalTransaction = transaction.isLocalTransaction();
	try {
		if (isLocalTransaction) {
			this.invokeTransactionCommitIfLocalTransaction(compensable);
		} else {
			this.invokeTransactionCommitIfNotLocalTransaction(compensable);
		}
	} finally {
		compensable.setTransactionalExtra(null);
	}
}
 
Example #21
Source File: CompensableManagerImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void invokeTransactionCommitIfNecessary(CompensableTransaction compensable) throws RollbackException,
		HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {
	// compensable.getTransaction().isMarkedRollbackOnly()
	if (compensable.getTransaction().getTransactionStatus() == Status.STATUS_MARKED_ROLLBACK) {
		this.invokeTransactionRollback(compensable);
		throw new HeuristicRollbackException();
	} else {
		this.invokeTransactionCommit(compensable);
	}
}
 
Example #22
Source File: DefaultUserTransaction.java    From piranha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Commit the transaction.
 *
 * @throws RollbackException when a roll back error occurs.
 * @throws HeuristicMixedException when heuristics are being mixed.
 * @throws HeuristicRollbackException when a rollback error occurs.
 * @throws SecurityException when a security error occurs.
 * @throws IllegalStateException when the transaction is not active.
 * @throws SystemException when a serious error occurs.
 */
@Override
public void commit() throws RollbackException, HeuristicMixedException,
        HeuristicRollbackException, SecurityException,
        IllegalStateException, SystemException {
    if (transactionManager.getTransaction() != null) {
        transactionManager.commit();
    } else {
        throw new IllegalStateException("Thread not associated with a transaction");
    }
}
 
Example #23
Source File: CompensableManagerImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException,
		IllegalStateException, SystemException {

	CompensableTransaction transaction = this.getCompensableTransactionQuietly();
	if (transaction == null) {
		throw new IllegalStateException();
	}
	TransactionContext transactionContext = transaction.getTransactionContext();
	boolean coordinator = transactionContext.isCoordinator();
	boolean propagated = transactionContext.isPropagated();
	boolean compensable = transactionContext.isCompensable();
	boolean compensating = transactionContext.isCompensating();
	int propagatedLevel = transactionContext.getPropagationLevel();

	if (compensable == false) {
		throw new IllegalStateException();
	} else if (compensating) {
		this.invokeTransactionCommitIfNecessary(transaction);
	} else if (coordinator) {
		if (propagated) {
			this.invokeTransactionCommitIfNecessary(transaction);
		} else if (propagatedLevel > 0) {
			this.invokeTransactionCommitIfNecessary(transaction);
		} else {
			throw new IllegalStateException();
		}
	} else {
		this.invokeTransactionCommitIfNecessary(transaction);
	}
}
 
Example #24
Source File: QueriesPeopleApiTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void createTestUsers() throws IllegalArgumentException, SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException, RollbackException
{
    AuthenticationUtil.setFullyAuthenticatedUser(user1);
    for (String[] properties: userProperties)
    {
        int l = properties.length;
        if (l > 0)
        {
            PersonInfo personInfo = newPersonInfo(properties);
            String originalUsername = personInfo.getUsername();
            String id = createUser(personInfo, networkOne);
            Person person = new Person(
                           id,
                           null, // Not set to originalUsername, as the returned JSON does not set it
                           true, // enabled
                personInfo.getFirstName(),
                personInfo.getLastName(),
                personInfo.getCompany(),
                personInfo.getSkype(),
                personInfo.getLocation(),
                personInfo.getTel(),
                personInfo.getMob(),
                personInfo.getInstantmsg(),
                personInfo.getGoogle(),
                           null); // description
            testUsernames.add(originalUsername);
            testPersons.add(person);

            // The following call to personService.getPerson(id) returns a NodeRef like:
            //    workspace://SpacesStore/9db76769-96de-4de4-bdb4-a127130af362
            // We call tenantService.getName(nodeRef) to get a fully qualified NodeRef as Solr returns this.
            // They look like:
            //    workspace://@org.alfresco.rest.api.tests.queriespeopleapitest@SpacesStore/9db76769-96de-4de4-bdb4-a127130af362
            NodeRef nodeRef = personService.getPerson(id);
            nodeRef = tenantService.getName(nodeRef);
            testPersonNodeRefs.add(nodeRef);
        }
    }
}
 
Example #25
Source File: TransactionImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void checkForTransactionExtraIfNecessary() throws RollbackException, HeuristicMixedException,
		HeuristicRollbackException, SecurityException, IllegalStateException, CommitRequiredException, SystemException {

	if (this.transactionalExtra != null) /* for ByteTCC */ {
		if (this.participantList.isEmpty() == false && this.participant == null) /* see initGetTransactionStrategy */ {
			this.participantRollback();
			throw new HeuristicRollbackException();
		} else if (this.participantList.size() > 1) {
			this.participantRollback();
			throw new HeuristicRollbackException();
		}
	} // end-if (this.transactionalExtra != null)

}
 
Example #26
Source File: DumbTransactionFactory.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public TransactionManager getTransactionManager() {
    return new TransactionManager() {
        public void begin() throws NotSupportedException, SystemException {
        }

        public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {
        }

        public int getStatus() throws SystemException {
            return TransactionUtil.STATUS_NO_TRANSACTION;
        }

        public Transaction getTransaction() throws SystemException {
            return null;
        }

        public void resume(Transaction transaction) throws InvalidTransactionException, IllegalStateException, SystemException {
        }

        public void rollback() throws IllegalStateException, SecurityException, SystemException {
        }

        public void setRollbackOnly() throws IllegalStateException, SystemException {
        }

        public void setTransactionTimeout(int i) throws SystemException {
        }

        public Transaction suspend() throws SystemException {
            return null;
        }
    };
}
 
Example #27
Source File: MultiThreadedTx.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void commit() throws HeuristicMixedException, HeuristicRollbackException, RollbackException, SecurityException, SystemException
{
    boolean performAfterCompletion = false;
    try
    {
        synchronized (this)
        {
            this.status.get().prePrepareCheck(this);
            bestEffortEndResources();
            this.status.get().beforeCompletion(this);
            // at this point, our status is either ACTIVE or MARKED_ROLLBACK
            this.status.get().chooseStateForPrepare(this);
            // possible statuses are now PREPARING, COMMITTED, COMMITTING, ROLLING_BACK
            this.status.get().prepare(this);
            // possible statuses are now COMMITTED, COMMITTING, ROLLING_BACK
            performAfterCompletion = true;
            this.status.get().commitOrPossiblyRollback(this);
        }
    }
    finally
    {
        if (performAfterCompletion)
        {
            // possible statuses are now COMMITTED, ROLLED_BACK
            this.status.get().afterCompletion(this);
            multiThreadedTm.removeTransactionFromThread(this);
        }
    }
    this.status.get().postCommitCheck(this);
}
 
Example #28
Source File: MdwTransactionManager.java    From mdw with Apache License 2.0 5 votes vote down vote up
@Override
public void commit() throws HeuristicMixedException,
        HeuristicRollbackException, IllegalStateException,
        RollbackException, SecurityException, SystemException {
    transaction.commit();
    transaction = null;
}
 
Example #29
Source File: RequiredInterceptor.java    From openwebbeans-meecrowave with Apache License 2.0 5 votes vote down vote up
@Override
protected void commit(final State state) {
    if (state.old != state.current) {
        try {
            state.current.commit();
        } catch (final HeuristicMixedException | HeuristicRollbackException | RollbackException | SystemException e) {
            throw new TransactionalException(e.getMessage(), e);
        }
    }
}
 
Example #30
Source File: CompensableManagerImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void invokeTransactionCommitIfLocalTransaction(CompensableTransaction compensable) throws RollbackException,
		HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {

	Transaction transaction = compensable.getTransaction();
	org.bytesoft.transaction.TransactionContext transactionContext = transaction.getTransactionContext();
	TransactionParticipant transactionCoordinator = this.beanFactory.getTransactionNativeParticipant();

	TransactionXid transactionXid = transactionContext.getXid();
	try {
		transactionCoordinator.end(transactionContext, XAResource.TMSUCCESS);
		transactionCoordinator.commit(transactionXid, true);
	} catch (XAException xaEx) {
		switch (xaEx.errorCode) {
		case XAException.XA_HEURCOM:
			transactionCoordinator.forgetQuietly(transactionXid);
			break;
		case XAException.XA_HEURRB:
			transactionCoordinator.forgetQuietly(transactionXid);
			HeuristicRollbackException hrex = new HeuristicRollbackException();
			hrex.initCause(xaEx);
			throw hrex;
		case XAException.XA_HEURMIX:
			transactionCoordinator.forgetQuietly(transactionXid);
			HeuristicMixedException hmex = new HeuristicMixedException();
			hmex.initCause(xaEx);
			throw hmex;
		case XAException.XAER_RMERR:
		default:
			transactionCoordinator.forgetQuietly(transactionXid); // TODO
			SystemException sysEx = new SystemException(xaEx.errorCode);
			sysEx.initCause(xaEx);
			throw sysEx;
		}
	}

}