Java Code Examples for javax.transaction.HeuristicMixedException

The following examples show how to use javax.transaction.HeuristicMixedException. These examples are extracted from open source projects. 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 Project: boost   Source File: JPAResource.java    License: 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 2
Source Project: boost   Source File: JPAResource.java    License: 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 3
/**
 * 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
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 5
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 6
Source Project: microprofile-sandbox   Source File: JPAResource.java    License: 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 7
Source Project: microprofile-sandbox   Source File: JPAResource.java    License: 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 8
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 9
Source Project: lams   Source File: TransactionManagerImpl.java    License: 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 10
Source Project: lams   Source File: UserTransactionImpl.java    License: 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 11
Source Project: scipio-erp   Source File: DumbTransactionFactory.java    License: 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 12
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 13
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 14
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 15
Source Project: lastaflute   Source File: LazyUserTransaction.java    License: 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 Project: requery   Source File: ManagedTransaction.java    License: 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 17
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 18
Source Project: cdi   Source File: JtaTransaction.java    License: Apache License 2.0 5 votes vote down vote up
private void attemptCommit() {
    logger.debug("Committing JTA transaction if required and possible.");

    if (userTransaction != null) {
        try {
            if (owned) {
                if (userTransaction.getStatus() == Status.STATUS_ACTIVE) {
                    logger.debug("Committing BMT transaction.");
                    userTransaction.commit();
                } else {
                    logger.warn("Cannot commit BMT transaction, current transaction status is {}.",
                            statusToString(userTransaction.getStatus()));
                }
            } else {
                logger.debug("Cannot commit non-owned BMT transaction.");
            }
        } catch (SystemException | RollbackException
                | HeuristicMixedException | HeuristicRollbackException
                | SecurityException | IllegalStateException ex) {
            logger.warn("Had trouble trying to commit BMT transaction.", ex);
        }
    } else {
        if (registry != null) {
            logger.debug("Not allowed to commit CMT transaction, the current transaction status is {}.",
                    statusToString(registry.getTransactionStatus()));
        } else {
            logger.warn("No JTA APIs available in this context. No commit done.");
        }
    }
}
 
Example 19
Source Project: javaee8-cookbook   Source File: AsyncTask.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public User call() throws Exception {
    performLookups();
    try {
        userTransaction.begin();
        User user = userBean.getUser();
        userTransaction.commit();
        return user;
    } catch (IllegalStateException | SecurityException | HeuristicMixedException | HeuristicRollbackException | NotSupportedException | RollbackException | SystemException e) {
        userTransaction.rollback();
        return null;
    }
}
 
Example 20
/**
 * 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 21
/**
 * Commit a transaction.
 *
 * @throws RollbackException when a rollback 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 {
    Transaction transaction = getTransaction();
    try {
        transaction.commit();
    } finally {
        Thread currentThread = Thread.currentThread();
        threadTransactionMap.remove(currentThread);
    }
}
 
Example 22
@Test
public void canVersionDocsWithoutSpecialInputFileNameExtension()
        throws HeuristicMixedException, IOException, SystemException,
        HeuristicRollbackException, NotSupportedException, RollbackException
{
    testCanVersionDocsWithoutSpecialInputFileNameExtension(file ->
        streamingNodeImporterFactory.getNodeImporter(resourceAsFile("classpath:bulkimport-autoversion/"+file)));
}
 
Example 23
/**
 * {@inheritDoc}
 */
public void commit() throws RollbackException, HeuristicMixedException,
                            HeuristicRollbackException, SecurityException, IllegalStateException,
                            SystemException
{
   tm.commit();
}
 
Example 24
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://@[email protected]/9db76769-96de-4de4-bdb4-a127130af362
            NodeRef nodeRef = personService.getPerson(id);
            nodeRef = tenantService.getName(nodeRef);
            testPersonNodeRefs.add(nodeRef);
        }
    }
}
 
Example 25
Source Project: scipio-erp   Source File: DumbTransactionFactory.java    License: 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 26
Source Project: reladomo   Source File: MultiThreadedTx.java    License: 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 27
Source Project: mdw   Source File: MdwTransactionManager.java    License: 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 28
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 29
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 30
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);
	}
}