List of usage examples for javax.transaction TransactionManager resume
public void resume(Transaction tobj) throws InvalidTransactionException, IllegalStateException, SystemException;
From source file:edu.illinois.enforcemop.examples.jbosscache.PessimisticSyncReplTxTest.java
public void testSyncRepl() throws Exception { Integer age;/* w ww .j a v a2 s . c o m*/ Transaction tx; cache1.getConfiguration().setSyncCommitPhase(true); cache2.getConfiguration().setSyncCommitPhase(true); TransactionManager mgr = beginTransaction(); cache1.put("/a/b/c", "age", 38); tx = mgr.suspend(); assertNull("age on cache2 must be null as the TX has not yet been committed", cache2.get("/a/b/c", "age")); // log.debug("cache1: locks held before commit: " // + CachePrinter.printCacheLockingInfo(cache1)); // log.debug("cache2: locks held before commit: " // + CachePrinter.printCacheLockingInfo(cache2)); mgr.resume(tx); mgr.commit(); // log.debug("cache1: locks held after commit: " // + CachePrinter.printCacheLockingInfo(cache1)); // log.debug("cache2: locks held after commit: " // + CachePrinter.printCacheLockingInfo(cache2)); // value on cache2 must be 38 age = (Integer) cache2.get("/a/b/c", "age"); assertNotNull("\"age\" obtained from cache2 must be non-null ", age); assertTrue("\"age\" must be 38", age == 38); }
From source file:edu.illinois.enforcemop.examples.jbosscache.PessimisticSyncReplTxTest.java
/** * Test for JBCACHE-361 -- does marking a tx on the remote side rollback-only * cause a rollback on the originating side? *///w w w . j av a 2 s . c o m public void testSyncReplWithRemoteRollback() throws Exception { TransactionManager tm; final Fqn NODE1 = Fqn.fromString("/one/two/three"); cache1.getConfiguration().setSyncRollbackPhase(true); cache2.getConfiguration().setSyncRollbackPhase(true); // Test with a rollback on the remote side // listener aborts any active tx // TransactionAborterListener tal = new TransactionAborterListener(cache2); tm = beginTransaction(); cache1.put(NODE1, "age", 38); // instead of a listener lets just get a WL on ROOT on cache2. And hold on // to it. Transaction tx = tm.suspend(); tm.begin(); cache2.getRoot().put("x", "y"); Transaction tx2 = cache2.getTransactionManager().suspend(); tm.resume(tx); try { tm.commit(); fail("commit should throw a RollbackException, we should not get here"); } catch (RollbackException rollback) { } finally { tm.resume(tx2); tm.rollback(); } // Sleep, as the commit call to cache2 is async Thread.sleep(1000); // assertNull(tal.getCallbackException()); assertEquals(0, cache1.getNumberOfLocksHeld()); assertEquals(0, cache2.getNumberOfLocksHeld()); assertEquals(0, cache1.getNumberOfNodes()); assertEquals(0, cache2.getNumberOfNodes()); }
From source file:org.apache.ofbiz.entity.transaction.TransactionUtil.java
public static void resume(Transaction parentTx) throws GenericTransactionException { if (parentTx == null) { return;/* w w w . j a va2 s .c o m*/ } TransactionManager txMgr = TransactionFactoryLoader.getInstance().getTransactionManager(); try { if (txMgr != null) { setTransactionBeginStack(popTransactionBeginStackSave()); setSetRollbackOnlyCause(popSetRollbackOnlyCauseSave()); txMgr.resume(parentTx); removeSuspendedTransaction(parentTx); } } catch (InvalidTransactionException e) { throw new GenericTransactionException("System error, could not resume transaction", e); } catch (SystemException e) { throw new GenericTransactionException("System error, could not resume transaction", e); } }
From source file:org.eclipse.ecr.automation.core.operations.execution.RunInNewTransaction.java
@OperationMethod public void run() throws Exception { // if the transaction was already marked for rollback, do nothing if (TransactionHelper.isTransactionMarkedRollback()) { return;//from www. j a va 2s. c o m } Map<String, Object> vars = isolate ? new HashMap<String, Object>(ctx.getVars()) : ctx.getVars(); OperationContext subctx = new OperationContext(ctx.getCoreSession(), vars); subctx.setInput(ctx.getInput()); final TransactionManager transactionManager = TransactionHelper.lookupTransactionManager(); final Transaction globalTx = transactionManager.suspend(); try { TransactionHelper.startTransaction(); try { service.run(subctx, chainId); } catch (Exception e) { handleRollbackOnlyOnGlobal(globalTx, e); } finally { try { TransactionHelper.commitOrRollbackTransaction(); } catch (TransactionRuntimeException e) { handleRollbackOnlyOnGlobal(globalTx, e); } } } finally { transactionManager.resume(globalTx); } }
From source file:org.etk.entity.engine.plugins.transaction.TransactionUtil.java
public static void resume(Transaction parentTx) throws GenericTransactionException { if (parentTx == null) { return;/* w ww . ja v a2 s .c o m*/ } TransactionManager txMgr = TransactionFactory.getTransactionManager(); try { if (txMgr != null) { setTransactionBeginStack(popTransactionBeginStackSave()); setSetRollbackOnlyCause(popSetRollbackOnlyCauseSave()); txMgr.resume(parentTx); removeSuspendedTransaction(parentTx); } } catch (InvalidTransactionException e) { /* * NOTE: uncomment this for Weblogic Application Server // this is a * work-around for non-standard Weblogic functionality; for more * information see: * http://www.onjava.com/pub/a/onjava/2005/07/20/transactions.html?page=3 * if (txMgr instanceof weblogic.transaction.ClientTransactionManager) { * // WebLogic 8 and above * ((weblogic.transaction.ClientTransactionManager) * txMgr).forceResume(parentTx); } else if (txMgr instanceof * weblogic.transaction.TransactionManager) { // WebLogic 7 * ((weblogic.transaction.TransactionManager) * txMgr).forceResume(parentTx); } else { throw new * GenericTransactionException * ("System error, could not resume transaction", e); } */ throw new GenericTransactionException("System error, could not resume transaction", e); } catch (SystemException e) { throw new GenericTransactionException("System error, could not resume transaction", e); } }
From source file:org.jboss.ejb3.entity.JTATableIdGenerator.java
public synchronized Serializable generate(SessionImplementor session, Object object) throws HibernateException { // get TransactionManager from JNDI // no JNDI properties provided -> we are in the container TransactionManager tm = transactionManagerLookup.getTransactionManager(new Properties()); Transaction surroundingTransaction = null; // for resuming in finally block Connection conn = null; // for ressource cleanup String sql = null; // for exception try {//from w w w . ja va 2 s. c o m long result; // holds the resulting sequence value // prepare a new transaction context for the generator surroundingTransaction = tm.suspend(); if (log.isDebugEnabled()) { log.debug("surrounding tx suspended"); } tm.begin(); // get connection from managed environment conn = session.getBatcher().openConnection(); // execute fetching of current sequence value sql = query; PreparedStatement qps = conn.prepareStatement(query); try { ResultSet rs = qps.executeQuery(); if (!rs.next()) { String err = "could not read sequence value - you need to populate the table: " + tableName; log.error(err); throw new IdentifierGenerationException(err); } result = rs.getLong(1); rs.close(); } catch (SQLException sqle) { log.error("could not read a sequence value", sqle); throw sqle; } finally { qps.close(); } // increment sequence value sql = update; long sequence = result + 1; PreparedStatement ups = conn.prepareStatement(update); try { ups.setLong(1, sequence); ups.setLong(2, result); ups.executeUpdate(); } catch (SQLException sqle) { log.error("could not update sequence value in: " + tableName, sqle); throw sqle; } finally { ups.close(); } // commit transaction to ensure updated sequence is not rolled back tm.commit(); // transform sequence to the desired type and return the value Number typedSequence = IdentifierGeneratorFactory.createNumber(sequence, returnClass); if (log.isDebugEnabled()) { log.debug("generate() returned: " + typedSequence); } return typedSequence; } catch (SQLException sqle) { throw JDBCExceptionHelper.convert(session.getFactory().getSQLExceptionConverter(), sqle, "could not get or update next value", sql); } catch (Exception e) { try { tm.rollback(); throw new HibernateException(e); } catch (SystemException e1) { throw new HibernateException(e1); } } finally { if (conn != null) try { conn.close(); } catch (SQLException e) { // ignore exception } // switch back to surrounding transaction context if (surroundingTransaction != null) { try { tm.resume(surroundingTransaction); if (log.isDebugEnabled()) { log.debug("surrounding tx resumed"); } } catch (Exception e) { throw new HibernateException(e); } } } }
From source file:org.nuxeo.runtime.transaction.TransactionHelper.java
/** * Commit the current transaction if active and resume the principal transaction * * @param tx/* w w w .jav a 2s . c o m*/ */ public static void resumeTransaction(Transaction tx) { TransactionManager tm = NuxeoContainer.getTransactionManager(); if (tm == null) { return; } try { if (tm.getStatus() == Status.STATUS_ACTIVE) { tm.commit(); } if (tx != null) { tm.resume(tx); } } catch (SystemException | RollbackException | HeuristicMixedException | HeuristicRollbackException | InvalidTransactionException | IllegalStateException | SecurityException e) { throw new TransactionRuntimeException("Cannot resume tx", e); } }
From source file:org.openejb.transaction.TxRequiresNew.java
public InvocationResult invoke(Interceptor interceptor, EjbInvocation ejbInvocation, TransactionManager transactionManager) throws Throwable { Transaction callerTransaction = transactionManager.suspend(); try {/* ww w . ja v a 2 s . c o m*/ transactionManager.begin(); try { InvocationResult result = interceptor.invoke(ejbInvocation); return result; } catch (RollbackException re) { throw re; } catch (Throwable t) { try { transactionManager.setRollbackOnly(); } catch (Exception e) { log.warn("Unable to roll back", e); } throw t; } finally { if (transactionManager.getStatus() == Status.STATUS_ACTIVE) { transactionManager.commit(); } else { transactionManager.rollback(); } } } finally { if (callerTransaction != null) { transactionManager.resume(callerTransaction); } } }
From source file:org.wso2.carbon.attachment.mgt.core.dao.impl.TransactionManagerProvider.java
public void doNonTransactionalWork(java.lang.Runnable runnable) throws NotSupportedException { TransactionManager transactionManager = null; Transaction transaction = null;/*from w w w. j a v a 2s . c o m*/ try { transactionManager = getTransactionManager(); transaction = transactionManager.suspend(); } catch (Exception e) { NotSupportedException nse = new NotSupportedException(e.getMessage()); nse.initCause(e); log.error(nse.getLocalizedMessage(), nse); throw nse; } runnable.run(); try { transactionManager.resume(transaction); } catch (Exception e) { log.error(e.getLocalizedMessage(), e); try { transaction.setRollbackOnly(); } catch (SystemException se2) { throw new GeneralException(se2); } NotSupportedException nse = new NotSupportedException(e.getMessage()); nse.initCause(e); throw nse; } }