Recently, a workflow-related demo is required for my work. I studied jbpm and recorded my experiences and experiences.
Software environment:
* Spring2.0.2
* Hibernate3.2.2
* Spring modules 0.8 (jbpm3.1)
* Jbpm3.1.4
* Struts2.0.6
Configuration
The spring module jbpm module provides several tool classes to integrate Spring and jbpm. For specific configurations, refer to the reference manual in the spring module download package and follow the instructions above to complete the process, paste the sample configuration here.
XML Code
1. <! -- Sp --> XML version = "1.0" encoding = "UTF-8"?>
2. <! -- Ctype beans public "-// spring // DTD bean 2.0 // en" "http://www.springframework.org/dtd/spring-beans-2.0.dtd" </SP -->
3. <beans default-autowire = "byname" default-Lazy-init = "true">
4. <bean id = "approveworkflow"
5. Class = "org. springmodules. workflow. jbpm31.definition. processdefinitionfactorybean">
6. <property name = "definitionlocation"
7. value = "classpath: jbpm/audit/processdefinition. xml"/>
8. bean>
9. <bean id = "jbpmconfiguration"
10. Class = "org. springmodules. workflow. jbpm31.localjbpmconfigurationfactorybean">
11. <property name = "sessionfactory" ref = "sessionfactory"/>
12. <property name = "configuration" value = "classpath: jbpm/jbpm. cfg. xml"/>
13. <property name = "processdefinitions">
14. <list>
15. <ref local = "approveworkflow"/>
16. List>
17. Property>
18.
19. bean>
20. <bean id = "jbpmtemplate"
21. Class = "org. springmodules. workflow. jbpm31.jbpmtemplate">
22. <constructor-Arg Index = "0" ref = "jbpmconfiguration"/>
23. <constructor-Arg Index = "1" ref = "approveworkflow"/>
24. bean>
25. Beans>
26.
The key is to enable the jbpm entity and business entity to use the same session factory, so that the business entity object can be persisted in the jbpm process instance. The Business Entity ing and jbpm entity ing must be integrated. My practice is to rewrite the hibernate. cfg. xml file provided by jbpm and include the business entity in it.
XML Code
1. <! -- Sp --> XML version = '1. 0' encoding = 'utf-8'?>
2.
3. <! -- Ctype hibernate-configuration Public </SP -->
4. "-// hibernate/hibernate configuration DTD 3.0 // en"
5. "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
6.
7. 8. <session-factory>
9.
10. <property name = "hibernate. cache. use_second_level_cache">
11. False
12. Property>
13. <property name = "hibernate. cache. use_query_cache">
14. False
15. Property>
16. <property name = "hibernate. dialect"> org. hibernate. dialect. mysql5dialectproperty>
17. <property name = "hibernate. show_ SQL"> falseproperty>
18. <property name = "hibernate. query. factory_class">
19. org. hibernate. hql. Ast. astquerytranslatorfactory
20. Property>
21.
22.
23. <! -- Below is the business entity ing -->
24. <Mapping Resource = "com/emap/jbpm/model/apply. HBM. xml"/>
25.
26. <! -- The following is the entity ing of the jbpm engine itself -->
27. <Mapping Resource = "org/jbpm/graph/Action/script. HBM. xml"/>
28.
29. <Mapping Resource = "org/jbpm/DB/hibernate. Queries. HBM. xml"/>
30.
31. <! -- Graph. Def Mapping Files -->
32. <Mapping Resource = "org/jbpm/graph/DEF/processdefinition. HBM. xml"/>
33. <Mapping Resource = "org/jbpm/graph/DEF/node. HBM. xml"/>
34. <Mapping Resource = "org/jbpm/graph/DEF/transition. HBM. xml"/>
35. <Mapping Resource = "org/jbpm/graph/DEF/event. HBM. xml"/>
36. <Mapping Resource = "org/jbpm/graph/DEF/action. HBM. xml"/>
37. <Mapping Resource = "org/jbpm/graph/DEF/superstate. HBM. xml"/>
38. <Mapping Resource = "org/jbpm/graph/DEF/exceptionhandler. HBM. xml"/>
39. <Mapping Resource = "org/jbpm/instantiation/delegation. HBM. xml"/>
40.
41 .........
42.
43. Session-factory>
44. hibernate-configuration>
Let's take a look at the configuration of the sessionfactory factory.
XML Code
1. <! -- Sp --> XML version = "1.0" encoding = "UTF-8"?>
2. <! -- Ctype beans public "-// spring // DTD bean 2.0 // en" "http://www.springframework.org/dtd/spring-beans-2.0.dtd" </SP -->
3. <beans default-autowire = "byname" default-Lazy-init = "true">
4.
5. <! -- Data Source Definition, use Apache DBCP connection pool -->
6. <bean id = "datasource" class = "org. Apache. commons. DBCP. basicdatasource" Destroy-method = "close">
7. <property name = "driverclassname" value = "$ {JDBC. driverclassname}"/>
8. <property name = "url" value = "$ {JDBC. url}"/>
9. <property name = "username" value = "$ {JDBC. Username}"/>
10. <property name = "password" value = "$ {JDBC. Password}"/>
11. bean>
12.
13. <! -- Hibernate sessionfactory -->
14. <bean id = "sessionfactory"
15. Class = "org. springframework. Orm. hibernate3.localsessionfactorybean">
16. <property name = "datasource" ref = "datasource"/>
17. <property name = "configlocations">
18. <list>
19. <value> classpath: jbpm/hibernate. cfg. xmlvalue>
20. List>
21. Property>
22. bean>
23. <! -- Hibernate transactionmanager -->
24. <bean id = "transactionmanager" class = "org. springframework. Orm. hibernate3.hibernatetransactionmanager">
25. <property name = "sessionfactory" ref = "sessionfactory"/>
26. bean>
27. Beans>
Legacy problems
How to Use the jbpm process designer plug-in?
I have never found any document on how to use the jbpm process designer plug-in, such as how to configure the jbpm installation path and how to deploy it. Currently, the only function used is to write process files.
How to publish process files?
I agree with the following post on how to publish a process file. Programming implementation may be the most concise method.
Www.pcdog.com/edu/java/2006/11/v171946.html
How to associate business entities and process instances?
Jbpm is mainly used to manage business processes, record the link that each process enters, and save some statuses. These status information may come from the business entity. Jbpm is implemented by serializing the status information to the table columns of the database.
Assume that there is an order processing process. Now we want to obtain the list of all tasks of a role and present the associated order information to the user. What should we do? Currently, I think of the following methods:
Method 1: when creating a task instance, the business entity is persisted to the contextinstance. When obtaining the task list, the business entity is directly parsed from the task instance. If the data size of the business entity to be saved is large, this will cause a lot of data redundancy to the jbpm database.
Method 2: when creating a task instance, only the unique identifier of the business entity is persistent to the contextinstance. When obtaining the task list, the unique identifier of the pragmatic body is resolved from the task instance, then query the business entity Database Based on this identifier. In this case, when querying a list of N tasks, it requires n + 1 database query. Obviously, the performance cannot meet the requirements.
Method 3: Can I associate with taskinstance when building a business entity? This approach will cause tight coupling between business entities and jbpm, and it must have a deep understanding of jbpm itself.
What is a better solution to this problem? I personally think that method 1 may be the most cost-effective solution at present.
Experience
Jbpm does not seem to have a lot of applications in China, and the materials are scarce. The only reference manual is very simple and simple. The source code annotation is not very good, which is rare in open-source software abroad.
Some APIs provided by jbpm are not comprehensive. For example, I want to query the list of all tasks of a role in a certain period of time. Because taskmgmtsession only provides the findxxxtaskinstances (string actorid) method, I can only query the list of all tasks of this role first, using the following code:
Java code
1. taskmgmtsession = context. gettaskmgmtsession ();
2. List tasks = taskmgmtsession. findpooledtaskinstances (actorid );
Then, use the code similar to the following in the memory for filtering.
Java code
1. If (task. getname (). Equals (taskname )&&! Task. hasended ())
This method is too clumsy and inefficient.
For the release process to the database:
Jbpmconfiguration = jbpmconfiguration. getinstance ();
Jbpmcontext = jbpmconfiguration. createjbpmcontext ();
// Processdefinition. xml generates the corresponding process definition class processdefinition
Inputstream is = new fileinputstream (
"D:/OA/workflow/processes/presalehandlerforbusinessreport. xml ");
Processdefinition = processdefinition. parsexmlinputstream (is );
Try {
Jbpmcontext. deployprocessdefinition (processdefinition );
} Catch (exception e ){
E. printstacktrace ();
} Finally {
Jbpmcontext. Close ();
}
To uninstall the process definition file:
Jbpmconfiguration = jbpmconfiguration. getinstance ();
Jbpmcontext = jbpmconfiguration. createjbpmcontext ();
Try {
Jbpmcontext. getgraphsession (). deleteprocessdefinition (long. parselong ("5 "));
} Catch (exception e ){
E. printstacktrace ();
} Finally {
Jbpmcontext. Close ();
}
Remember to disable jbpmcontext. There is a problem here. If the process you want to delete has been used, it may not be deleted when you uninstall the process. Sometimes I encounter this situation.