Search in sources :

Example 1 with PersistenceContext

use of org.drools.persistence.api.PersistenceContext in project drools by kiegroup.

the class JPAWorkItemManager method abortWorkItem.

public void abortWorkItem(long id) {
    PersistenceContext context = getPersistenceContext();
    WorkItemInfo workItemInfo = null;
    if (this.workItems != null) {
        workItemInfo = this.workItems.get(id);
        if (workItemInfo != null) {
            workItemInfo = (WorkItemInfo) context.merge(workItemInfo);
        }
    }
    if (workItemInfo == null) {
        workItemInfo = (WorkItemInfo) context.findWorkItem(id);
    }
    // work item may have been aborted
    if (workItemInfo != null) {
        WorkItem workItem = (WorkItemImpl) internalGetWorkItem(workItemInfo);
        ProcessInstance processInstance = kruntime.getProcessInstance(workItem.getProcessInstanceId());
        workItem.setState(WorkItem.ABORTED);
        // process instance may have finished already
        if (processInstance != null) {
            processInstance.signalEvent("workItemAborted", workItem);
        }
        context.remove(workItemInfo);
        if (workItems != null) {
            workItems.remove(workItem.getId());
        }
    }
}
Also used : WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) PersistenceContext(org.drools.persistence.api.PersistenceContext) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.drools.core.process.instance.WorkItem) WorkItemInfo(org.drools.persistence.info.WorkItemInfo)

Example 2 with PersistenceContext

use of org.drools.persistence.api.PersistenceContext in project drools by kiegroup.

the class JPAWorkItemManager method getWorkItem.

public WorkItem getWorkItem(long id) {
    PersistenceContext context = getPersistenceContext();
    WorkItemInfo workItemInfo = null;
    if (this.workItems != null) {
        workItemInfo = this.workItems.get(id);
    }
    if (this.pessimisticLocking && workItemInfo != null) {
        context.lock(workItemInfo);
    }
    if (workItemInfo == null && context != null) {
        workItemInfo = (WorkItemInfo) context.findWorkItem(id);
    }
    if (workItemInfo == null) {
        return null;
    }
    return internalGetWorkItem(workItemInfo);
}
Also used : PersistenceContext(org.drools.persistence.api.PersistenceContext) WorkItemInfo(org.drools.persistence.info.WorkItemInfo)

Example 3 with PersistenceContext

use of org.drools.persistence.api.PersistenceContext in project drools by kiegroup.

the class JPAWorkItemManager method getPersistenceContext.

private PersistenceContext getPersistenceContext() {
    Environment env = this.kruntime.getEnvironment();
    PersistenceContext context = ((PersistenceContextManager) env.get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER)).getCommandScopedPersistenceContext();
    return context;
}
Also used : Environment(org.kie.api.runtime.Environment) PersistenceContext(org.drools.persistence.api.PersistenceContext) PersistenceContextManager(org.drools.persistence.api.PersistenceContextManager)

Example 4 with PersistenceContext

use of org.drools.persistence.api.PersistenceContext in project drools by kiegroup.

the class JPAWorkItemManager method internalExecuteWorkItem.

public void internalExecuteWorkItem(WorkItem workItem) {
    Environment env = this.kruntime.getEnvironment();
    WorkItemInfo workItemInfo = new WorkItemInfo(workItem, env);
    PersistenceContext context = getPersistenceContext();
    workItemInfo = (WorkItemInfo) context.persist(workItemInfo);
    ((WorkItemImpl) workItem).setId(workItemInfo.getId());
    if (this.workItems == null) {
        this.workItems = new HashMap<Long, WorkItemInfo>();
    }
    workItems.put(workItem.getId(), workItemInfo);
    WorkItemHandler handler = (WorkItemHandler) this.workItemHandlers.get(workItem.getName());
    if (handler != null) {
        handler.executeWorkItem(workItem, this);
    } else {
        throwWorkItemNotFoundException(workItem);
    }
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) Environment(org.kie.api.runtime.Environment) PersistenceContext(org.drools.persistence.api.PersistenceContext) WorkItemInfo(org.drools.persistence.info.WorkItemInfo)

Example 5 with PersistenceContext

use of org.drools.persistence.api.PersistenceContext in project drools by kiegroup.

the class PersistableRunner method destroy.

@Override
public void destroy() {
    PersistenceContext persistenceContext = this.jpm.getApplicationScopedPersistenceContext();
    boolean transactionOwner = false;
    try {
        transactionOwner = txm.begin();
        persistenceContext.joinTransaction();
        initExistingKnowledgeSession(this.sessionInfo.getId(), this.marshallingHelper.getKbase(), this.marshallingHelper.getConf(), persistenceContext);
        persistenceContext.remove(this.sessionInfo);
        txm.commit(transactionOwner);
    } catch (RuntimeException re) {
        rollbackTransaction(re, transactionOwner);
        throw re;
    } catch (Exception t1) {
        rollbackTransaction(t1, transactionOwner);
        throw new RuntimeException("Wrapped exception see cause", t1);
    }
}
Also used : PersistenceContext(org.drools.persistence.api.PersistenceContext) SessionNotFoundException(org.drools.persistence.api.SessionNotFoundException)

Aggregations

PersistenceContext (org.drools.persistence.api.PersistenceContext)8 WorkItemInfo (org.drools.persistence.info.WorkItemInfo)6 WorkItem (org.drools.core.process.instance.WorkItem)3 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)3 Environment (org.kie.api.runtime.Environment)3 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)2 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)2 PersistenceContextManager (org.drools.persistence.api.PersistenceContextManager)1 SessionNotFoundException (org.drools.persistence.api.SessionNotFoundException)1