use of org.drools.persistence.info.WorkItemInfo 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.info.WorkItemInfo 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.info.WorkItemInfo 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.info.WorkItemInfo in project drools by kiegroup.
the class JpaPersistenceContext method merge.
public PersistentWorkItem merge(PersistentWorkItem workItem) {
if (this.pessimisticLocking) {
if (em.contains(workItem)) {
em.lock(workItem, LockModeType.PESSIMISTIC_FORCE_INCREMENT);
} else {
// Yes, this is a hack, but for detached entities, it's the only way to lock before merging
WorkItemInfo dbWorkItemInfo = em.find(WorkItemInfo.class, workItem.getId(), LockModeType.PESSIMISTIC_FORCE_INCREMENT);
for (Field field : WorkItemInfo.class.getDeclaredFields()) {
boolean access = field.isAccessible();
field.setAccessible(true);
try {
field.set(dbWorkItemInfo, field.get(workItem));
} catch (Exception e) {
logger.error("Unable to set field " + field.getName() + " of unmerged WorkItemInfo instance!", e);
}
field.setAccessible(access);
}
}
}
TransactionManagerHelper.addToUpdatableSet(txm, workItem);
return em.merge(workItem);
}
use of org.drools.persistence.info.WorkItemInfo in project drools by kiegroup.
the class JpaPersistenceContext method findWorkItem.
public PersistentWorkItem findWorkItem(Long id) {
WorkItemInfo workItemInfo = null;
if (this.pessimisticLocking) {
workItemInfo = this.em.find(WorkItemInfo.class, id, LockModeType.PESSIMISTIC_FORCE_INCREMENT);
TransactionManagerHelper.addToUpdatableSet(txm, workItemInfo);
return workItemInfo;
}
workItemInfo = em.find(WorkItemInfo.class, id);
TransactionManagerHelper.addToUpdatableSet(txm, workItemInfo);
return workItemInfo;
}
Aggregations