use of org.jbpm.runtime.manager.impl.mapper.JPAMapper in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManager method init.
@Override
public void init() {
TaskContentRegistry.get().addMarshallerContext(getIdentifier(), new ContentMarshallerContext(environment.getEnvironment(), environment.getClassLoader()));
boolean owner = false;
TransactionManager tm = null;
if (environment.usePersistence()) {
tm = getTransactionManagerInternal(environment.getEnvironment());
owner = tm.begin();
}
try {
// need to init one session to bootstrap all case - such as start timers
KieSession initialKsession = factory.newKieSession();
// there is a need to call getProcessRuntime otherwise the start listeners are not registered
initialKsession.execute(new ExecutableCommand<Void>() {
private static final long serialVersionUID = 1L;
@Override
public Void execute(org.kie.api.runtime.Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
((InternalKnowledgeRuntime) ksession).getProcessRuntime();
return null;
}
});
factory.onDispose(initialKsession.getIdentifier());
initialKsession.execute(new DestroyKSessionCommand(initialKsession, this));
if (!"false".equalsIgnoreCase(System.getProperty("org.jbpm.rm.init.timer"))) {
if (mapper instanceof JPAMapper) {
List<Long> ksessionsToInit = ((JPAMapper) mapper).findKSessionToInit(this.identifier);
for (Long id : ksessionsToInit) {
initialKsession = factory.findKieSessionById(id);
initialKsession.execute(new DisposeKSessionCommand(initialKsession, this));
}
}
}
if (tm != null) {
tm.commit(owner);
}
} catch (Exception e) {
if (tm != null) {
tm.rollback(owner);
}
throw new RuntimeException("Exception while initializing runtime manager " + this.identifier, e);
}
}
use of org.jbpm.runtime.manager.impl.mapper.JPAMapper in project jbpm by kiegroup.
the class PerCaseRuntimeManager method init.
@Override
public void init() {
TaskContentRegistry.get().addMarshallerContext(getIdentifier(), new ContentMarshallerContext(environment.getEnvironment(), environment.getClassLoader()));
boolean owner = false;
TransactionManager tm = null;
if (environment.usePersistence()) {
tm = getTransactionManagerInternal(environment.getEnvironment());
owner = tm.begin();
}
try {
// need to init one session to bootstrap all case - such as start timers
KieSession initialKsession = factory.newKieSession();
// there is a need to call getProcessRuntime otherwise the start listeners are not registered
initialKsession.execute(new ExecutableCommand<Void>() {
private static final long serialVersionUID = 1L;
@Override
public Void execute(org.kie.api.runtime.Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
((InternalKnowledgeRuntime) ksession).getProcessRuntime();
return null;
}
});
factory.onDispose(initialKsession.getIdentifier());
initialKsession.execute(new DestroyKSessionCommand(initialKsession, this));
if (!"false".equalsIgnoreCase(System.getProperty("org.jbpm.rm.init.timer"))) {
if (mapper instanceof JPAMapper) {
List<Long> ksessionsToInit = ((JPAMapper) mapper).findKSessionToInit(this.identifier);
for (Long id : ksessionsToInit) {
initialKsession = factory.findKieSessionById(id);
initialKsession.execute(new DisposeKSessionCommand(initialKsession, this));
}
}
}
if (tm != null) {
tm.commit(owner);
}
} catch (Exception e) {
if (tm != null) {
tm.rollback(owner);
}
throw new RuntimeException("Exception while initializing runtime manager " + this.identifier, e);
}
}
Aggregations