List of usage examples for javax.transaction UserTransaction setTransactionTimeout
void setTransactionTimeout(int seconds) throws SystemException;
From source file:edu.harvard.i2b2.crc.ejb.QueryExecutorMDB.java
/** * Take the XML based message and delegate to the system coordinator to * handle the actual processing/*from www . j a v a 2 s .co m*/ * * @param msg * th JMS TextMessage object containing XML data */ public void onMessage(Message msg) { MapMessage message = null; QueueConnection conn = null; QueueSession session = null; QueueSender sender = null; QueryProcessorUtil qpUtil = QueryProcessorUtil.getInstance(); Queue replyToQueue = null; UserTransaction transaction = sessionContext.getUserTransaction(); // default timeout three minutes int transactionTimeout = 0; try { transactionTimeout = this.readTimeoutPropertyValue(SMALL_QUEUE); if (callingMDBName.equalsIgnoreCase(QueryExecutorMDB.MEDIUM_QUEUE)) { // four hours // transactionTimeout = 14400; transactionTimeout = this.readTimeoutPropertyValue(MEDIUM_QUEUE); } else if (callingMDBName.equalsIgnoreCase(QueryExecutorMDB.LARGE_QUEUE)) { // twelve hours // transactionTimeout = 43200; transactionTimeout = this.readTimeoutPropertyValue(LARGE_QUEUE); } transaction.setTransactionTimeout(transactionTimeout); transaction.begin(); message = (MapMessage) msg; String sessionId = msg.getJMSCorrelationID(); replyToQueue = (Queue) msg.getJMSReplyTo(); log.debug("Extracting the message [" + msg.getJMSMessageID() + " ] on " + callingMDBName); transaction.commit(); ExecRunnable er = new ExecRunnable(transaction, transactionTimeout, callingMDBName, message, sessionId); er.execute(); } catch (Exception ex) { ex.printStackTrace(); try { if (transaction.getStatus() != 4) { transaction.rollback(); } } catch (Exception e) { e.printStackTrace(); } log.error("Error extracting message", ex); } finally { QueryManagerBeanUtil qmBeanUtil = new QueryManagerBeanUtil(); qmBeanUtil.closeAll(sender, null, conn, session); } }
From source file:org.apache.ofbiz.entity.transaction.TransactionUtil.java
protected static void internalBegin(UserTransaction ut, int timeout) throws SystemException, NotSupportedException { // set the timeout for THIS transaction if (timeout > 0) { ut.setTransactionTimeout(timeout); if (Debug.verboseOn()) { Debug.logVerbose("Set transaction timeout to : " + timeout + " seconds", module); }// w ww . j a v a 2s. c o m } // begin the transaction ut.begin(); if (Debug.verboseOn()) { Debug.logVerbose("Transaction begun", module); } // reset the timeout to the default if (timeout > 0) { ut.setTransactionTimeout(0); } }
From source file:org.apache.ofbiz.entity.transaction.TransactionUtil.java
/** Sets the timeout of the transaction in the current thread IF transactions are available */ public static void setTransactionTimeout(int seconds) throws GenericTransactionException { UserTransaction ut = TransactionFactoryLoader.getInstance().getUserTransaction(); if (ut != null) { try {/* w w w. j a va 2 s.co m*/ ut.setTransactionTimeout(seconds); } catch (SystemException e) { throw new GenericTransactionException("System error, could not set transaction timeout", e); } } }
From source file:org.eclipse.ecr.core.event.tx.EventBundleTransactionHandler.java
protected UserTransaction createUT(Integer transactionTimeout, boolean retry) { try {/*from ww w. j a v a 2s . c o m*/ new InitialContext(); } catch (Exception e) { disabled = true; return null; } UserTransaction ut; try { ut = TransactionHelper.lookupUserTransaction(); } catch (NamingException e) { disabled = true; return null; } try { int txStatus = ut.getStatus(); if (txStatus != Status.STATUS_NO_TRANSACTION && !retry) { // if previous tx in this thread aborted in TimeOut // Ajuna may have failed to dissociate tx from thread context // => force rollback to avoid reusing a dead tx log.warn( "Transaction was not properly cleanup up from thread context, rolling back before getting a new tx"); try { ut.rollback(); } catch (Throwable t) { log.warn("error during tx rollback", t); } return createUT(transactionTimeout, true); } } catch (Exception se) { log.warn("Error while getting TX status", se); } if (transactionTimeout != null) { try { ut.setTransactionTimeout(transactionTimeout); } catch (SystemException e) { log.error("Error while setting transaction timeout to " + transactionTimeout, e); } } return ut; }
From source file:org.etk.entity.engine.plugins.transaction.TransactionUtil.java
protected static synchronized void internalBegin(UserTransaction ut, int timeout) throws SystemException, NotSupportedException { // set the timeout for THIS transaction if (timeout > 0) { ut.setTransactionTimeout(timeout); if (logger.isDebugEnabled()) { logger.debug("[TransactionUtil.begin] set transaction timeout to : " + timeout + " seconds"); }/*from ww w .ja v a 2 s . com*/ } // begin the transaction ut.begin(); if (logger.isDebugEnabled()) { logger.debug("[TransactionUtil.begin] transaction begun"); } // reset the timeout to the default if (timeout > 0) { ut.setTransactionTimeout(0); } }
From source file:org.etk.entity.engine.plugins.transaction.TransactionUtil.java
/** * Sets the timeout of the transaction in the current thread IF transactions * are available/*from w w w . j a v a 2 s . c o m*/ */ public static void setTransactionTimeout(int seconds) throws GenericTransactionException { UserTransaction ut = TransactionFactory.getUserTransaction(); if (ut != null) { try { ut.setTransactionTimeout(seconds); } catch (SystemException e) { throw new GenericTransactionException("System error, could not set transaction timeout", e); } } }
From source file:org.nuxeo.ecm.platform.importer.base.TxHelper.java
protected UserTransaction createUT(Integer transactionTimeout) { InitialContext context = null; try {/* w w w. j ava 2s.c o m*/ context = new InitialContext(); } catch (Exception e) { disabled = true; return null; } UserTransaction ut = null; try { ut = (UserTransaction) context.lookup(UT_NAME); } catch (NamingException ne) { try { ut = (UserTransaction) context.lookup(UT_NAME_ALT); } catch (NamingException ne2) { disabled = true; } } if (transactionTimeout != null && ut != null) { try { ut.setTransactionTimeout(transactionTimeout); } catch (SystemException e) { log.error("Error while setting transaction timeout to " + transactionTimeout, e); } } return ut; }
From source file:org.xchain.namespaces.jta.TransactionCommand.java
public boolean execute(JXPathContext context) throws Exception { boolean managingTransaction = false; boolean result = false; UserTransaction transaction = ContainerContext.getJtaLookupStrategy().getUserTransaction(); if (transaction != null) { try {//from www . ja va2s . co m // if there is not a transaction running, then start one. if (Status.STATUS_ACTIVE != transaction.getStatus()) { managingTransaction = true; transaction.setTransactionTimeout(this.getTimeout(context)); transaction.begin(); } // put the transaction into the context. ((ScopedQNameVariables) context.getVariables()).declareVariable(getResult(context), transaction, Scope.execution); // execute the chain result = super.execute(context); // roll back the transaction. if (managingTransaction) { transaction.commit(); } } catch (Exception e) { if (managingTransaction) { if (transaction.getStatus() != Status.STATUS_NO_TRANSACTION) { transaction.rollback(); } } throw e; } finally { // TODO: If we defined the transaction variable, then we should remove it. } } else { // TODO: Should this throw an IllegalStateException? Returning true seems like the wrong behavior. result = true; } return result; }