org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration Java Examples

The following examples show how to use org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ActivitiPlugin.java    From my_curd with Apache License 2.0 6 votes vote down vote up
/**
 * 创建工作流引擎
 * @return
 */
private Boolean createProcessEngine(){
    if (processEngine != null) {
        return true;
    }
    StandaloneProcessEngineConfiguration conf =
            (StandaloneProcessEngineConfiguration) ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
    conf.setDataSource(DbKit.getConfig().getDataSource())
        .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE) // 自动更新数据库表
        .setDbHistoryUsed(true);                                                   // 历史表生效功能
    // conf.setTransactionsExternallyManaged(true); // 使用托管事务工厂(不配置,事务也可生效)


    conf.setTransactionFactory(new ActivitiTransactionFactory());

    ActivitiPlugin.processEngine = conf.buildProcessEngine();
    return true;
}
 
Example #2
Source File: ActivitiConfig.java    From acitviti6.0 with MIT License 5 votes vote down vote up
/**
 * 初始化配置,将创建28张表
 * @return
 */
@Bean
public StandaloneProcessEngineConfiguration processEngineConfiguration() {
    StandaloneProcessEngineConfiguration configuration = new StandaloneProcessEngineConfiguration();
    configuration.setDataSource(dataSource);
    configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
    configuration.setAsyncExecutorActivate(false);
    return configuration;
}
 
Example #3
Source File: SpringProcessEngineConfiguration.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public CommandInterceptor createTransactionInterceptor() {
  if (transactionManager == null) {
    throw new ActivitiException("transactionManager is required property for SpringProcessEngineConfiguration, use " + StandaloneProcessEngineConfiguration.class.getName() + " otherwise");
  }

  return new SpringTransactionInterceptor(transactionManager);
}
 
Example #4
Source File: DefaultProcessEngineFactory.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Takes in an Activiti 6 process engine config, gives back an Activiti 5 Process engine.
 */
public ProcessEngine buildProcessEngine(ProcessEngineConfigurationImpl activiti6Configuration) {
  org.activiti5.engine.impl.cfg.ProcessEngineConfigurationImpl activiti5Configuration = null;
  if (activiti6Configuration instanceof StandaloneProcessEngineConfiguration) {
    activiti5Configuration = new org.activiti5.engine.impl.cfg.StandaloneProcessEngineConfiguration();
    copyConfigItems(activiti6Configuration, activiti5Configuration);
    return activiti5Configuration.buildProcessEngine();
  } else {
    throw new ActivitiException("Unsupported process engine configuration");
  }
}
 
Example #5
Source File: ConfigurationFactory.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public StandaloneProcessEngineConfiguration getConfiguration() {
  StandaloneProcessEngineConfiguration conf = new StandaloneProcessEngineConfiguration();
  conf.setDataSource(dataSource);
  conf.setDatabaseSchemaUpdate(databaseSchemaUpdate);
  conf.setAsyncExecutorActivate(jobExecutorActivate);
  return conf;
}
 
Example #6
Source File: SpringProcessEngineConfiguration.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
protected CommandInterceptor createTransactionInterceptor() {
    if (transactionManager == null) {
        throw new ActivitiException("transactionManager is required property for SpringProcessEngineConfiguration, use " + StandaloneProcessEngineConfiguration.class.getName() + " otherwise");
    }

    return new SpringTransactionInterceptor(transactionManager);
}
 
Example #7
Source File: ProcessEngineConfiguration.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public static ProcessEngineConfiguration createStandaloneProcessEngineConfiguration() {
  return new StandaloneProcessEngineConfiguration();
}
 
