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);
}
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");
}
}
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());
}
}
}
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);
}
}
}
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;
}
Aggregations