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-configuration>
<session-factory> <!-- 数据库信息 -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/jbpmdemo</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property> <!-- 其他配置 -->
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property> <!-- 映射文件 -->
<mapping resource="jbpm.repository.hbm.xml" />
<mapping resource="jbpm.execution.hbm.xml" />
<mapping resource="jbpm.history.hbm.xml" />
<mapping resource="jbpm.task.hbm.xml" />
<mapping resource="jbpm.identity.hbm.xml" />
</session-factory>
</hibernate-configuration>

 

通过hibernate生成表的测试代码:

package com.xjz.jbpm.db;

import org.hibernate.cfg.Configuration;
import org.junit.Test;

public class CreateDB {

@Test
public void test(){
Configuration configuration = new Configuration();
configuration.configure("jbpm.hibernate.cfg.xml");
configuration.buildSessionFactory();
}
}

 

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();
	}
}

  

posted @ 2017-05-04 10:43  dangzhenjiuhao  阅读(382)  评论(0编辑  收藏  举报