wei wei [
http://community.jboss.org/people/wwweeii] created the discussion
"Re: How to reload knowledgeSession from database?"
To view the discussion, visit:
http://community.jboss.org/message/613608#613608
--------------------------------------------------------------
Thank you! I have tried this method, #but after the intercepted human task was completed,
the Ksession couldn’t know it, the state of the task was still 1, and I couldn’t continue
with the other tasks. How can I solve this problem?
Here are codes:
package com.sample;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.transaction.UserTransaction;
import org.drools.KnowledgeBaseFactory;
import org.drools.base.MapGlobalResolver;
import org.drools.runtime.*;
import org.drools.persistence.jpa.*;
import org.jbpm.process.audit.JPAWorkingMemoryDbLogger;
import org.jbpm.process.workitem.wsht.CommandBasedWSHumanTaskHandler;
import bitronix.tm.TransactionManagerServices;
import bitronix.tm.resource.jdbc.PoolingDataSource;
public class TestLoadSession {
public void loadSession(){
EntityManagerFactory emf = Persistence.createEntityManagerFactory(
"org.jbpm.persistence.jpa" );
Environment env = KnowledgeBaseFactory.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
env.set(EnvironmentName.TRANSACTION_MANAGER,
TransactionManagerServices.getTransactionManager());
env.set( EnvironmentName.GLOBALS, new MapGlobalResolver() );
StatefulKnowledgeSession ksession = JPAKnowledgeService.loadStatefulKnowledgeSession( 1,
KBaseFactory.getKbase(), null, env );
}
public static final void main(String[] args) {
try{
UserTransaction ut = (UserTransaction) new InitialContext().lookup(
"java:comp/UserTransaction" );
PoolingDataSource ds1 = new PoolingDataSource();
ds1 = new PoolingDataSource();
ds1.setUniqueName( "jdbc/testDS1" );
ds1.setClassName( "com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" );
ds1.setMaxPoolSize( 3 );
ds1.setAllowLocalTransactions( true );
ds1.getDriverProperties().put( "user","root" );
ds1.getDriverProperties().put( "password","111111" );
ds1.getDriverProperties().put( "URL",
"jdbc:mysql://localhost:3306/jbpm5db" );
ds1.init();
ut.begin();
EntityManagerFactory emf = Persistence.createEntityManagerFactory(
"org.jbpm.persistence.jpa" );
Environment env = KnowledgeBaseFactory.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
env.set(EnvironmentName.TRANSACTION_MANAGER,
TransactionManagerServices.getTransactionManager());
env.set( EnvironmentName.GLOBALS, new MapGlobalResolver() );
//Properties properties = new Properties();
//properties.put("drools.processInstanceManagerFactory",
"org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory");
//properties.put("drools.processSignalManagerFactory",
"org.jbpm.persistence.processinstance.JPASignalManagerFactory");
//KnowledgeSessionConfiguration config =
KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties);
StatefulKnowledgeSession ksession = JPAKnowledgeService.loadStatefulKnowledgeSession( 1,
KBaseFactory.getKbase(), null, env );
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new
CommandBasedWSHumanTaskHandler(ksession));
JPAWorkingMemoryDbLogger logger = new JPAWorkingMemoryDbLogger(ksession);
//ksession.notifyAll();
//ksession.abortProcessInstance(1);
//ksession.startProcessInstance(1);
//ksession.getProcessInstance(1).
ut.commit();
logger.dispose();
ut.begin();
Map data2=new HashMap();
Map data3=new HashMap();
data3.put("name", "This is my test Human Task param 222222!!");
data3.put("second", "The Second is KYO!!");
data2.put("name1",data3);
System.out.println("This is before commit:"+data2);
JbpmAPIUtil.completeTask(1, data2, "krisv");
ut.commit();
System.out.println("LOADSSESSION success!");
}
catch(Exception e){
e.printStackTrace();
}
}
}
--------------------------------------------------------------
Reply to this message by going to Community
[
http://community.jboss.org/message/613608#613608]
Start a new discussion in jBPM at Community
[
http://community.jboss.org/choose-container!input.jspa?contentType=1&...]