Example #8
Source File: ProcessDefinitionCacheTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testStartProcessInstanceByIdAfterReboot() {

    // In case this test is run in a test suite, previous engines might
    // have been initialized and cached. First we close the
    // existing process engines to make sure that the db is clean
    // and that there are no existing process engines involved.
    ProcessEngines.destroy();

    // Creating the DB schema (without building a process engine)
    ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneInMemProcessEngineConfiguration();
    processEngineConfiguration.setProcessEngineName("reboot-test-schema");
    processEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000");
    ProcessEngine schemaProcessEngine = processEngineConfiguration.buildProcessEngine();

    // Create process engine and deploy test process
    ProcessEngine processEngine = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test").setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
        .setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000").setAsyncExecutorActivate(false).buildProcessEngine();

    processEngine.getRepositoryService().createDeployment().addClasspathResource("org/activiti/engine/test/cache/originalProcess.bpmn20.xml").deploy();

    // verify existence of process definition
    List<ProcessDefinition> processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().list();

    assertEquals(1, processDefinitions.size());

    // Start a new Process instance
    ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId());
    String processInstanceId = processInstance.getId();
    assertNotNull(processInstance);

    // Close the process engine
    processEngine.close();
    assertNotNull(processEngine.getRuntimeService());

    // Reboot the process engine
    processEngine = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test").setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
        .setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000").setAsyncExecutorActivate(false).buildProcessEngine();

    // Check if the existing process instance is still alive
    processInstance = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();

    assertNotNull(processInstance);

    // Complete the task. That will end the process instance
    TaskService taskService = processEngine.getTaskService();
    Task task = taskService.createTaskQuery().list().get(0);
    taskService.complete(task.getId());

    // Check if the process instance has really ended. This means that the
    // process definition has
    // re-loaded into the process definition cache
    processInstance = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();

    assertNull(processInstance);

    // Extra check to see if a new process instance can be started as well
    processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId());
    assertNotNull(processInstance);

    // close the process engine
    processEngine.close();

    // Cleanup schema
    schemaProcessEngine.close();
  }
 
Example #9
Source File: ProcessDefinitionCacheTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testDeployRevisedProcessAfterDeleteOnOtherProcessEngine() {

    // Setup both process engines
    ProcessEngine processEngine1 = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test-schema")
        .setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE).setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000")
        .setAsyncExecutorActivate(false).buildProcessEngine();
    RepositoryService repositoryService1 = processEngine1.getRepositoryService();

    ProcessEngine processEngine2 = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test")
        .setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE).setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000")
        .setAsyncExecutorActivate(false).buildProcessEngine();
    RepositoryService repositoryService2 = processEngine2.getRepositoryService();
    RuntimeService runtimeService2 = processEngine2.getRuntimeService();
    TaskService taskService2 = processEngine2.getTaskService();

    // Deploy first version of process: start->originalTask->end on first
    // process engine
    String deploymentId = repositoryService1.createDeployment().addClasspathResource("org/activiti/engine/test/cache/originalProcess.bpmn20.xml").deploy().getId();

    // Start process instance on second engine
    String processDefinitionId = repositoryService2.createProcessDefinitionQuery().singleResult().getId();
    runtimeService2.startProcessInstanceById(processDefinitionId);
    Task task = taskService2.createTaskQuery().singleResult();
    assertEquals("original task", task.getName());

    // Delete the deployment on second process engine
    repositoryService2.deleteDeployment(deploymentId, true);
    assertEquals(0, repositoryService2.createDeploymentQuery().count());
    assertEquals(0, runtimeService2.createProcessInstanceQuery().count());

    // deploy a revised version of the process: start->revisedTask->end on
    // first process engine
    //
    // Before the bugfix, this would set the cache on the first process
    // engine,
    // but the second process engine still has the original process
    // definition in his cache.
    // Since there is a deployment delete in between, the new generated
    // process definition id is the same
    // as in the original deployment, making the second process engine using
    // the old cached process definition.
    deploymentId = repositoryService1.createDeployment().addClasspathResource("org/activiti/engine/test/cache/revisedProcess.bpmn20.xml").deploy().getId();

    // Start process instance on second process engine -> must use revised
    // process definition
    repositoryService2.createProcessDefinitionQuery().singleResult().getId();
    runtimeService2.startProcessInstanceByKey("oneTaskProcess");
    task = taskService2.createTaskQuery().singleResult();
    assertEquals("revised task", task.getName());

    // cleanup
    repositoryService1.deleteDeployment(deploymentId, true);
    processEngine1.close();
    processEngine2.close();
  }
 
