An overview,

Description: After a process is started, each process instance has an execution flow (stored in the ACT_RU_execution table). Each instance has a main execution flow, and an execution flow without a parent ID is a process instance, followed by a child execution flow if there is a branch in the process, and the branch corresponds to the child execution flow. You can set variables for the execution flow, setting variables for the child execution flow to local (temporary) variables (valid for the current execution flow), and setting variables for the main execution flow to global variables.

Second, the execution flow view

  1. A branch of process testing.
  • The flow chart is as follows:
  • Deploy directly using code
	ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
	RepositoryService repositoryService = processEngine.getRepositoryService();
	RuntimeService runtimeService = processEngine.getRuntimeService();

	// Publish resources
	Deployment deployment = repositoryService.createDeployment().addClasspathResource("single.bpmn").deploy();

	// Get the process definition
	ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();

	// Get the process instance
	ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());

	// Prints the process instance ID, which is the main execution flow. Results: 97505
	System.out.println(processInstance.getId());

	/ / close
	processEngine.close();
	System.exit(0);
Copy the code
  • View the database (act_ru_execution)
  1. A multi-branch process.
  • The flow chart is as follows:
  • Deployment is the same as a branch
  • Viewing a Database

Start process “BUSINESS_KEY_”

Summary:

  • “BUSINESS_KEY_” is the business primary key, which is used by the main process. In addition, this business primary key field has unique constraints in the table, and can be queried using this value. The business primary key can set a value when the process is started, using an overloaded method of the startProcessInstanceById() method, stored in the BUSINESS_KEY_ field of act_ru_execution. Here are the tests.
  • Test methods on the startup process way is using a runtimeService. StartProcessInstanceById () method, Another runtimeService startProcessInstanceByKey (String processDefinitionKey) can also be started, one of the key process definition, the corresponding BPMN files process id tags.

Testing:

  1. 2. The key codes are as follows:
	// Get the process definition
	ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();

	// Get the process instance, where the second parameter corresponds to BUSINESS_KEY_ of the act_RU_execution database
	ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId(), "abc");
Copy the code
  1. Viewing a Database

Local (local) and global variables of the execution flow

** Overview: ** You can set local and global variables for execution flow. Local variables are valid for the current execution flow, and if the current execution flow completes, the local variables in the database are removed and no longer usable. Global variables are bound to the main execution flow and persist in the current process instance. The tests are as follows:

  1. The flow chart is as follows:
  2. The encoding is as follows:
	ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
	RepositoryService repositoryService = processEngine.getRepositoryService();
	RuntimeService runtimeService = processEngine.getRuntimeService();
	TaskService taskService = processEngine.getTaskService();

	Deployment deployment = repositoryService.createDeployment().addClasspathResource("scope.bpmn").deploy();

	ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();

	ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
	System.out.println("Process instance ID:" + processInstance.getId());

	System.out.println("= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =");

	// Query task, the first time the two tasks are parallel, so there will be two tasks
	List<Task> taskList = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();

	taskList.forEach(tempTask-> {
			// First query the execution flow
			Execution execution = runtimeService.createExecutionQuery().executionId(tempTask.getExecutionId()).singleResult();

			if ("TaskA".equals(tempTask.getName())){
					// Set the local variable to flow A, that is, to execute in the current flow. This variable is deleted if the current execution stream is complete. Bound to the execution flow
					runtimeService.setVariableLocal(execution.getId(),"taskVarA"."varA");
					System.out.println("Complete setting local variable varA for execution flow TaskA");
			}else {
					// Set global variables for execution flow B, which are available in the current instance and are directly bound to the process instance
					runtimeService.setVariable(execution.getId(),"taskVarB"."varB");
					runtimeService.setVariable(execution.getId(),"taskVarB2"."varB2");
					System.out.println("Complete setting global variables varB and varB2 for execution stream TaskB"); }});// Pause temporarily for 30 seconds to check database changes
	Thread.sleep(30000);

	// After TaskA and TaskB are completed, TaskC can be used to query parameters
	taskList.forEach(task -> taskService.complete(task.getId()));

	System.out.println("= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =");

	// Query parameters
	Task taskC = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
	System.out.println("Current Task:" + taskC.getName() + ". Get the execution flow parameters as follows:");
	System.out.println(runtimeService.getVariable(taskC.getExecutionId(), "taskVarA"));
	System.out.println(runtimeService.getVariable(taskC.getExecutionId(), "taskVarB"));

	processEngine.close();
	System.exit(0);
Copy the code
  1. Viewing a Database
  • TaskA and TaskB preceded Complete

    The execution flow is as follows:

    The variables are as follows (act_ru_variable table), where the global variable is bound and EXECUTION_ID_ is the main execution flow:

  • After complete

    The execution flow is as follows, where TaskA and TaskB are missing, depending on the ACT_ID_ difference:

    Variables, you can see that local variables are deleted, and only global variables are saved:

Mortals fly