4 Replies Latest reply on Jul 21, 2006 12:21 PM by Ronald van Kuijk

    Purge existing process instances

    kbutler Newbie

      Hi -
      I am currently integrating a project that includes jBPM, and do not have time to gain solid familiarity with its inner-workings. Also I trust the community more than the vendor. So I ask you here...

      I am cleaning up what was a test database, to ready it for production. One thing I want to clean up is all the pending jBPM process/task instances, while retaining all the process/task definitions. Here is a list of the tables I think should be purged:

      delete from JBPM_MODULEINSTANCE
      delete from JBPM_PROCESSINSTANCE
      delete from JBPM_TASKINSTANCE
      delete from JBPM_VARIABLEINSTANCE
      delete from JBPM_TOKEN
      delete from JBPM_TOKENVARIABLEMAP
      delete from JBPM_TIMER
      delete from JBPM_LOG
      

      And here is a list of the tables that were empty, so I am ignoring:
      /*
      -- Tables which are currently unused (empty)
      JBPM_COMMENT
      JBPM_DESCISIONCONDITIONS
      JBPM_EXCEPTIONHANDLER
      JBPM_POOLEDACTOR
      JBPM_RUNTIMEACTION
      JBPM_SWIMLANE
      JBPM_SWIMLANEINSTANCE
      JBPM_TASKACTORPOOL
      */
      


      Can someone please tell me if this looks correct?


        • 1. Re: Purge existing process instances
          kbutler Newbie

          Sorry, this is jBPM 3.0.1

          • 2. Re: Purge existing process instances
            kbutler Newbie

            Duh - I just saw the DataModel Wiki
            http://wiki.jboss.org/wiki/Wiki.jsp?page=Jbpm31DataModel ,
            somehow I missed it on the Wiki page.

            I have corrected my earlier script, for SQLServer, by adding the rest of the tables from the Execution Model. Note that JBPM_MESSAGE is not part of my 3.0.1 installation, so is omitted here.

            By way of apology, here is the final script for SQLServer users, note the skirting of a FK.

            delete from JBPM_LOG
            delete from JBPM_TIMER
            delete from JBPM_MODULEINSTANCE
            delete from JBPM_TOKENVARIABLEMAP
            delete from JBPM_TASKINSTANCE
            delete from JBPM_VARIABLEINSTANCE
            
            -- Must temporarily drop FK from Token -> ProcInstance
            if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_TOKEN_PROCINST]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
            ALTER TABLE [dbo].[JBPM_TOKEN] DROP CONSTRAINT FK_TOKEN_PROCINST
            
            -- Clear tables
            delete from JBPM_PROCESSINSTANCE
            delete from JBPM_TOKEN
            
            -- Re-add dropped FKs
            ALTER TABLE [dbo].[JBPM_TOKEN] ADD
             CONSTRAINT [FK_TOKEN_PROCINST] FOREIGN KEY
             (
             [PROCESSINSTANCE_]
             ) REFERENCES [dbo].[JBPM_PROCESSINSTANCE] (
             [ID_]
             )
            
            delete from JBPM_SWIMLANEINSTANCE
            delete from JBPM_POOLEDACTOR
            delete from JBPM_TASKACTORPOOL
            delete from JBPM_COMMENT
            delete from JBPM_RUNTIMEACTION
            delete from JBPM_BYTEBLOCK
            delete from JBPM_BYTEARRAY
            


            Comments welcome.


            • 3. Re: Purge existing process instances
              Chris OBrien Novice

              Why alter the foreign keys? Why not just set the JBPM_TOKEN.PROCESSINSTANCE to null on the token table, delete the process instances, and then the tokens.

              Also, you might want to look into the GraphSession. In 3.1.x, there is a GraphSession.deleteProcessInstance which will automatically go through and delete everything tied to that process instance, instead of you worrying about it.