Example usage for javax.transaction TransactionManager setTransactionTimeout

List of usage examples for javax.transaction TransactionManager setTransactionTimeout

Introduction

In this page you can find the example usage for javax.transaction TransactionManager setTransactionTimeout.

Prototype

public void setTransactionTimeout(int seconds) throws SystemException;

Source Link

Document

Modify the timeout value that is associated with transactions started by the current thread with the begin method.

Usage

From source file:org.apache.axis2.transaction.TransactionConfiguration.java

public synchronized TransactionManager getTransactionManager() throws AxisFault {
    TransactionManager transactionManager = (TransactionManager) threadTransactionManager.get();
    if (transactionManager == null) {
        transactionManager = lookupTransactionManager();
        threadTransactionManager.set(transactionManager);
        if (log.isDebugEnabled())
            log.debug("JNDI lookup TransactionManager");
    } else {/*  w  ww  .  j  a  va2  s  . c  o  m*/
        if (log.isDebugEnabled())
            log.debug("Re-use previously JNDI lookup TransactionManager");
    }
    try {
        transactionManager.setTransactionTimeout(transactionTimeout);
    } catch (Exception ignore) {
    }

    return transactionManager;
}

From source file:org.apache.ode.test.BPELTestAbstract.java

protected TransactionManager createTransactionManager() throws Exception {
    EmbeddedGeronimoFactory factory = new EmbeddedGeronimoFactory();
    TransactionManager _txManager = factory.getTransactionManager();
    _txManager.setTransactionTimeout(30);
    return _txManager;
}

From source file:org.collectionspace.services.nuxeo.client.java.NuxeoClientEmbedded.java

public RepositoryInstance openRepository(String repoName, int timeoutSeconds) throws Exception {
    RepositoryInstance result = null;/*w ww  . ja v a2s.  c  o m*/

    if (timeoutSeconds > 0) {
        TransactionManager transactionMgr = TransactionHelper.lookupTransactionManager();
        transactionMgr.setTransactionTimeout(timeoutSeconds);
        if (logger.isInfoEnabled()) {
            logger.info(String.format("Changing current request's transaction timeout period to %d seconds",
                    timeoutSeconds));
        }
    }

    boolean startTransaction = TransactionHelper.startTransaction();
    if (startTransaction == false) {
        logger.warn("Could not start a Nuxeo transaction with the TransactionHelper class.");
    }

    Repository repository = null;
    if (repoName != null) {
        repository = getRepositoryManager().getRepository(repoName);
    } else {
        repository = getRepositoryManager().getDefaultRepository(); // Add a log info statement here stating that since no repo name was given we'll use the default repo instead
    }

    if (repository != null) {
        result = newRepositoryInstance(repository);
        String key = result.getSessionId();
        repositoryInstances.put(key, result);
        if (logger.isTraceEnabled()) {
            logger.trace("Added a new repository instance to our repo list.  Current count is now: "
                    + repositoryInstances.size());
        }
    } else {
        String errMsg = String.format("Could not open a session to the Nuxeo repository='%s'", repoName);
        logger.error(errMsg);
        throw new Exception(errMsg);
    }

    return result;
}

From source file:org.nuxeo.runtime.transaction.TransactionHelper.java

/**
 * Starts a new User Transaction with the specified timeout.
 *
 * @param timeout the timeout in seconds, <= 0 for the default
 * @return {@code true} if the transaction was successfully started, {@code false} otherwise
 * @since 5.6/*ww  w.j  a  v  a 2s.  co  m*/
 */
public static boolean startTransaction(int timeout) {
    if (timeout < 0) {
        timeout = 0;
    }
    TransactionManager tm = NuxeoContainer.getTransactionManager();
    if (tm == null) {
        return false;
    }

    try {
        tm.setTransactionTimeout(timeout);
    } catch (SystemException e) {
        log.error("Unable to set transaction timeout: " + timeout, e);
        return false;
    }
    try {
        return startTransaction();
    } finally {
        try {
            tm.setTransactionTimeout(0);
        } catch (SystemException e) {
            log.error("Unable to reset transaction timeout", e);
        }
    }
}

From source file:org.topazproject.otm.impl.AbstractSession.java

private void ensureTxActive(boolean start, int txTimeout) throws OtmException {
    if (jtaTxn != null)
        return;// w  w  w  .  j a v  a2 s.c om

    try {
        TransactionManager tm = getSessionFactory().getTransactionManager();

        jtaTxn = tm.getTransaction();
        if (jtaTxn == null) {
            if (!start)
                throw new OtmException("No active transaction");

            tm.setTransactionTimeout(txTimeout > 0 ? txTimeout : 0);
            tm.begin();
            jtaTxn = tm.getTransaction();
        }

        jtaTxn.registerSynchronization(new Synchronization() {
            public void beforeCompletion() {
                if (getFlushMode().implies(FlushMode.commit) && !isRollback())
                    flush();
            }

            public void afterCompletion(int status) {
                endTransaction();
            }

            private boolean isRollback() throws OtmException {
                try {
                    return (jtaTxn.getStatus() == Status.STATUS_MARKED_ROLLBACK);
                } catch (Exception e) {
                    throw new OtmException("Error getting rollback-only status", e);
                }
            }
        });
    } catch (OtmException oe) {
        throw oe;
    } catch (Exception e) {
        throw new OtmException("Error setting up transaction", e);
    }
}