protected <R> R call(Function<EntityManager, R> function) { boolean transactionOwner = false; try { transactionOwner = txm.begin(); EntityManager em = emf.createEntityManager(); R result = function.apply(em); txm.commit( transactionOwner ); em.close(); return result; } catch (Exception e) { txm.rollback(transactionOwner); throw new RuntimeException( "Exception when persisting error information", e); } }
protected TransactionManager startTxIfNeeded(Environment environment) { try { if (hasEnvironmentEntry(environment, "IS_TIMER_CMT", true)) { return null; } if (environment.get(EnvironmentName.TRANSACTION_MANAGER) instanceof ContainerManagedTransactionManager) { TransactionManager tm = TransactionManagerFactory.get().newTransactionManager(); if (tm.begin()) { return tm; } } } catch (Exception e) { logger.debug("Unable to optionally start transaction due to {}", e.getMessage(), e); } return null; }
@Override public Object joinTransaction(EntityManager em) { boolean newTx = false; TransactionManager txm = TransactionManagerFactory.get().newTransactionManager(); if( txm == null ) { throw new IllegalStateException("Unable to find JTA transaction." ); } try { if( txm.getStatus() == TransactionManager.STATUS_NO_TRANSACTION ) { txm.begin(); newTx = true; // since new transaction was started em must join it } } catch(Exception ex) { throw new IllegalStateException("Unable to find or open a transaction: " + ex.getMessage(), ex); } try { em.joinTransaction(); } catch( Exception e) { throw new IllegalStateException("Unable to join EntityManager to transaction: " + e.getMessage(), e); } if( newTx ) { return txm; } return USER_MANAGED_TRANSACTION; }
public <T> T execute(Command<T> command) { boolean transactionOwner = false; boolean emOwner = false; T result = null; try { transactionOwner = txm.begin(); EntityManager em = getEntityManager(command); if (em == null) { em = emf.createEntityManager(); emOwner = true; } JpaPersistenceContext context = new JpaPersistenceContext(em); context.joinTransaction(); result = ((ExecutableCommand<T>)command).execute( context ); txm.commit( transactionOwner ); context.close(transactionOwner, emOwner); return result; } catch ( RuntimeException re ) { rollbackTransaction( re, transactionOwner ); throw re; } catch ( Exception t1 ) { rollbackTransaction( t1, transactionOwner ); throw new RuntimeException( "Wrapped exception see cause", t1 ); } }
transactionOwner = txm.begin();
if (environment.usePersistence()){ tm = getTransactionManagerInternal(environment.getEnvironment()); owner = tm.begin();
if (environment.usePersistence()) { tm = getTransactionManagerInternal(environment.getEnvironment()); owner = tm.begin();
transactionOwner = txm.begin(); tpm.beginCommandScopedEntityManager(); TransactionManagerHelper.registerTransactionSyncInContainer(this.txm, new TaskSynchronizationImpl( this ));
if (environment.usePersistence()) { tm = getTransactionManagerInternal(environment.getEnvironment()); owner = tm.begin();
protected <R> R call(Function<EntityManager, R> function) { boolean transactionOwner = false; try { transactionOwner = txm.begin(); EntityManager em = emf.createEntityManager(); R result = function.apply(em); txm.commit( transactionOwner ); em.close(); return result; } catch (Exception e) { txm.rollback(transactionOwner); throw new RuntimeException( "Exception when persisting error information", e); } }
public <T> T execute(Command<T> command) { boolean transactionOwner = false; boolean emOwner = false; T result = null; try { transactionOwner = txm.begin(); EntityManager em = getEntityManager(command); if (em == null) { em = emf.createEntityManager(); emOwner = true; } JpaPersistenceContext context = new JpaPersistenceContext(em); context.joinTransaction(); result = ((ExecutableCommand<T>)command).execute( context ); txm.commit( transactionOwner ); context.close(transactionOwner, emOwner); return result; } catch ( RuntimeException re ) { rollbackTransaction( re, transactionOwner ); throw re; } catch ( Exception t1 ) { rollbackTransaction( t1, transactionOwner ); throw new RuntimeException( "Wrapped exception see cause", t1 ); } }
@Override public void destroy() { PersistenceContext persistenceContext = this.jpm.getApplicationScopedPersistenceContext(); boolean transactionOwner = false; try { transactionOwner = txm.begin(); persistenceContext.joinTransaction(); initExistingKnowledgeSession( this.sessionInfo.getId(), this.marshallingHelper.getKbase(), this.marshallingHelper.getConf(), persistenceContext ); persistenceContext.remove(this.sessionInfo); txm.commit( transactionOwner ); } catch ( RuntimeException re ) { rollbackTransaction( re, transactionOwner ); throw re; } catch ( Exception t1 ) { rollbackTransaction(t1, transactionOwner); throw new RuntimeException( "Wrapped exception see cause", t1 ); } }
transactionOwner = txm.begin(); registerRollbackSync();
transactionOwner = txm.begin();
boolean transactionOwner = false; try { transactionOwner = txm.begin(); registerRollbackSync();
if (environment.usePersistence()){ tm = getTransactionManagerInternal(environment.getEnvironment()); owner = tm.begin();
transactionOwner = txm.begin(); tpm.beginCommandScopedEntityManager(); TransactionManagerHelper.registerTransactionSyncInContainer(this.txm, new TaskSynchronizationImpl( this ));
@Test public void basicTransactionRollbackTest() { Environment env = createEnvironment(context); //TransactionManager txm = (TransactionManager) env.get( EnvironmentName.TRANSACTION_MANAGER ); javax.transaction.TransactionManager tm = (javax.transaction.TransactionManager) env.get( EnvironmentName.TRANSACTION_MANAGER ); TransactionManager txm = new JtaTransactionManager( env.get( EnvironmentName.TRANSACTION ), env.get( EnvironmentName.TRANSACTION_SYNCHRONIZATION_REGISTRY ), tm ); // Create linked transactionTestObjects TransactionTestObject mainObject = new TransactionTestObject(); mainObject.setName("main"); TransactionTestObject subObject = new TransactionTestObject(); subObject.setName("sub"); mainObject.setSubObject(subObject); Cache<Serializable, Object> cache = cm.getCache("jbpm-configured-cache"); try { boolean notTxOwner = txm.begin(); Serializable s = generateId(mainObject); mainObject.setId(Long.valueOf(s.toString())); cache.put(s, mainObject); txm.rollback(notTxOwner); } catch ( Exception e ) { fail("There should not be an exception thrown here: " + e.getMessage()); } }
if (environment.usePersistence()) { tm = getTransactionManagerInternal(environment.getEnvironment()); owner = tm.begin();