Example #10
Source File: ProcessDefinitionCacheTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testDeployRevisedProcessAfterDeleteOnOtherProcessEngine() {
  
  // Setup both process engines
  StandaloneProcessEngineConfiguration standaloneProcessEngineConfiguration = new StandaloneProcessEngineConfiguration();
  standaloneProcessEngineConfiguration.setProcessEngineName("reboot-test-schema");
  standaloneProcessEngineConfiguration.setDatabaseSchemaUpdate(org.activiti5.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
  standaloneProcessEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000");
  standaloneProcessEngineConfiguration.setAsyncExecutorActivate(false);
  standaloneProcessEngineConfiguration.setActiviti5CompatibilityEnabled(true);
  ProcessEngine processEngine1 = standaloneProcessEngineConfiguration.buildProcessEngine();
  RepositoryService repositoryService1 = processEngine1.getRepositoryService();
  
  StandaloneProcessEngineConfiguration standaloneProcessEngineConfiguration2 = new StandaloneProcessEngineConfiguration();
  standaloneProcessEngineConfiguration2.setProcessEngineName("reboot-test");
  standaloneProcessEngineConfiguration2.setDatabaseSchemaUpdate(org.activiti5.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE);
  standaloneProcessEngineConfiguration2.setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000");
  standaloneProcessEngineConfiguration2.setAsyncExecutorActivate(false);
  standaloneProcessEngineConfiguration2.setActiviti5CompatibilityEnabled(true);
  ProcessEngine processEngine2  = standaloneProcessEngineConfiguration2.buildProcessEngine();
  RepositoryService repositoryService2 = processEngine2.getRepositoryService();
  RuntimeService runtimeService2 = processEngine2.getRuntimeService();
  TaskService taskService2 = processEngine2.getTaskService();
  
  // Deploy first version of process: start->originalTask->end on first process engine
  String deploymentId = repositoryService1.createDeployment()
    .addClasspathResource("org/activiti5/engine/test/cache/originalProcess.bpmn20.xml")
    .deploymentProperty(DeploymentProperties.DEPLOY_AS_ACTIVITI5_PROCESS_DEFINITION, Boolean.TRUE)
    .deploy()
    .getId();
  
  // Start process instance on second engine
  String processDefinitionId = repositoryService2.createProcessDefinitionQuery().singleResult().getId();
  runtimeService2.startProcessInstanceById(processDefinitionId);
  Task task = taskService2.createTaskQuery().singleResult();
  assertEquals("original task", task.getName());
  
  // Delete the deployment on second process engine
  repositoryService2.deleteDeployment(deploymentId, true);
  assertEquals(0, repositoryService2.createDeploymentQuery().count());
  assertEquals(0, runtimeService2.createProcessInstanceQuery().count());
  
  // deploy a revised version of the process: start->revisedTask->end on first process engine
  //
  // Before the bugfix, this would set the cache on the first process engine,
  // but the second process engine still has the original process definition in his cache.
  // Since there is a deployment delete in between, the new generated process definition id is the same 
  // as in the original deployment, making the second process engine using the old cached process definition.
  deploymentId = repositoryService1.createDeployment()
    .addClasspathResource("org/activiti5/engine/test/cache/revisedProcess.bpmn20.xml")
    .deploymentProperty(DeploymentProperties.DEPLOY_AS_ACTIVITI5_PROCESS_DEFINITION, Boolean.TRUE)
    .deploy()
    .getId();
  
  // Start process instance on second process engine -> must use revised process definition
  repositoryService2.createProcessDefinitionQuery().singleResult().getId();
  runtimeService2.startProcessInstanceByKey("oneTaskProcess");
  task = taskService2.createTaskQuery().singleResult();
  assertEquals("revised task", task.getName());
  
  // cleanup
  repositoryService1.deleteDeployment(deploymentId, true);
  processEngine1.close();
  processEngine2.close();
}
 
Example #11
Source File: ProcessEngineConfiguration.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public static ProcessEngineConfiguration createStandaloneProcessEngineConfiguration() {
    return new StandaloneProcessEngineConfiguration();
}