use of org.camunda.bpm.engine.impl.interceptor.CommandExecutor in project camunda-bpm-platform by camunda.
the class JobMigrationScenario method triggerEntryCriterion.
@DescribesScenario("createJob")
public static ScenarioSetup triggerEntryCriterion() {
return new ScenarioSetup() {
public void execute(ProcessEngine engine, final String scenarioName) {
final ProcessEngineConfigurationImpl engineConfiguration = (ProcessEngineConfigurationImpl) engine.getProcessEngineConfiguration();
CommandExecutor commandExecutor = engineConfiguration.getCommandExecutorTxRequired();
// create a job with the scenario name as id and a null suspension state
commandExecutor.execute(new Command<Void>() {
public Void execute(CommandContext commandContext) {
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
try {
SqlSession sqlSession = commandContext.getDbSqlSession().getSqlSession();
connection = sqlSession.getConnection();
statement = connection.createStatement();
statement.executeUpdate("INSERT INTO ACT_RU_JOB(ID_, REV_, RETRIES_, TYPE_, EXCLUSIVE_, HANDLER_TYPE_) " + "VALUES (" + "'" + scenarioName + "'," + "1," + "3," + "'timer'," + DbSqlSessionFactory.databaseSpecificTrueConstant.get(engineConfiguration.getDatabaseType()) + "," + "'" + TimerStartEventJobHandler.TYPE + "'" + ")");
connection.commit();
statement.close();
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
try {
if (statement != null) {
statement.close();
}
if (rs != null) {
rs.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
return null;
}
});
}
};
}
use of org.camunda.bpm.engine.impl.interceptor.CommandExecutor in project camunda-bpm-platform by camunda.
the class StartTimerEventTest method cleanDB.
private void cleanDB() {
String jobId = managementService.createJobQuery().singleResult().getId();
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
commandExecutor.execute(new DeleteJobsCmd(jobId, true));
}
use of org.camunda.bpm.engine.impl.interceptor.CommandExecutor in project camunda-bpm-platform by camunda.
the class ExecutionTree method forExecution.
public static ExecutionTree forExecution(final String executionId, ProcessEngine processEngine) {
ProcessEngineConfigurationImpl configuration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
CommandExecutor commandExecutor = configuration.getCommandExecutorTxRequired();
ExecutionTree executionTree = commandExecutor.execute(new Command<ExecutionTree>() {
public ExecutionTree execute(CommandContext commandContext) {
ExecutionEntity execution = commandContext.getExecutionManager().findExecutionById(executionId);
return ExecutionTree.forExecution(execution);
}
});
return executionTree;
}
use of org.camunda.bpm.engine.impl.interceptor.CommandExecutor in project camunda-bpm-platform by camunda.
the class UserOperationLogQueryTest method testQueryJobDefinitionOperationWithDelayedJobDefinition.
@Deployment(resources = { ONE_TASK_PROCESS })
public void testQueryJobDefinitionOperationWithDelayedJobDefinition() {
// given
// a running process instance
ProcessInstance process = runtimeService.startProcessInstanceByKey("oneTaskProcess");
// with a process definition id
String processDefinitionId = process.getProcessDefinitionId();
// ...which will be suspended with the corresponding jobs
managementService.suspendJobDefinitionByProcessDefinitionId(processDefinitionId, true);
// one week from now
ClockUtil.setCurrentTime(today);
long oneWeekFromStartTime = today.getTime() + (7 * 24 * 60 * 60 * 1000);
// when
// activate the job definition
managementService.activateJobDefinitionByProcessDefinitionId(processDefinitionId, false, new Date(oneWeekFromStartTime));
// then
// there is a user log entry for the activation
Long jobDefinitionEntryCount = query().entityType(JOB_DEFINITION).operationType(UserOperationLogEntry.OPERATION_TYPE_ACTIVATE_JOB_DEFINITION).processDefinitionId(processDefinitionId).count();
assertEquals(1, jobDefinitionEntryCount.longValue());
// there exists a job for the delayed activation execution
JobQuery jobQuery = managementService.createJobQuery();
Job delayedActivationJob = jobQuery.timers().active().singleResult();
assertNotNull(delayedActivationJob);
// execute job
managementService.executeJob(delayedActivationJob.getId());
jobDefinitionEntryCount = query().entityType(JOB_DEFINITION).operationType(UserOperationLogEntry.OPERATION_TYPE_ACTIVATE_JOB_DEFINITION).processDefinitionId(processDefinitionId).count();
assertEquals(1, jobDefinitionEntryCount.longValue());
// Clean up db
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
commandExecutor.execute(new Command<Object>() {
public Object execute(CommandContext commandContext) {
commandContext.getHistoricJobLogManager().deleteHistoricJobLogsByHandlerType(TimerActivateJobDefinitionHandler.TYPE);
return null;
}
});
}
use of org.camunda.bpm.engine.impl.interceptor.CommandExecutor in project camunda-bpm-platform by camunda.
the class UserOperationLogQueryTest method testQueryProcessDefinitionOperationWithDelayedProcessDefinition.
@Deployment(resources = { "org/camunda/bpm/engine/test/api/repository/ProcessDefinitionSuspensionTest.testWithOneAsyncServiceTask.bpmn" })
public void testQueryProcessDefinitionOperationWithDelayedProcessDefinition() {
// given
ClockUtil.setCurrentTime(today);
final long hourInMs = 60 * 60 * 1000;
String key = "oneFailingServiceTaskProcess";
// a running process instance with a failed service task
Map<String, Object> params = new HashMap<String, Object>();
params.put("fail", Boolean.TRUE);
runtimeService.startProcessInstanceByKey(key, params);
// when
// the process definition will be suspended
repositoryService.suspendProcessDefinitionByKey(key, false, new Date(today.getTime() + (2 * hourInMs)));
// then
// there exists a timer job to suspend the process definition delayed
Job timerToSuspendProcessDefinition = managementService.createJobQuery().timers().singleResult();
assertNotNull(timerToSuspendProcessDefinition);
// there is a user log entry for the activation
Long processDefinitionEntryCount = query().entityType(PROCESS_DEFINITION).operationType(UserOperationLogEntry.OPERATION_TYPE_SUSPEND_PROCESS_DEFINITION).processDefinitionKey(key).count();
assertEquals(1, processDefinitionEntryCount.longValue());
// when
// execute job
managementService.executeJob(timerToSuspendProcessDefinition.getId());
// then
// there is a user log entry for the activation
processDefinitionEntryCount = query().entityType(PROCESS_DEFINITION).operationType(UserOperationLogEntry.OPERATION_TYPE_SUSPEND_PROCESS_DEFINITION).processDefinitionKey(key).count();
assertEquals(1, processDefinitionEntryCount.longValue());
// clean up op log
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
commandExecutor.execute(new Command<Object>() {
public Object execute(CommandContext commandContext) {
commandContext.getHistoricJobLogManager().deleteHistoricJobLogsByHandlerType(TimerSuspendProcessDefinitionHandler.TYPE);
return null;
}
});
}
Aggregations