JBPM流程定义(pd)ProcessDefinition

其他例子 点击打开链接

1 新建一个java Project

2 导包   讲jbpm4.4根路径下包 


把所有的jar包导入



配置文件


jbpm.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>

<jbpm-configuration>

	<import resource="jbpm.default.cfg.xml" />
	<import resource="jbpm.businesscalendar.cfg.xml" />
	<import resource="jbpm.tx.hibernate.cfg.xml" />
	<import resource="jbpm.jpdl.cfg.xml" />
	<import resource="jbpm.bpmn.cfg.xml" />
	<import resource="jbpm.identity.cfg.xml" />



</jbpm-configuration>

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="dialect">
		org.hibernate.dialect.MySQL5InnoDBDialect
	</property>
	<property name="connection.url">
		jdbc:mysql://localhost:3306/jbpm0909
	</property>
	<property name="connection.username">root</property>
	<property name="connection.password"> </property>
	<property name="connection.driver_class">
		com.mysql.jdbc.Driver
	</property>
	<property name="myeclipse.connection.profile">mysql</property>
	<property name="show_sql">true</property>
	<property name="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>


注意

org.hibernate.dialect.MySQL5InnoDBDialect

不同的数据库版本是不一样的

logging.properties


handlers= java.util.logging.ConsoleHandler
redirect.commons.logging = enabled

java.util.logging.ConsoleHandler.level = FINEST
java.util.logging.ConsoleHandler.formatter = org.jbpm.internal.log.LogFormatter

org.jbpm.level=FINE
# org.jbpm.pvm.internal.tx.level=FINE
# org.jbpm.pvm.internal.wire.level=FINE
# org.jbpm.pvm.internal.util.level=FINE

org.hibernate.level=INFO
org.hibernate.cfg.SettingsFactory.level=SEVERE
org.hibernate.cfg.HbmBinder.level=SEVERE
org.hibernate.SQL.level=FINEST
org.hibernate.type.level=FINEST
# org.hibernate.tool.hbm2ddl.SchemaExport.level=FINEST
# org.hibernate.transaction.level=FINEST

创建数据库的表

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



import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.junit.Before;

public class BaseJbpm {
	public static ProcessEngine processEngine;
	@Before
	public void testBase(){
		this.processEngine = Configuration.getProcessEngine();
	}
}

/**
 * 流程定义管理
 *    *  流程定义
 *    *  把流程定义文档部署到jbpm中
 *    *  查询
 *       *  查询流程部署
 *          * 查询所有的流程部署
 *          * 根据部署ID查询流程部署
 *       *  查询流程定义
 *          *  查询所有的流程定义
 *          *  根据deploymentID查询流程定义
 *          *  根据pdid查询流程定义
 *          *  根据pdkey查询流程定义
 *    *  删除
 *    *  查看流程图
 * @author Administrator
 *
 */
public class PDManager extends BaseJbpm{
	
	/**
	 * 涉及到的表
	 *     *  JBPM4_DEPLOYMENT
	 *        *  部署表,用来描述一次部署
	 *        *  字段说明
	 *           DBID_: 主键、部署ID
	 *           STATE: 状态   active
	 *     *  JBPM4_LOB
	 *        *  仓库表   存放了流程定义文档(xml,png)
	 *        *  字段说明
	 *           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开始计算
	 */
	/**
	 * 从classpath加载
	 */
	@Test
	public void testDeployFromClasspath(){
//		RepositoryService repositoryService = processEngine.getRepositoryService();
//		NewDeployment newDeployment = repositoryService.createDeployment();
//		newDeployment.addResourceFromClasspath("");
//		newDeployment.addResourceFromClasspath("");
//		newDeployment.deploy();
		processEngine.getRepositoryService()
		.createDeployment()
		.addResourceFromClasspath("qingjia.jpdl.xml")
		.addResourceFromClasspath("qingjia.png")
		.deploy();
	}
	/**
	 * 从inputstream加载
	 */
	@Test
	public void testDeployFromInputStream(){
		InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("qingjia.jpdl.xml");
		processEngine.getRepositoryService()
		.createDeployment()
		.addResourceFromInputStream("qingjia.jpdl.xml", inputStream)
		.deploy();
	}
	/**
	 * 从zipinoutStream加载
	 */
	@Test
	public void testDeployFromZipinputStream(){
		InputStream in = this.getClass().getClassLoader().getResourceAsStream("qingjia.zip");
		ZipInputStream zipInputStream = new ZipInputStream(in);
		processEngine.getRepositoryService()
		.createDeployment()
		.addResourcesFromZipInputStream(zipInputStream)
		.deploy();
	}
	
