use of org.drools.persistence.info.SessionInfo in project jbpm by kiegroup.
the class PersistenceRuntimeManagerTest method testPerRequestManagerDestorySession.
@SuppressWarnings("unchecked")
@Test
public void testPerRequestManagerDestorySession() {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTask.bpmn2"), ResourceType.BPMN2).get();
EntityManager em = emf.createEntityManager();
List<SessionInfo> sessions = em.createQuery("from SessionInfo").getResultList();
assertEquals(0, sessions.size());
manager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment);
assertNotNull(manager);
sessions = em.createQuery("from SessionInfo").getResultList();
assertEquals(0, sessions.size());
// ksession for process instance #1
// since there is no process instance yet we need to get new session
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
runtime.getKieSession();
sessions = em.createQuery("from SessionInfo").getResultList();
assertEquals(1, sessions.size());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ProcessInstance pi1 = ksession.startProcess("UserTask");
// both processes started
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
manager.disposeRuntimeEngine(runtime);
sessions = em.createQuery("from SessionInfo").getResultList();
assertEquals(0, sessions.size());
runtime = manager.getRuntimeEngine(EmptyContext.get());
ksession = runtime.getKieSession();
sessions = em.createQuery("from SessionInfo").getResultList();
assertEquals(1, sessions.size());
ksession.getWorkItemManager().completeWorkItem(1, null);
manager.disposeRuntimeEngine(runtime);
sessions = em.createQuery("from SessionInfo").getResultList();
assertEquals(0, sessions.size());
manager.close();
emf.close();
}
use of org.drools.persistence.info.SessionInfo in project drools by kiegroup.
the class JpaPersistenceContext method remove.
public void remove(PersistentSession session) {
if (!em.contains(session)) {
SessionInfo s = em.getReference(SessionInfo.class, session.getId());
em.remove(s);
} else {
em.remove(session);
}
TransactionManagerHelper.removeFromUpdatableSet(txm, session);
em.flush();
}
use of org.drools.persistence.info.SessionInfo in project drools by kiegroup.
the class PersistableRunner method initNewKnowledgeSession.
protected void initNewKnowledgeSession(KieBase kbase, KieSessionConfiguration conf) {
this.sessionInfo = new SessionInfo();
// create session but bypass command service
this.ksession = kbase.newKieSession(conf, this.env);
initKieSessionMBeans(this.ksession);
this.marshallingHelper = new SessionMarshallingHelper(this.ksession, conf);
MarshallingConfigurationImpl config = (MarshallingConfigurationImpl) this.marshallingHelper.getMarshaller().getMarshallingConfiguration();
config.setMarshallProcessInstances(false);
config.setMarshallWorkItems(false);
this.sessionInfo.setJPASessionMashallingHelper(this.marshallingHelper);
((InternalKnowledgeRuntime) this.ksession).setEndOperationListener(new EndOperationListenerImpl(this.txm, this.sessionInfo));
this.runner = new TransactionInterceptor();
TimerJobFactoryManager timerJobFactoryManager = ((InternalKnowledgeRuntime) ksession).getTimerService().getTimerJobFactoryManager();
if (timerJobFactoryManager instanceof CommandServiceTimerJobFactoryManager) {
((CommandServiceTimerJobFactoryManager) timerJobFactoryManager).setRunner(this);
}
}
use of org.drools.persistence.info.SessionInfo in project drools by kiegroup.
the class JpaPersistenceContext method findSession.
public PersistentSession findSession(Long id) {
SessionInfo sessionInfo = null;
if (this.pessimisticLocking) {
sessionInfo = this.em.find(SessionInfo.class, id, lockMode);
TransactionManagerHelper.addToUpdatableSet(txm, sessionInfo);
return sessionInfo;
}
sessionInfo = this.em.find(SessionInfo.class, id);
TransactionManagerHelper.addToUpdatableSet(txm, sessionInfo);
return sessionInfo;
}
use of org.drools.persistence.info.SessionInfo in project jbpm by kiegroup.
the class PersistenceRuntimeManagerTest method testPerProcessInstanceManagerDestorySession.
@SuppressWarnings("unchecked")
@Test
public void testPerProcessInstanceManagerDestorySession() {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTask.bpmn2"), ResourceType.BPMN2).get();
EntityManager em = emf.createEntityManager();
List<SessionInfo> sessions = em.createQuery("from SessionInfo").getResultList();
assertEquals(0, sessions.size());
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
sessions = em.createQuery("from SessionInfo").getResultList();
assertEquals(0, sessions.size());
// ksession for process instance #1
// since there is no process instance yet we need to get new session
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
runtime.getKieSession();
sessions = em.createQuery("from SessionInfo").getResultList();
assertEquals(1, sessions.size());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
long ksession1Id = ksession.getIdentifier();
assertTrue(ksession1Id == 2);
ProcessInstance pi1 = ksession.startProcess("UserTask");
// both processes started
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
manager.disposeRuntimeEngine(runtime);
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi1.getId()));
ksession = runtime.getKieSession();
assertEquals(ksession1Id, ksession.getId());
sessions = em.createQuery("from SessionInfo").getResultList();
assertEquals(1, sessions.size());
ksession.getWorkItemManager().completeWorkItem(1, null);
manager.disposeRuntimeEngine(runtime);
// since process is completed now session should not be there any more
try {
manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi1.getId())).getKieSession();
fail("Session for this (" + pi1.getId() + ") process instance is no more accessible");
} catch (RuntimeException e) {
}
sessions = em.createQuery("from SessionInfo").getResultList();
assertEquals(0, sessions.size());
manager.close();
emf.close();
}
Aggregations