JBoss Community

Re: StatefulKnowledgeSession in custom work item handlers

created by Amin Mohammed-Coleman in jBPM - View the full discussion

Just looking at the source code...could i extend the JPAWorkItemManager to achive this?  For example:

 

in JPAWorkItemManager

 

public void internalExecuteWorkItem(WorkItem workItem) {

        Environment env = this.kruntime.getEnvironment();

 

        WorkItemInfo workItemInfo = new WorkItemInfo(workItem, env);

       

        PersistenceContext context = ((PersistenceContextManager) env.get( EnvironmentName.PERSISTENCE_CONTEXT_MANAGER )).getCommandScopedPersistenceContext();

        context.persist( workItemInfo );

 

        ((WorkItemImpl) workItem).setId(workItemInfo.getId());

        workItemInfo.update();

       

        if (this.workItems == null) {

            this.workItems = new HashMap<Long, WorkItemInfo>();

        }

        workItems.put(workItem.getId(), workItemInfo);

       

        WorkItemHandler handler = (WorkItemHandler) this.workItemHandlers.get(workItem.getName());

        if (handler != null) {

 

                  if (handler instanceof StatefulKnowledgeSessionAware) {

                                  //invoke a different execute and inject the session into this?

                            handler.executeWorkItemWithSession(workItem, this, kruntime);

                  } else {

                            handler.executeWorkItem(workItem, this);

                  }

        } else {

            throwWorkItemNotFoundException( workItem );

        }

    }

 

 

Would this work?  If so would i register a custom JPAWorkItemManager other than creating my own version of this...

Reply to this message by going to Community

Start a new discussion in jBPM at Community