	/**
	 * 查询所有的部署
	 */
	@Test
	public void testQueryAllDeploy(){
		List<Deployment> deploymentList = processEngine.getRepositoryService()
		.createDeploymentQuery()
		.list();
		for(Deployment deployment:deploymentList){
			System.out.print(deployment.getId());
			System.out.print("  ");
			System.out.println(deployment.getState());
		}
	}
	
	/**
	 * 根据部署ID查询部署
	 */
	@Test
	public void testQueryDeployByID(){
		Deployment deployment = processEngine.getRepositoryService()
		.createDeploymentQuery()
		.deploymentId("1")
		.uniqueResult();
		System.out.print(deployment.getId());
		System.out.print("  ");
		System.out.println(deployment.getState());
	}
	
	/**
	 * 查询所有的流程定义
	 */
	@Test
	public void testQueryAllPD(){
		List<ProcessDefinition> pdList = processEngine.getRepositoryService()
		.createProcessDefinitionQuery()
		.list();
		for(ProcessDefinition pd:pdList){
			System.out.print("deploymentId:"+pd.getDeploymentId()+",");
			System.out.print("imageURL:"+pd.getImageResourceName()+",");
			System.out.print("key:"+pd.getKey()+",");
			System.out.println("version:"+pd.getVersion());
		}
	}
	
	/**
	 * 根据部署ID查询流程定义
	 */
	@Test
	public void testQueryPDByDeploymentId(){
		ProcessDefinition pd = processEngine.getRepositoryService()
		.createProcessDefinitionQuery()
		.deploymentId("1")
		.uniqueResult();
		System.out.print("deploymentId:"+pd.getDeploymentId()+",");
		System.out.print("imageURL:"+pd.getImageResourceName()+",");
		System.out.print("key:"+pd.getKey()+",");
		System.out.println("version:"+pd.getVersion());
	}
	
	/**
	 * 根据PDID查询流程定义
	 */
	@Test
	public void testQueryPDByPDID(){
		ProcessDefinition pd = processEngine.getRepositoryService()
		.createProcessDefinitionQuery()
		.processDefinitionId("qingjia1-1")
		.uniqueResult();
		System.out.print("deploymentId:"+pd.getDeploymentId()+",");
		System.out.print("imageURL:"+pd.getImageResourceName()+",");
		System.out.print("key:"+pd.getKey()+",");
		System.out.println("version:"+pd.getVersion());
	}
	
	/**
	 * 根据pdkey查询流程定义
	 */
	@Test
	public void testQueryPDByPDKEY(){
		List<ProcessDefinition> pdList = processEngine
		.getRepositoryService()
		.createProcessDefinitionQuery()
		.processDefinitionKey("qingjia")
		.list();
		for(ProcessDefinition pd:pdList){
			System.out.println("--------------------------------");
			System.out.print("deploymentId:"+pd.getDeploymentId()+",");
			System.out.print("imageURL:"+pd.getImageResourceName()+",");
			System.out.print("key:"+pd.getKey()+",");
			System.out.println("version:"+pd.getVersion());
		}
	}
	
	/**
	 * 删除
	 *   只能直接删除流程部署
	 *   而没有提供删除流程定义的API
	 */
	@Test
	public void testDeleteDeployment(){
		processEngine.getRepositoryService()
		.deleteDeploymentCascade("10001");
	}
	
	/**
	 * 根据key得到所有的流程定义,然后遍历每一个流程定义,得到流程部署,然后依次删除
	 */
	/**
	 * 查询流程图
	 */
	@Test
	public void testShowImage() throws Exception{
		InputStream inputStream = processEngine.getRepositoryService()
		.getResourceAsStream("20001", "qingjia.png");
		
		OutputStream outputStream = new FileOutputStream("c:/processimg.png");
		for(int b=-1;(b=inputStream.read())!=-1;){
			outputStream.write(b);
		}
		inputStream.close();
		outputStream.close();
	}
}

注意 pdkey 1:N pdid  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值