Search in sources :

Example 1 with TransactionContext

use of org.camunda.bpm.engine.impl.cfg.TransactionContext in project camunda-bpm-platform by camunda.

the class JobRetryCmd method notifyAcquisition.

protected void notifyAcquisition(CommandContext commandContext) {
    JobExecutor jobExecutor = Context.getProcessEngineConfiguration().getJobExecutor();
    MessageAddedNotification messageAddedNotification = new MessageAddedNotification(jobExecutor);
    TransactionContext transactionContext = commandContext.getTransactionContext();
    transactionContext.addTransactionListener(TransactionState.COMMITTED, messageAddedNotification);
}
Also used : MessageAddedNotification(org.camunda.bpm.engine.impl.jobexecutor.MessageAddedNotification) JobExecutor(org.camunda.bpm.engine.impl.jobexecutor.JobExecutor) TransactionContext(org.camunda.bpm.engine.impl.cfg.TransactionContext)

Example 2 with TransactionContext

use of org.camunda.bpm.engine.impl.cfg.TransactionContext in project camunda-bpm-platform by camunda.

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.getCommandContext().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;
}
Also used : TransactionListener(org.camunda.bpm.engine.impl.cfg.TransactionListener) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) TransactionContext(org.camunda.bpm.engine.impl.cfg.TransactionContext)

Aggregations

TransactionContext (org.camunda.bpm.engine.impl.cfg.TransactionContext)2 TransactionListener (org.camunda.bpm.engine.impl.cfg.TransactionListener)1 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)1 JobExecutor (org.camunda.bpm.engine.impl.jobexecutor.JobExecutor)1 MessageAddedNotification (org.camunda.bpm.engine.impl.jobexecutor.MessageAddedNotification)1