JBPM入門

jbpm.hibernate.cfg.xmljava

<?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>mysql

 

經過hibernate生成表的測試代碼:sql

package com.xjz.jbpm.db;數據庫

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

public class CreateDB {

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

 

JBPM4.4的API測試代碼:app

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();
	}
}
相關文章
相關標籤/搜索