一、流程定义部署之ZIP方式
- 上一章节我们使用classpath的方式加载流程定义文件,这里我们使用ZIP的方式。
1.1 用activiti插件生成bpmn和png图片之后,压缩到一个zip格式的压缩包中。
1.2 代码中加载
package com.shyroke.activiti.firstActiviti;
import static org.junit.Assert.*;
import java.io.InputStream;
import java.util.zip.ZipInputStream;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class ProcessDefineTest {
/**
* 获取默认流程引擎实例,会自动读取activiti.cfg.xml文件
*/
private ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
/**
* 部署流程定义使用zip方式
*/
@Test
public void test_deployWithZip() {
InputStream in=this.getClass().getClassLoader().getSystemResourceAsStream("diagrams/HelloWorld.zip");
ZipInputStream zipInputStream=new ZipInputStream(in);
Deployment deployment=processEngine.getRepositoryService()
.createDeployment().addZipInputStream(zipInputStream)
.name("HelloWorld流程2")
.deploy();
System.out.println("流程部署ID:"+deployment.getId());
System.out.println("流程部署Name:"+deployment.getName());
}
}
- act_re_deployment 流程定义部署表新增一条记录
- act_re_procdef 流程定义表中VERSION_字段 版本升级了,KEY依然是一样的;
- act_ge_bytearry 资源文件表,多了两条记录
- 这里再提一个表 act_ge_property 属性表,这里的next_dbid是主键策略,就是规定好了下一次生成的id就是10001;
二、流程定义查询
2.1 查询流程定义 返回流程定义集合 对应表 act_re_procdef
package com.shyroke.activiti.firstActiviti;
import static org.junit.Assert.*;
import java.io.InputStream;
import java.util.List;
import java.util.zip.ZipInputStream;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class ProcessDefineTest2 {
/**
* 获取默认流程引擎实例,会自动读取activiti.cfg.xml文件
*/
private ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
/**
* 查询流程定义 返回流程定义集合 对应表 act_re_procdef
*/
@Test
public void test_list() {
List<ProcessDefinition> pdList=processEngine.getRepositoryService().createProcessDefinitionQuery()
.processDefinitionKey("myFirstProcess")
.list();
for(ProcessDefinition pd:pdList){
System.out.println("ID_"+pd.getId());
System.out.println("NAME_"+pd.getName());
System.out.println("KEY_"+pd.getKey());
System.out.println("VERSION_"+pd.getVersion());
System.out.println("=========");
}
}
}
2.2 通过ID查询某个流程定义
package com.shyroke.activiti.firstActiviti;
import static org.junit.Assert.*;
import java.io.InputStream;
import java.util.List;
import java.util.zip.ZipInputStream;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class ProcessDefineTest2 {
/**
* 获取默认流程引擎实例,会自动读取activiti.cfg.xml文件
*/
private ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
/**
* 通过ID查询某个流程定义
*/
@Test
public void getById(){
String processDefinitionId="myFirstProcess:2:7504";
ProcessDefinition pd=processEngine.getRepositoryService() // 获取service
.createProcessDefinitionQuery() // 创建流程定义查询
.processDefinitionId(processDefinitionId) // 通过id查询
.singleResult();
System.out.println("ID_"+pd.getId());
System.out.println("NAME_"+pd.getName());
System.out.println("KEY_"+pd.getKey());
System.out.println("VERSION_"+pd.getVersion());
}
}