Search in sources :

Example 1 with CommandExecutor

use of org.camunda.bpm.engine.impl.interceptor.CommandExecutor in project camunda-bpm-platform by camunda.

the class DbSchemaPrune method main.

public static void main(String[] args) {
    ProcessEngineImpl processEngine = (ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine();
    CommandExecutor commandExecutor = processEngine.getProcessEngineConfiguration().getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Object>() {

        public Object execute(CommandContext commandContext) {
            commandContext.getSession(PersistenceSession.class).dbSchemaPrune();
            return null;
        }
    });
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) ProcessEngineImpl(org.camunda.bpm.engine.impl.ProcessEngineImpl)

Example 2 with CommandExecutor

use of org.camunda.bpm.engine.impl.interceptor.CommandExecutor in project camunda-bpm-platform by camunda.

the class DbSchemaDrop method main.

public static void main(String[] args) {
    ProcessEngineImpl processEngine = (ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine();
    CommandExecutor commandExecutor = processEngine.getProcessEngineConfiguration().getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Object>() {

        public Object execute(CommandContext commandContext) {
            commandContext.getSession(PersistenceSession.class).dbSchemaDrop();
            return null;
        }
    });
    processEngine.close();
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) ProcessEngineImpl(org.camunda.bpm.engine.impl.ProcessEngineImpl)

Example 3 with CommandExecutor

use of org.camunda.bpm.engine.impl.interceptor.CommandExecutor in project camunda-bpm-platform by camunda.

the class IncidentAuthorizationTest method clearDatabase.

protected void clearDatabase() {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Object>() {

        public Object execute(CommandContext commandContext) {
            HistoryLevel historyLevel = Context.getProcessEngineConfiguration().getHistoryLevel();
            if (historyLevel.equals(HistoryLevel.HISTORY_LEVEL_FULL)) {
                commandContext.getHistoricJobLogManager().deleteHistoricJobLogsByHandlerType(TimerSuspendProcessDefinitionHandler.TYPE);
                List<HistoricIncident> incidents = Context.getProcessEngineConfiguration().getHistoryService().createHistoricIncidentQuery().list();
                for (HistoricIncident incident : incidents) {
                    commandContext.getHistoricIncidentManager().delete((HistoricIncidentEntity) incident);
                }
            }
            return null;
        }
    });
}
Also used : HistoricIncident(org.camunda.bpm.engine.history.HistoricIncident) HistoricIncidentEntity(org.camunda.bpm.engine.impl.persistence.entity.HistoricIncidentEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) HistoryLevel(org.camunda.bpm.engine.impl.history.HistoryLevel) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) List(java.util.List)

Example 4 with CommandExecutor

use of org.camunda.bpm.engine.impl.interceptor.CommandExecutor in project camunda-bpm-platform by camunda.

the class DatabaseTableSchemaTest method testTablePresentWithSchemaAndPrefix.

public void testTablePresentWithSchemaAndPrefix() throws SQLException {
    PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.getClassLoader(), "org.h2.Driver", "jdbc:h2:mem:DatabaseTablePrefixTest;DB_CLOSE_DELAY=1000", "sa", "");
    Connection connection = pooledDataSource.getConnection();
    connection.createStatement().execute("drop schema if exists " + SCHEMA_NAME);
    connection.createStatement().execute("create schema " + SCHEMA_NAME);
    connection.createStatement().execute("create table " + SCHEMA_NAME + "." + PREFIX_NAME + "SOME_TABLE(id varchar(64));");
    connection.close();
    ProcessEngineConfigurationImpl config1 = createCustomProcessEngineConfiguration().setProcessEngineName("DatabaseTablePrefixTest-engine1").setDataSource(pooledDataSource).setDatabaseSchemaUpdate("NO_CHECK");
    config1.setDatabaseTablePrefix(SCHEMA_NAME + "." + PREFIX_NAME);
    config1.setDatabaseSchema(SCHEMA_NAME);
    config1.setDbMetricsReporterActivate(false);
    ProcessEngine engine = config1.buildProcessEngine();
    CommandExecutor commandExecutor = config1.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            DbSqlSession sqlSession = commandContext.getSession(DbSqlSession.class);
            assertTrue(sqlSession.isTablePresent("SOME_TABLE"));
            return null;
        }
    });
    engine.close();
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) Connection(java.sql.Connection) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) PooledDataSource(org.apache.ibatis.datasource.pooled.PooledDataSource) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) DbSqlSession(org.camunda.bpm.engine.impl.db.sql.DbSqlSession)

Example 5 with CommandExecutor

use of org.camunda.bpm.engine.impl.interceptor.CommandExecutor in project camunda-bpm-platform by camunda.

the class SetProcessDefinitionVersionCmdTest method testSetProcessDefinitionVersionMigrateJob.

@Deployment(resources = TEST_PROCESS_ONE_JOB)
public void testSetProcessDefinitionVersionMigrateJob() {
    // given a process instance
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneJobProcess");
    // with a job
    Job job = managementService.createJobQuery().singleResult();
    assertNotNull(job);
    // and a second deployment of the process
    org.camunda.bpm.engine.repository.Deployment deployment = repositoryService.createDeployment().addClasspathResource(TEST_PROCESS_ONE_JOB).deploy();
    ProcessDefinition newDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
    assertNotNull(newDefinition);
    // when the process instance is migrated
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new SetProcessDefinitionVersionCmd(instance.getId(), 2));
    // then the the job should also be migrated
    Job migratedJob = managementService.createJobQuery().singleResult();
    assertNotNull(migratedJob);
    assertEquals(job.getId(), migratedJob.getId());
    assertEquals(newDefinition.getId(), migratedJob.getProcessDefinitionId());
    assertEquals(deployment.getId(), migratedJob.getDeploymentId());
    JobDefinition newJobDefinition = managementService.createJobDefinitionQuery().processDefinitionId(newDefinition.getId()).singleResult();
    assertNotNull(newJobDefinition);
    assertEquals(newJobDefinition.getId(), migratedJob.getJobDefinitionId());
    repositoryService.deleteDeployment(deployment.getId(), true);
}
Also used : CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) SetProcessDefinitionVersionCmd(org.camunda.bpm.engine.impl.cmd.SetProcessDefinitionVersionCmd) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) Job(org.camunda.bpm.engine.runtime.Job) JobDefinition(org.camunda.bpm.engine.management.JobDefinition) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)53 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)31 Deployment (org.camunda.bpm.engine.test.Deployment)17 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)15 SetProcessDefinitionVersionCmd (org.camunda.bpm.engine.impl.cmd.SetProcessDefinitionVersionCmd)13 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)11 Job (org.camunda.bpm.engine.runtime.Job)9 Date (java.util.Date)8 List (java.util.List)7 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)7 Execution (org.camunda.bpm.engine.runtime.Execution)6 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)5 HistoricIncident (org.camunda.bpm.engine.history.HistoricIncident)5 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)5 AcquireJobsCmd (org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd)5 AcquiredJobs (org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs)5 JobExecutor (org.camunda.bpm.engine.impl.jobexecutor.JobExecutor)5 JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)5 HistoricIncidentEntity (org.camunda.bpm.engine.impl.persistence.entity.HistoricIncidentEntity)4 MessageEntity (org.camunda.bpm.engine.impl.persistence.entity.MessageEntity)4