use of org.activiti.engine.impl.cfg.TransactionListener in project Activiti by Activiti.
the class JobEntityManager method hintJobExecutor.
protected void hintJobExecutor(JobEntity job) {
JobExecutor jobExecutor = Context.getProcessEngineConfiguration().getJobExecutor();
// notify job executor:
TransactionListener transactionListener = new JobAddedNotification(jobExecutor);
Context.getCommandContext().getTransactionContext().addTransactionListener(TransactionState.COMMITTED, transactionListener);
}
use of org.activiti.engine.impl.cfg.TransactionListener in project Activiti by Activiti.
the class EntityManagerSessionImpl method getEntityManager.
public EntityManager getEntityManager() {
if (entityManager == null) {
entityManager = getEntityManagerFactory().createEntityManager();
if (handleTransactions) {
// Add transaction listeners, if transactions should be handled
TransactionListener jpaTransactionCommitListener = new TransactionListener() {
public void execute(CommandContext commandContext) {
if (isTransactionActive()) {
entityManager.getTransaction().commit();
}
}
};
TransactionListener jpaTransactionRollbackListener = new TransactionListener() {
public void execute(CommandContext commandContext) {
if (isTransactionActive()) {
entityManager.getTransaction().rollback();
}
}
};
TransactionContext transactionContext = Context.getTransactionContext();
transactionContext.addTransactionListener(TransactionState.COMMITTED, jpaTransactionCommitListener);
transactionContext.addTransactionListener(TransactionState.ROLLED_BACK, jpaTransactionRollbackListener);
// Also, start a transaction, if one isn't started already
if (!isTransactionActive()) {
entityManager.getTransaction().begin();
}
}
}
return entityManager;
}
use of org.activiti.engine.impl.cfg.TransactionListener in project Activiti by Activiti.
the class StandaloneMybatisTransactionContext method fireTransactionEvent.
/**
* Fires the event for the provided {@link TransactionState}.
*
* @param transactionState The {@link TransactionState} for which the listeners will be called.
* @param executeInNewContext If true, the listeners will be called in a new command context.
* This is needed for example when firing the {@link TransactionState#COMMITTED}
* event: the transacation is already committed and executing logic in the same
* context could lead to strange behaviour (for example doing a {@link SqlSession#update(String)}
* would actually roll back the update (as the MyBatis context is already committed
* and the internal flags have not been correctly set).
*/
protected void fireTransactionEvent(TransactionState transactionState, boolean executeInNewContext) {
if (stateTransactionListeners == null) {
return;
}
final List<TransactionListener> transactionListeners = stateTransactionListeners.get(transactionState);
if (transactionListeners == null) {
return;
}
if (executeInNewContext) {
CommandExecutor commandExecutor = commandContext.getProcessEngineConfiguration().getCommandExecutor();
CommandConfig commandConfig = new CommandConfig(false, TransactionPropagation.REQUIRES_NEW);
commandExecutor.execute(commandConfig, new Command<Void>() {
public Void execute(CommandContext commandContext) {
executeTransactionListeners(transactionListeners, commandContext);
return null;
}
});
} else {
executeTransactionListeners(transactionListeners, commandContext);
}
}
use of org.activiti.engine.impl.cfg.TransactionListener in project Activiti by Activiti.
the class JobEntityManager method hintAsyncExecutor.
protected void hintAsyncExecutor(JobEntity job) {
AsyncExecutor asyncExecutor = Context.getProcessEngineConfiguration().getAsyncExecutor();
// notify job executor:
TransactionListener transactionListener = new AsyncJobAddedNotification(job, asyncExecutor);
Context.getCommandContext().getTransactionContext().addTransactionListener(TransactionState.COMMITTED, transactionListener);
}
Aggregations