Search in sources :

Example 1 with CorrelationKeyInfo

use of org.jbpm.persistence.correlation.CorrelationKeyInfo in project jbpm by kiegroup.

the class JPAProcessInstanceManager method addProcessInstance.

public void addProcessInstance(ProcessInstance processInstance, CorrelationKey correlationKey) {
    ProcessInstanceInfo processInstanceInfo = new ProcessInstanceInfo(processInstance, this.kruntime.getEnvironment());
    ProcessPersistenceContext context = ((ProcessPersistenceContextManager) this.kruntime.getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER)).getProcessPersistenceContext();
    processInstanceInfo = (ProcessInstanceInfo) context.persist(processInstanceInfo);
    ((org.jbpm.process.instance.ProcessInstance) processInstance).setId(processInstanceInfo.getId());
    processInstanceInfo.updateLastReadDate();
    // generate correlation key if not given which is same as process instance id to keep uniqueness
    if (correlationKey == null) {
        correlationKey = new CorrelationKeyInfo();
        ((CorrelationKeyInfo) correlationKey).addProperty(new CorrelationPropertyInfo(null, processInstanceInfo.getId().toString()));
        ((org.jbpm.process.instance.ProcessInstance) processInstance).getMetaData().put("CorrelationKey", correlationKey);
    }
    CorrelationKeyInfo correlationKeyInfo = (CorrelationKeyInfo) correlationKey;
    correlationKeyInfo.setProcessInstanceId(processInstanceInfo.getId());
    context.persist(correlationKeyInfo);
    internalAddProcessInstance(processInstance);
    EventManagerProvider.getInstance().get().create(new ProcessInstanceView(processInstance));
}
Also used : CorrelationPropertyInfo(org.jbpm.persistence.correlation.CorrelationPropertyInfo) CorrelationKeyInfo(org.jbpm.persistence.correlation.CorrelationKeyInfo) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) ProcessPersistenceContextManager(org.jbpm.persistence.api.ProcessPersistenceContextManager) ProcessPersistenceContext(org.jbpm.persistence.api.ProcessPersistenceContext) ProcessInstanceView(org.jbpm.persistence.api.integration.model.ProcessInstanceView)

Example 2 with CorrelationKeyInfo

use of org.jbpm.persistence.correlation.CorrelationKeyInfo in project jbpm by kiegroup.

the class JpaProcessPersistenceContext method remove.

public void remove(PersistentProcessInstance processInstanceInfo) {
    getEntityManager().remove(processInstanceInfo);
    TransactionManagerHelper.removeFromUpdatableSet(txm, processInstanceInfo);
    List<CorrelationKeyInfo> correlations = getEntityManager().createNamedQuery("GetCorrelationKeysByProcessInstanceId").setParameter("pId", processInstanceInfo.getId()).getResultList();
    if (correlations != null) {
        for (CorrelationKeyInfo key : correlations) {
            getEntityManager().remove(key);
        }
    }
}
Also used : CorrelationKeyInfo(org.jbpm.persistence.correlation.CorrelationKeyInfo)

Aggregations

CorrelationKeyInfo (org.jbpm.persistence.correlation.CorrelationKeyInfo)2 ProcessPersistenceContext (org.jbpm.persistence.api.ProcessPersistenceContext)1 ProcessPersistenceContextManager (org.jbpm.persistence.api.ProcessPersistenceContextManager)1 ProcessInstanceView (org.jbpm.persistence.api.integration.model.ProcessInstanceView)1 CorrelationPropertyInfo (org.jbpm.persistence.correlation.CorrelationPropertyInfo)1 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)1 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)1