JBPM入门
jbpm.hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> |
通过hibernate生成表的测试代码:
package com.xjz.jbpm.db; import org.hibernate.cfg.Configuration; public class CreateDB { |
JBPM4.4的API测试代码:
package com.xjz.jbpm.pd; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.util.List; import java.util.zip.ZipInputStream; import org.jbpm.api.Configuration; import org.jbpm.api.Deployment; import org.jbpm.api.ProcessDefinition; import org.jbpm.api.ProcessEngine; import org.junit.Test; /** * 流程定义管理 * 1.流程定义 * 2.把流程定义文档布署到jbpm中 * 3.查询 * 查询所有的流程定义 * 根据deploymentId查询流程定义 * 根据pdid查询流程定义 * 根据pdkey查询流程定义 * 4.删除 * 5.查看流程图 * @author Administrator * */ public class PDManager { /** * 流程布署涉及到的表 * JBPM4_PROPERTY(版本的表,不用理) * JBPM4_DEPLOYMENT(布署表,用来描述一次布署) * 字段说明: * DBID_:主键\部署ID * STATE:状态 active * JBPM4_LOB(仓库表,存放了流程定义文档\图片) * 字段说明: * DEPLOYMENT_:部署ID 外键 * NAME:XML或PNG的文件路径 * JBPM4_DEPLOYPROP(布署属性表) * 字段说明: * DBID_:主键 * OBJNAME_:流程定义名称 * KEY_: * 每布署一次生成4行记录 * langid 语言版本 jpdl-4.4 * pdid pdkey-version * pdkey 流程定义名称 * 一般情况下pdkey objname_的值是一样的 * pdversion 版本号 * 如果pdkey没有发生改变,每部署一次,版本号加1 * 如果pdkey发生改变,则是一个全新的名称,所以版本号应该从1开始计算 */ @Test public void testDeployFromClassPath(){ ProcessEngine processEngine = Configuration.getProcessEngine(); /*RepositoryService repositoryService = processEngine.getRepositoryService(); NewDeployment newDeployment = repositoryService.createDeployment(); newDeployment.addResourceFromClasspath(""); newDeployment.addResourceFromClasspath(""); newDeployment.deploy();*/ processEngine.getRepositoryService() .createDeployment() .addResourceFromClasspath("qjlc.jpdl.xml") .addResourceFromClasspath("qjlc.png") .deploy(); } @Test public void testDeployFromInputStream(){ ProcessEngine processEngine = Configuration.getProcessEngine(); InputStream inputStream = this.getClass().getClassLoader() .getResourceAsStream("qjlc.jpdl.xml"); processEngine.getRepositoryService() .createDeployment() .addResourceFromInputStream("qjlc.jpdl.xml", inputStream) .deploy(); } @Test public void testDeployFromZipInputStream(){ ProcessEngine processEngine = Configuration.getProcessEngine(); InputStream inputStream = this.getClass().getClassLoader() .getResourceAsStream("qjlc.zip"); ZipInputStream zipStream = new ZipInputStream(inputStream); processEngine.getRepositoryService() .createDeployment() .addResourcesFromZipInputStream(zipStream) .deploy(); } /** * 查询所有部署 */ @Test public void testQueryAllDeploy(){ ProcessEngine processEngine = Configuration.getProcessEngine(); List<Deployment> list = processEngine.getRepositoryService() .createDeploymentQuery() .list(); for(Deployment deployment:list){ System.out.println(deployment.getId()); System.out.println("---------------"); System.out.println(deployment.getState()); } } /** * 根据部署ID查询部署 */ @Test public void testQueryDeploymentById(){ ProcessEngine processEngine = Configuration.getProcessEngine(); Deployment deployment = processEngine.getRepositoryService() .createDeploymentQuery() .deploymentId("40014") .uniqueResult(); System.out.println(deployment.getId()); System.out.println("---------------"); System.out.println(deployment.getState()); } /** * 查询所有流程定义 */ @Test public void testQueryAllPD(){ ProcessEngine processEngine = Configuration.getProcessEngine(); List<ProcessDefinition> list = processEngine.getRepositoryService() .createProcessDefinitionQuery() .list(); for(ProcessDefinition pd : list){ System.out.println(pd.getDeploymentId() + "-----------"); System.out.println(pd.getDescription() + "-----------"); System.out.println(pd.getId() + "-----------"); System.out.println(pd.getImageResourceName() + "-----------"); System.out.println(pd.getKey() + "-----------"); System.out.println(pd.getName() + "-----------"); System.out.println(pd.getVersion() + "-----------"); } } /** * 根据部署ID查询部署 */ @Test public void testQueryPDByDeploymentId(){ ProcessEngine processEngine = Configuration.getProcessEngine(); ProcessDefinition pd = processEngine.getRepositoryService() .createProcessDefinitionQuery() .deploymentId("50014") .uniqueResult(); System.out.println(pd.getDeploymentId() + "-----------"); System.out.println(pd.getDescription() + "-----------"); System.out.println(pd.getId() + "-----------"); System.out.println(pd.getImageResourceName() + "-----------"); System.out.println(pd.getKey() + "-----------"); System.out.println(pd.getName() + "-----------"); System.out.println(pd.getVersion() + "-----------"); } /** * 根据PDID查询流程定义 */ @Test public void testPdidByDefinition(){ ProcessEngine processEngine = Configuration.getProcessEngine(); ProcessDefinition pd = processEngine.getRepositoryService() .createProcessDefinitionQuery() .processDefinitionId("qclc-1") .uniqueResult(); System.out.println(pd.getDeploymentId() + "-----------"); System.out.println(pd.getDescription() + "-----------"); System.out.println(pd.getId() + "-----------"); System.out.println(pd.getImageResourceName() + "-----------"); System.out.println(pd.getKey() + "-----------"); System.out.println(pd.getName() + "-----------"); System.out.println(pd.getVersion() + "-----------"); } /** * 根据PDKEY查询流程定义 */ @Test public void testQueryPDByPdKey(){ ProcessEngine processEngine = Configuration.getProcessEngine(); List<ProcessDefinition> list = processEngine.getRepositoryService() .createProcessDefinitionQuery() .processDefinitionKey("qclc") .list(); for(ProcessDefinition pd : list){ System.out.println(pd.getDeploymentId() + "-----------"); System.out.println(pd.getDescription() + "-----------"); System.out.println(pd.getId() + "-----------"); System.out.println(pd.getImageResourceName() + "-----------"); System.out.println(pd.getKey() + "-----------"); System.out.println(pd.getName() + "-----------"); System.out.println(pd.getVersion() + "-----------"); } } /** * 删除 */ @Test public void testDelete(){ Configuration.getProcessEngine().getRepositoryService() //.deleteDeployment("50001"); .deleteDeploymentCascade("60001"); } /** * 查询流程图 * @throws Exception */ @Test public void testShowImage() throws Exception{ InputStream stream = Configuration.getProcessEngine().getRepositoryService() .getResourceAsStream("70001", "qjlc.png"); OutputStream outStream = new FileOutputStream("c:/qjlc.png"); int b = 0; while((b=stream.read())!=-1){ outStream.write(b); } stream.close(); outStream.close(); } }
|