流程部署创建主要影响以下几张表
ACT_RE_*:’RE’表示repository(存储)。RepositoryService接口操作的表。带此前缀的表包含的是静态信息,如,流程定义,流程的资源(图片,规则等)。
表名 | 说明 |
---|---|
ACT_GE_BYTEARRAY | 流程定义和流程资源 |
ACT_RE_DEPLOYMENT | 部署单元信息 |
ACT_RE_MODEL | 模型信息(主要针对于flowable在线设计器) |
ACT_RE_PROCDEF | 流程定义数据表 |
flowable流程创建是由DeploymentBuilder接口提供,支持以下几种方式创建:
DeploymentBuilder addInputStream(String var1, InputStream var2);
DeploymentBuilder addClasspathResource(String var1);
DeploymentBuilder addString(String var1, String var2);
DeploymentBuilder addBytes(String var1, byte[] var2);
DeploymentBuilder addZipInputStream(ZipInputStream var1);
DeploymentBuilder addBpmnModel(String var1, BpmnModel var2);
addInputStream输入流创建:
//在resources文件夹下创建 org/flowable/engine/test/repository/one.bpmn20.xml
InputStream bpmnInputStream = this.getClass().getClassLoader().getResourceAsStream("org/flowable/engine/test/repository/one.bpmn20.xml");
Deployment deployment = repositoryService.createDeployment()
.addInputStream("one.bpmn20.xml", bpmnInputStream)
.deploy();
以上创建部署时的方法返回的结果还是DeploymentBuilder接口 。所以,如果要是创建多个bpmn,可以在后面追加如下代码:
Deployment deployment = repositoryService.createDeployment()
.addInputStream("one.bpmn20.xml", bpmnInputStream)
.addInputStream("two.bpmn20.xml", bpmnInputStream)
.deploy();
addClasspathResource (springboot项目会常用),resources文件夹下创建:
repositoryService.createDeployment().addClasspathResource("org/flowable/engine/test/db/processOne.bpmn20.xml").deploy();
此种方式,无需转换成InputStream
addString方式,可以通过字符串直接进行创建:
private static String UNSAFE_XML = "" + "" + "" + "" + ""
+ "" + ""
+ "" + ""
+ "" + ""
+ "" + "]>" + "&lol9; " + "" + ""
+ " This is a process for testing purposes " + " " + " "
+ " " + " " + " " + " " + " ";
repositoryService.createDeployment().addString("test.bpmn20.xml", UNSAFE_XML).deploy().getId();
addBytes字节方式:
可以根据上面的addString方式进行修改,将UNSAFE_XML字符串转换为Bytes[]数组
repositoryService.createDeployment().addString("Bytes[]方式测试", String.valueOf(UNSAFE_XML .getBytes("UTF-8"))).deploy();
addZipInputStream zip压缩包方式:
InputStream inputStream = this.getClass()
.getClassLoader()
.getResourceAsStream("org/flowable/engine/test/api/repository/test-processes.zip");
addBpmnModel BpmnModel模型方式创建:
org.flowable.bpmn.model.Process process = new org.flowable.bpmn.model.Process();
process.setId("oneTaskProcess");
process.setName("The one task process");
StartEvent startEvent = new StartEvent();
startEvent.setId("start");
startEvent.setName("The start");
process.addFlowElement(startEvent);
UserTask userTask = new UserTask();
userTask.setName("The Task");
userTask.setId("theTask");
userTask.setAssignee("kermit");
process.addFlowElement(userTask);
EndEvent endEvent = new EndEvent();
endEvent.setId("theEnd");
endEvent.setName("The end");
process.addFlowElement(endEvent);
process.addFlowElement(new SequenceFlow("start", "theTask"));
process.addFlowElement(new SequenceFlow("theTask", "theEnd"));
BpmnModel model = new BpmnModel();
model.addProcess(process);
repositoryService.createDeployment().addBpmnModel("模型方式创建流程", model).deploy();
最后:注意,无论哪种方式加载 模型名称 也就是 resourcesName 结尾必须以bpmn20.xml, bpmn为结尾,不然不会插入ACT_RE_PROCDEF 流程定义表,源码位置ParsedDeploymentBuilder.class->build()
while(true) {
EngineResource resource;
do {
if (!var5.hasNext()) {
return new ParsedDeployment(deploymentEntity, processDefinitions, processDefinitionsToBpmnParseMap, processDefinitionsToResourceMap);
}
resource = (EngineResource)var5.next();
} while(!this.isBpmnResource(resource.getName()));//此处根据名称判断是否符合规规范
LOGGER.debug("Processing BPMN resource {}", resource.getName());
BpmnParse parse = this.createBpmnParseFromResource(resource);
Iterator var8 = parse.getProcessDefinitions().iterator();
while(var8.hasNext()) {
ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity)var8.next();
processDefinitions.add(processDefinition);
processDefinitionsToBpmnParseMap.put(processDefinition, parse);
processDefinitionsToResourceMap.put(processDefinition, resource);
}
}