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());
}
}
}
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);
}
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;
}
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);
}
}
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);
}
}
Aggregations