Search in sources :

Example 1 with JPAMapper

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);
    }
}
Also used : SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException) TransactionManager(org.drools.persistence.api.TransactionManager) JPAMapper(org.jbpm.runtime.manager.impl.mapper.JPAMapper) KieSession(org.kie.api.runtime.KieSession) ContentMarshallerContext(org.kie.internal.task.api.ContentMarshallerContext)

Example 2 with JPAMapper

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);
    }
}
Also used : TransactionManager(org.drools.persistence.api.TransactionManager) JPAMapper(org.jbpm.runtime.manager.impl.mapper.JPAMapper) KieSession(org.kie.api.runtime.KieSession) ContentMarshallerContext(org.kie.internal.task.api.ContentMarshallerContext)

Aggregations

TransactionManager (org.drools.persistence.api.TransactionManager)2 JPAMapper (org.jbpm.runtime.manager.impl.mapper.JPAMapper)2 KieSession (org.kie.api.runtime.KieSession)2 ContentMarshallerContext (org.kie.internal.task.api.ContentMarshallerContext)2 SessionNotFoundException (org.kie.internal.runtime.manager.SessionNotFoundException)1