5 Replies Latest reply on Jun 20, 2012 9:54 AM by pgoncalves

    How to save history of the process in a database

    ashish_kumar

       

      Hello,

       

        Can any body tell me how to save the details of the process in a database using persistence and logger(JPAWorkingMemoryDbLogger).

       

       

      Thanks and Regards

        • 1. Re: How to save history of the process in a database
          pgoncalves

          Just declare it after initialize your knowledge session

           

           

          StatefulKnowledgeSession kSession = JPAKnowledgeService.newStatefulKnowledgeSession(getKbase(), null, env);
          
          JPAWorkingMemoryDbLogger jbpmLogger = new JPAWorkingMemoryDbLogger(kSession);
          
          // do stuff (start processes, etc...)
          
          jbpmLogger.dispose();
          
          

           

          Everything should be logged in the database!

          1 of 1 people found this helpful
          • 2. Re: How to save history of the process in a database
            ashish_kumar

            I added that but it was asking to define getkbase().So I manupulated the code.Kindly have a look and advice me that how can I correct it.

            Also tell me how can I test this concept.Where to find out the database in which the details are stored.

             

            For your reference the code is as below:

             


            package sample;
            import org.drools.KnowledgeBase;
            import org.drools.KnowledgeBaseFactory;
            import org.drools.builder.KnowledgeBuilder;
            import org.drools.builder.KnowledgeBuilderFactory;
            import org.drools.builder.ResourceType;
            import org.drools.io.ResourceFactory;
            import org.drools.persistence.jpa.JPAKnowledgeService;
            import org.drools.runtime.StatefulKnowledgeSession;
            import org.jbpm.process.audit.JPAWorkingMemoryDbLogger;
            import org.jbpm.test.JBPMHelper;


            public class historyLog  {

            /**
              * @param args
              */
            public static void main(String[] args)  throws Exception {
              // TODO Auto-generated method stub
              //JBPMHelper.startH2Server();
              //JBPMHelper.setupDataSource();
             
              //EntityManagerFactory emf =
              //    Persistence.createEntityManagerFactory( "org.jbpm.persistence.jpa" );


              org.drools.runtime.Environment env = KnowledgeBaseFactory.newEnvironment();
              KnowledgeBase kbase = readKnowledgeBase();
             
              //StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
              //JPAWorkingMemoryDbLogger logger = new JPAWorkingMemoryDbLogger(ksession);


              StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
              JPAWorkingMemoryDbLogger jbpmLogger = new JPAWorkingMemoryDbLogger(ksession);
              ksession.startProcess("sample.bpmn.hh"); 
              jbpmLogger.dispose();


            }

             

            private static KnowledgeBase readKnowledgeBase() throws Exception {
              KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
              kbuilder.add(ResourceFactory.newClassPathResource("demo2.bpmn"), ResourceType.BPMN2);
              return kbuilder.newKnowledgeBase();
            }

            }

             

            • 3. Re: How to save history of the process in a database
              pgoncalves

              Well... you will have to set up a database.

               

              Then you need to configure the jbpm to use the database! For this, check chapter 8 of the user guide.

              • 4. Re: How to save history of the process in a database
                ashish_kumar

                But can I use the inbuilt H2 database? And in the user guide that I had doesn't mention anything regarding the creatio of the database.Can you share the user guide or the link if possible.And also let me know whether my approach is correct or not.

                • 5. Re: How to save history of the process in a database
                  pgoncalves

                  Yes, you can use the inbuilt H2 database. I'm haven't used it, so I don't know how to query it.

                   

                  Check this for the docs:

                  http://www.jboss.org/jbpm/documentation

                  User Guide:

                  http://docs.jboss.org/jbpm/v5.3/userguide/

                  API:

                  http://docs.jboss.org/jbpm/v5.3/javadocs

                   

                  Dig into the examples to clarify some of your doubts:

                  http://sourceforge.net/projects/jbpm/files/jBPM%205/jbpm-5.3.0.Final/ -----> check jbpm-5.3.0.Final-examples.zip