protected void registerDisposeCallback(RuntimeEngine runtime, TransactionSynchronization sync, Environment environment) { // register it if there is an active transaction as we assume then to be running in a managed environment e.g CMT TransactionManager tm = getTransactionManager(environment); if (tm.getStatus() != TransactionManager.STATUS_NO_TRANSACTION && tm.getStatus() != TransactionManager.STATUS_ROLLEDBACK && tm.getStatus() != TransactionManager.STATUS_COMMITTED) { TransactionManagerHelper.registerTransactionSyncInContainer(tm, (OrderedTransactionSynchronization) sync); } }
protected void countDown() { try { TransactionManager tm = TransactionManagerFactory.get().newTransactionManager(); if (tm != null && tm.getStatus() != TransactionManager.STATUS_NO_TRANSACTION && tm.getStatus() != TransactionManager.STATUS_ROLLEDBACK && tm.getStatus() != TransactionManager.STATUS_COMMITTED) { tm.registerTransactionSynchronization(new TransactionSynchronization() { @Override public void beforeCompletion() { } @Override public void afterCompletion(int status) { latch.countDown(); } }); } else { latch.countDown(); } } catch (Exception e) { latch.countDown(); } } }
protected void countDown() { try { TransactionManager tm = TransactionManagerFactory.get().newTransactionManager(); if (tm != null && tm.getStatus() != TransactionManager.STATUS_NO_TRANSACTION && tm.getStatus() != TransactionManager.STATUS_ROLLEDBACK && tm.getStatus() != TransactionManager.STATUS_COMMITTED) { tm.registerTransactionSynchronization(new TransactionSynchronization() { @Override public void beforeCompletion() { } @Override public void afterCompletion(int status) { latch.countDown(); } }); } else { latch.countDown(); } } catch (Exception e) { latch.countDown(); } } }
protected boolean canDestroy(RuntimeEngine runtime) { if (((RuntimeEngineImpl) runtime).isAfterCompletion()) { return false; } TransactionManager tm = getTransactionManager(runtime.getKieSession().getEnvironment()); if (tm.getStatus() == TransactionManager.STATUS_NO_TRANSACTION || tm.getStatus() == TransactionManager.STATUS_ACTIVE) { return true; } return false; }
protected boolean canDispose(RuntimeEngine runtime) { // avoid duplicated dispose if (((RuntimeEngineImpl)runtime).isDisposed()) { return false; } // if this method was called as part of afterCompletion allow to dispose if (((RuntimeEngineImpl)runtime).isAfterCompletion()) { return true; } try { // check tx status to disallow dispose when within active transaction TransactionManager tm = getTransactionManager(runtime.getKieSession().getEnvironment()); if (tm.getStatus() != TransactionManager.STATUS_NO_TRANSACTION && tm.getStatus() != TransactionManager.STATUS_ROLLEDBACK && tm.getStatus() != TransactionManager.STATUS_COMMITTED) { return false; } } catch (SessionNotFoundException e) { // ignore it as it might be thrown for per process instance } return true; }
@Override public final void internalSchedule(final TimerJobInstance timerJobInstance) { if (hasEnvironmentEntry("IS_JTA_TRANSACTION", false)) { super.internalSchedule(timerJobInstance); return; } TransactionManager tm = getTransactionManager(timerJobInstance.getJobContext()); if (tm.getStatus() != TransactionManager.STATUS_NO_TRANSACTION && tm.getStatus() != TransactionManager.STATUS_ROLLEDBACK && tm.getStatus() != TransactionManager.STATUS_COMMITTED) { TransactionManagerHelper.registerTransactionSyncInContainer(tm, new ScheduleTimerTransactionSynchronization(timerJobInstance, delegate)); return; } super.internalSchedule(timerJobInstance); }
@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; }
@Override public Void execute(org.kie.api.runtime.Context context) { if (manager.hasEnvironmentEntry("IS_JTA_TRANSACTION", false)) { initialKsession.dispose(); return null; } TransactionManager tm = (TransactionManager) initialKsession.getEnvironment().get(EnvironmentName.TRANSACTION_MANAGER); if (tm != null && tm.getStatus() != TransactionManager.STATUS_NO_TRANSACTION && tm.getStatus() != TransactionManager.STATUS_ROLLEDBACK && tm.getStatus() != TransactionManager.STATUS_COMMITTED) { TransactionManagerHelper.registerTransactionSyncInContainer(tm, new OrderedTransactionSynchronization(5, "PPIRM-" + initialKsession.getIdentifier()) { @Override public void beforeCompletion() { } @Override public void afterCompletion(int arg0) { initialKsession.dispose(); } }); } else { initialKsession.dispose(); } return null; } }
txStatus = tm.getStatus();
@Override public Void execute(org.kie.api.runtime.Context context) { if (manager.hasEnvironmentEntry("IS_JTA_TRANSACTION", false)) { initialKsession.dispose(); return null; } TransactionManager tm = (TransactionManager) initialKsession.getEnvironment().get(EnvironmentName.TRANSACTION_MANAGER); if (tm != null && tm.getStatus() != TransactionManager.STATUS_NO_TRANSACTION && tm.getStatus() != TransactionManager.STATUS_ROLLEDBACK && tm.getStatus() != TransactionManager.STATUS_COMMITTED) { TransactionManagerHelper.registerTransactionSyncInContainer(tm, new OrderedTransactionSynchronization(5, "PPIRM-"+initialKsession.getIdentifier()) { @Override public void beforeCompletion() { } @Override public void afterCompletion(int arg0) { initialKsession.dispose(); } }); } else { initialKsession.dispose(); } return null; } }
protected boolean allowedToDispose(Environment environment) { if (hasEnvironmentEntry(environment, "IS_JTA_TRANSACTION", false)) { return true; } TransactionManager transactionManager = null; Object txm = environment.get(EnvironmentName.TRANSACTION_MANAGER); if (txm != null && txm instanceof TransactionManager) { transactionManager = (TransactionManager) txm; } else { transactionManager = TransactionManagerFactory.get().newTransactionManager(); } int status = transactionManager.getStatus(); if (status != TransactionManager.STATUS_NO_TRANSACTION && status != TransactionManager.STATUS_ROLLEDBACK && status != TransactionManager.STATUS_COMMITTED) { return false; } return true; }
if (tm != null && tm.getStatus() != TransactionManager.STATUS_NO_TRANSACTION && tm.getStatus() != TransactionManager.STATUS_ROLLEDBACK && tm.getStatus() != TransactionManager.STATUS_COMMITTED) { TransactionManagerHelper.registerTransactionSyncInContainer(tm, new OrderedTransactionSynchronization(5, "PPIRM-"+initialKsession.getIdentifier()) {
if (tm != null && tm.getStatus() != TransactionManager.STATUS_NO_TRANSACTION && tm.getStatus() != TransactionManager.STATUS_ROLLEDBACK && tm.getStatus() != TransactionManager.STATUS_COMMITTED) { TransactionManagerHelper.registerTransactionSyncInContainer(tm, new OrderedTransactionSynchronization(5, "PCRM-" + initialKsession.getIdentifier()) {
protected void registerDisposeCallback(RuntimeEngine runtime, TransactionSynchronization sync, Environment environment) { // register it if there is an active transaction as we assume then to be running in a managed environment e.g CMT TransactionManager tm = getTransactionManager(environment); if (tm.getStatus() != TransactionManager.STATUS_NO_TRANSACTION && tm.getStatus() != TransactionManager.STATUS_ROLLEDBACK && tm.getStatus() != TransactionManager.STATUS_COMMITTED) { TransactionManagerHelper.registerTransactionSyncInContainer(tm, (OrderedTransactionSynchronization) sync); } }
protected void countDown() { try { TransactionManager tm = TransactionManagerFactory.get().newTransactionManager(); if (tm != null && tm.getStatus() != TransactionManager.STATUS_NO_TRANSACTION && tm.getStatus() != TransactionManager.STATUS_ROLLEDBACK && tm.getStatus() != TransactionManager.STATUS_COMMITTED) { tm.registerTransactionSynchronization(new TransactionSynchronization() { @Override public void beforeCompletion() { } @Override public void afterCompletion(int status) { latch.countDown(); } }); } else { latch.countDown(); } } catch (Exception e) { latch.countDown(); } } }
protected boolean canDestroy(RuntimeEngine runtime) { if (((RuntimeEngineImpl) runtime).isAfterCompletion()) { return false; } TransactionManager tm = getTransactionManager(runtime.getKieSession().getEnvironment()); if (tm.getStatus() == TransactionManager.STATUS_NO_TRANSACTION || tm.getStatus() == TransactionManager.STATUS_ACTIVE) { return true; } return false; }
protected boolean canDispose(RuntimeEngine runtime) { // avoid duplicated dispose if (((RuntimeEngineImpl)runtime).isDisposed()) { return false; } // if this method was called as part of afterCompletion allow to dispose if (((RuntimeEngineImpl)runtime).isAfterCompletion()) { return true; } try { // check tx status to disallow dispose when within active transaction TransactionManager tm = getTransactionManager(runtime.getKieSession().getEnvironment()); if (tm.getStatus() != TransactionManager.STATUS_NO_TRANSACTION && tm.getStatus() != TransactionManager.STATUS_ROLLEDBACK && tm.getStatus() != TransactionManager.STATUS_COMMITTED) { return false; } } catch (SessionNotFoundException e) { // ignore it as it might be thrown for per process instance } return true; }
@Override public final void internalSchedule(final TimerJobInstance timerJobInstance) { if (hasEnvironmentEntry("IS_JTA_TRANSACTION", false)) { super.internalSchedule(timerJobInstance); return; } TransactionManager tm = getTransactionManager(timerJobInstance.getJobContext()); if (tm.getStatus() != TransactionManager.STATUS_NO_TRANSACTION && tm.getStatus() != TransactionManager.STATUS_ROLLEDBACK && tm.getStatus() != TransactionManager.STATUS_COMMITTED) { TransactionManagerHelper.registerTransactionSyncInContainer(tm, new ScheduleTimerTransactionSynchronization(timerJobInstance, delegate)); return; } super.internalSchedule(timerJobInstance); }
public EntityManager getApplicationScopedEntityManager() { if ( this.appScopedEntityManager == null ) { // Use the App scoped EntityManager if the user has provided it, and it is open. this.appScopedEntityManager = (EntityManager) this.env.get( EnvironmentName.APP_SCOPED_ENTITY_MANAGER ); if ( this.appScopedEntityManager != null && !this.appScopedEntityManager.isOpen() ) { throw new RuntimeException("Provided APP_SCOPED_ENTITY_MANAGER is not open"); } if ( this.appScopedEntityManager == null ) { internalAppScopedEntityManagerFlag = true; this.appScopedEntityManager = this.emf.createEntityManager(); this.env.set( EnvironmentName.APP_SCOPED_ENTITY_MANAGER, this.appScopedEntityManager ); if (txm.getStatus() == TransactionManager.STATUS_ACTIVE) { this.txm.putResource(EnvironmentName.APP_SCOPED_ENTITY_MANAGER, this.appScopedEntityManager ); } } else { internalAppScopedEntityManagerFlag = false; } } return appScopedEntityManager; }
@Override public Void execute(org.kie.api.runtime.Context context) { if (manager.hasEnvironmentEntry("IS_JTA_TRANSACTION", false)) { initialKsession.dispose(); return null; } TransactionManager tm = (TransactionManager) initialKsession.getEnvironment().get(EnvironmentName.TRANSACTION_MANAGER); if (tm != null && tm.getStatus() != TransactionManager.STATUS_NO_TRANSACTION && tm.getStatus() != TransactionManager.STATUS_ROLLEDBACK && tm.getStatus() != TransactionManager.STATUS_COMMITTED) { TransactionManagerHelper.registerTransactionSyncInContainer(tm, new OrderedTransactionSynchronization(5, "PPIRM-" + initialKsession.getIdentifier()) { @Override public void beforeCompletion() { } @Override public void afterCompletion(int arg0) { initialKsession.dispose(); } }); } else { initialKsession.dispose(); } return null; } }