官方提供的userguide从大的方面阐述了jBPM的基本流程和概念,总结一下其思路:
一:发布
1.一切从Configuration开始:Configuration configuration = new Configuration();
2.然后构建 ProcessEngine:ProcessEngine processEngine = configuration().buildProcessEngine();
3.有了ProcessEngine,一切就都有了:
RepositoryService repositoryService = processEngine.getRepositoryService();
ExecutionService executionService = processEngine.getExecutionService();
TaskService taskService = processEngine.getTaskService();
HistoryService historyService = processEngine.getHistoryService();
ManagementService = processEngine.getManagementService();
4.发布了:String deploymentId = repositoryService.createDeployment()
.addResourceFromClassPath("org/jbpm/Order.jpdl.xml")
.deploy();
5.现在删除它吧:repositoryService.deleteDeployment(deploymentId);
当然,还有另一个方法:repositoryService.deleteDeploymentCascade(deploymentId);//将删除相关instance和history。
ProcessEngine processEngine = new Configuration().buildProcessEngine();
those code will load this default configuration file jbpm.cfg.xml which is expected in the root of the classpath.
Get ProcessEngine from your own configuration file by Configuration:
ProcessEngine processEngine = new Configuration().setResource("myconfigurationfile.xml").bulidProcessEngine();
Now you can obtain the following services:
RepositoryService repositoryService = processEngine.getRepositoryService();
ExecutionService executionService = processEngine.getExecutionService();
TaskService taskService = processEngine.getTaskService();
HistoryService historyService = processEngine.getHistoryService();
ManagementService managementService = processEngine.getManagementService();
Deploying a process:
String deploymentId = repositoryService.createDeployment().addResourceFromClassPath("org/jbpm/my.jpdl.xml").deploy();
Deleting a deployment:
repositoryService.deleteDeployment(deploymentId);
repositoryService.deleteDeploymentCascade(deploymentId);
Starting a new process instance
Simplest and most common way:
ProcessInstance processInstance = executionService.startProcessInstanceByKey("ICL");
Specific process version:
ProcessInstanc processInstance = executionService.startProcessInstanceById("ICL-1");
ProcessInstance processInstance = executionService.startProcessInstanceByKey("ICL","CL92837");
With variables:
Map<String,Object> variables = new HashMap<String,Object>();
variables.put("customer","John Doe");
variables.put("type","Accident");
ProcessInstance processInstance = executionService.startProcessInstanceByKey("ICL",variables);
startProcessInstanceByKey和startProcessInstanceById的区别:
前者会根据key寻找最近的deployment版本,后者是直接寻找到特定版本。
Execution executionInA = processInstance.findActiveExecutionIn("a");
processInstance = executionService.signalExecutionById(executionInA.getId());
Execution executionInB = processInstance.findActiveExecutionIn("b");
processInstance = executionService.signalExecutionById(executionInB.getId());
Execution executionInC = processInstance.findActiveExecutionIn("c");
String executionId = processInstance.findActiveExecutionIn("wait for response").getId();
processInstance = executionService.signalExecutionById(executionId,"accept");
assertTrue(processInstance.isActive("submit document"));
variables.put("content","good");
ProcessInstance processInstance = executionService.startProcessInstanceByKey("DecisionConditions",variables);
assertTrue(processInstance.isActive("submit document"));
<! DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd" >
<!-- Generated by MyEclipse Hibernate Tools. -->
< hibernate-configuration >
< session-factory >
< property name ="connection.username" > root </ property >
< property name ="connection.url" >jdbc:mysql://localhost:3306/jbpmdb </ property >
< property name ="dialect" > org.hibernate.dialect.MySQLDialect </ property >
< property name ="myeclipse.connection.profile" > bbs </ property >
< property name ="connection.password" >pwd </ property >
< property name ="connection.driver_class" > com.mysql.jdbc.Driver </ property >
< property name ="show_sql" > true </ property >
< mapping resource ="com/bbs/hibernate/User.hbm.xml" ></ mapping >
</ session-factory >
Hibernate之hbm2ddl
<property name="hibernate.hbm2ddl.auto">
</property>
它包含4个属性:
* create : 会根据你的model类来生成表,但是每次运行都会删除上一次的表,重新生成表,哪怕2次没有任何改变
* create-drop : 根据model类生成表,但是sessionFactory一关闭,表就自动删除
* update : 最常用的属性,也根据model类生成表,即使表结构改变了,表中的行仍然存在,不会删除以前的行
* validate : 只会和数据库中的表进行比较,不会创建新表,但是会插入新值
</ hibernate-configuration >