Search in sources :

Example 16 with CommandContext

use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.

the class CustomMybatisMapperConfigurationTest method executeCustomMybatisXmlQuery.

@Test
public void executeCustomMybatisXmlQuery() throws Exception {
    AnnotationConfigApplicationContext applicationContext = this.context(Application.class);
    ManagementService managementService = applicationContext.getBean(ManagementService.class);
    String processDefinitionDeploymentId = managementService.executeCommand(new Command<String>() {

        @Override
        public String execute(CommandContext commandContext) {
            return (String) commandContext.getDbSqlSession().selectOne("selectProcessDefinitionDeploymentIdByKey", "waiter");
        }
    });
    Assert.assertNotNull("the processDefinitionDeploymentId should not be null!", processDefinitionDeploymentId);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ManagementService(org.activiti.engine.ManagementService) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) Test(org.junit.Test)

Example 17 with CommandContext

use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.

the class ExecutionEntityManager method updateProcessInstanceLockTime.

public void updateProcessInstanceLockTime(String processInstanceId) {
    CommandContext commandContext = Context.getCommandContext();
    Date expirationTime = commandContext.getProcessEngineConfiguration().getClock().getCurrentTime();
    int lockMillis = commandContext.getProcessEngineConfiguration().getAsyncExecutor().getAsyncJobLockTimeInMillis();
    GregorianCalendar lockCal = new GregorianCalendar();
    lockCal.setTime(expirationTime);
    lockCal.add(Calendar.MILLISECOND, lockMillis);
    HashMap<String, Object> params = new HashMap<String, Object>();
    params.put("id", processInstanceId);
    params.put("lockTime", lockCal.getTime());
    params.put("expirationTime", expirationTime);
    int result = getDbSqlSession().update("updateProcessInstanceLockTime", params);
    if (result == 0) {
        throw new ActivitiOptimisticLockingException("Could not lock process instance");
    }
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) HashMap(java.util.HashMap) GregorianCalendar(java.util.GregorianCalendar) ActivitiOptimisticLockingException(org.activiti.engine.ActivitiOptimisticLockingException) Date(java.util.Date)

Example 18 with CommandContext

use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.

the class HistoricProcessInstanceEntityManager method deleteHistoricProcessInstanceById.

@SuppressWarnings("unchecked")
public void deleteHistoricProcessInstanceById(String historicProcessInstanceId) {
    if (getHistoryManager().isHistoryEnabled()) {
        CommandContext commandContext = Context.getCommandContext();
        HistoricProcessInstanceEntity historicProcessInstance = findHistoricProcessInstance(historicProcessInstanceId);
        commandContext.getHistoricDetailEntityManager().deleteHistoricDetailsByProcessInstanceId(historicProcessInstanceId);
        commandContext.getHistoricVariableInstanceEntityManager().deleteHistoricVariableInstanceByProcessInstanceId(historicProcessInstanceId);
        commandContext.getHistoricActivityInstanceEntityManager().deleteHistoricActivityInstancesByProcessInstanceId(historicProcessInstanceId);
        commandContext.getHistoricTaskInstanceEntityManager().deleteHistoricTaskInstancesByProcessInstanceId(historicProcessInstanceId);
        commandContext.getHistoricIdentityLinkEntityManager().deleteHistoricIdentityLinksByProcInstance(historicProcessInstanceId);
        commandContext.getCommentEntityManager().deleteCommentsByProcessInstanceId(historicProcessInstanceId);
        commandContext.getAttachmentEntityManager().deleteAttachmentsByProcessInstanceId(historicProcessInstanceId);
        getDbSqlSession().delete(historicProcessInstance);
        // Also delete any sub-processes that may be active (ACT-821)
        HistoricProcessInstanceQueryImpl subProcessesQueryImpl = new HistoricProcessInstanceQueryImpl();
        subProcessesQueryImpl.superProcessInstanceId(historicProcessInstanceId);
        List<HistoricProcessInstance> selectList = getDbSqlSession().selectList("selectHistoricProcessInstancesByQueryCriteria", subProcessesQueryImpl);
        for (HistoricProcessInstance child : selectList) {
            deleteHistoricProcessInstanceById(child.getId());
        }
    }
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) HistoricProcessInstanceQueryImpl(org.activiti.engine.impl.HistoricProcessInstanceQueryImpl)

Example 19 with CommandContext

use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.

the class HistoricTaskInstanceEntityManager method deleteHistoricTaskInstanceById.

public void deleteHistoricTaskInstanceById(String taskId) {
    if (getHistoryManager().isHistoryEnabled()) {
        HistoricTaskInstanceEntity historicTaskInstance = findHistoricTaskInstanceById(taskId);
        if (historicTaskInstance != null) {
            CommandContext commandContext = Context.getCommandContext();
            List<HistoricTaskInstance> subTasks = findHistoricTasksByParentTaskId(taskId);
            for (HistoricTaskInstance subTask : subTasks) {
                deleteHistoricTaskInstanceById(subTask.getId());
            }
            commandContext.getHistoricDetailEntityManager().deleteHistoricDetailsByTaskId(taskId);
            commandContext.getHistoricVariableInstanceEntityManager().deleteHistoricVariableInstancesByTaskId(taskId);
            commandContext.getCommentEntityManager().deleteCommentsByTaskId(taskId);
            commandContext.getAttachmentEntityManager().deleteAttachmentsByTaskId(taskId);
            commandContext.getHistoricIdentityLinkEntityManager().deleteHistoricIdentityLinksByTaskId(taskId);
            getDbSqlSession().delete(historicTaskInstance);
        }
    }
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) CommandContext(org.activiti.engine.impl.interceptor.CommandContext)

Example 20 with CommandContext

use of org.activiti.engine.impl.interceptor.CommandContext 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.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.activiti.engine.impl.cfg.TransactionListener) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) TransactionContext(org.activiti.engine.impl.cfg.TransactionContext)

Aggregations

CommandContext (org.activiti.engine.impl.interceptor.CommandContext)72 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)18 DbSqlSession (org.activiti.engine.impl.db.DbSqlSession)13 SignalEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity)8 Date (java.util.Date)7 ActivitiException (org.activiti.engine.ActivitiException)7 CommandConfig (org.activiti.engine.impl.interceptor.CommandConfig)7 EventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity)7 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)7 MessageEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity)6 HashMap (java.util.HashMap)4 TimerEntity (org.activiti.engine.impl.persistence.entity.TimerEntity)4 Job (org.activiti.engine.runtime.Job)4 Deployment (org.activiti.engine.test.Deployment)4 ArrayList (java.util.ArrayList)3 GregorianCalendar (java.util.GregorianCalendar)3 List (java.util.List)3 ExtensionElement (org.activiti.bpmn.model.ExtensionElement)3 DynamicBpmnService (org.activiti.engine.DynamicBpmnService)3 JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)3