JBPM4入门——4.封装流程管理的工具类(JbpmUtil)

本博文只是简要对JBPM4进行介绍,如需更详细内容请自行google
链接:

JBPM4入门——1.jbpm简要介绍

JBPM4入门——2.在eclipse中安装绘制jbpm流程图的插件

JBPM4入门——3.JBPM4开发环境的搭建

JBPM4入门——4.封装流程管理的工具类(JbpmUtil) 

JBPM4入门——5.流程定义的发布、查询、删除

JBPM4入门——6.流程实例的创建和执行

JBPM4入门——7.等待节点的单条线手动执行

JBPM4入门——8.等待节点的分支执行

JBPM4入门——9.自动节点单线执行

扫描二维码关注公众号,回复: 548685 查看本文章

1.在util包下新建JbpmUtil 工具类

package com.test.util;
import org.jbpm.api.Configuration;
import org.jbpm.api.ExecutionService;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.RepositoryService;

public class JbpmUtil {
	private static ProcessEngine processEngine;
	private static RepositoryService repositoryService;
	private static ExecutionService executionService;
	
	static{
		//流程定义引擎的初始化
		processEngine = Configuration.getProcessEngine();
		//管理流程定义
		repositoryService = processEngine.getRepositoryService();
		//executionService  用于执行流程定义实例
		executionService = processEngine.getExecutionService();
	}
		
	/**
	 * 获取流程管理的repositoryService
	 * @return 
	 */
	public static RepositoryService getRepositoryService(){
		return repositoryService;
	}
	
	/**
	 * 获取执行流程定义的ExecutionService
	 * @return
	 */
	public static ExecutionService getExecutionService(){
		return executionService;
	}
}

 2.在test类里使用工具类来管理流程、并测试发布

package com.test.test;
import com.test.util.JbpmUtil;

public class Test {
	/**
	 * 流程发布的方法
	 * @param jpdlFileName 流程定义的文件名。例如:hello.jpdl.xml
	 */
	public void deploy(String jpdlFileName){
		JbpmUtil.getRepositoryService()
		.createDeployment()
		.addResourceFromClasspath(jpdlFileName)
		.deploy();
	}
	
	public static void main(String[] args) {
		Test test = new Test();
		test.deploy("hello.jpdl.xml");
	}
}

 3.查看数据库中的数据:deployment表中多了一条数据



 再看发布表中的数据:多了4条数据


 

1.在util包下新建JbpmUtil 工具类

package com.test.util;
import org.jbpm.api.Configuration;
import org.jbpm.api.ExecutionService;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.RepositoryService;

public class JbpmUtil {
	private static ProcessEngine processEngine;
	private static RepositoryService repositoryService;
	private static ExecutionService executionService;
	
	static{
		//流程定义引擎的初始化
		processEngine = Configuration.getProcessEngine();
		//管理流程定义
		repositoryService = processEngine.getRepositoryService();
		//executionService  用于执行流程定义实例
		executionService = processEngine.getExecutionService();
	}
		
	/**
	 * 获取流程管理的repositoryService
	 * @return 
	 */
	public static RepositoryService getRepositoryService(){
		return repositoryService;
	}
	
	/**
	 * 获取执行流程定义的ExecutionService
	 * @return
	 */
	public static ExecutionService getExecutionService(){
		return executionService;
	}
}

 2.在test类里使用工具类来管理流程、并测试发布

package com.test.test;
import com.test.util.JbpmUtil;

public class Test {
	/**
	 * 流程发布的方法
	 * @param jpdlFileName 流程定义的文件名。例如:hello.jpdl.xml
	 */
	public void deploy(String jpdlFileName){
		JbpmUtil.getRepositoryService()
		.createDeployment()
		.addResourceFromClasspath(jpdlFileName)
		.deploy();
	}
	
	public static void main(String[] args) {
		Test test = new Test();
		test.deploy("hello.jpdl.xml");
	}
}

 3.查看数据库中的数据:deployment表中多了一条数据



 再看发布表中的数据:多了4条数据


 

猜你喜欢

转载自794492789.iteye.com/blog/2198127