use of org.activiti.engine.impl.persistence.entity.ExecutionEntityManager in project Activiti by Activiti.
the class ScopeUtil method throwCompensationEvent.
/**
* we create a separate execution for each compensation handler invocation.
*/
public static void throwCompensationEvent(List<CompensateEventSubscriptionEntity> eventSubscriptions, DelegateExecution execution, boolean async) {
ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager();
// first spawn the compensating executions
for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
ExecutionEntity compensatingExecution = null;
// where the compensating execution is created when leaving the subprocess and holds snapshot data).
if (eventSubscription.getConfiguration() != null) {
compensatingExecution = executionEntityManager.findById(eventSubscription.getConfiguration());
compensatingExecution.setParent(compensatingExecution.getProcessInstance());
compensatingExecution.setEventScope(false);
} else {
compensatingExecution = executionEntityManager.createChildExecution((ExecutionEntity) execution);
eventSubscription.setConfiguration(compensatingExecution.getId());
}
}
// signal compensation events in reverse order of their 'created' timestamp
Collections.sort(eventSubscriptions, new Comparator<EventSubscriptionEntity>() {
public int compare(EventSubscriptionEntity o1, EventSubscriptionEntity o2) {
return o2.getCreated().compareTo(o1.getCreated());
}
});
for (CompensateEventSubscriptionEntity compensateEventSubscriptionEntity : eventSubscriptions) {
Context.getCommandContext().getEventSubscriptionEntityManager().eventReceived(compensateEventSubscriptionEntity, null, async);
}
}
use of org.activiti.engine.impl.persistence.entity.ExecutionEntityManager in project Activiti by Activiti.
the class FindActiveActivityIdsCmd method execute.
public List<String> execute(CommandContext commandContext) {
if (executionId == null) {
throw new ActivitiIllegalArgumentException("executionId is null");
}
ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
ExecutionEntity execution = executionEntityManager.findById(executionId);
if (execution == null) {
throw new ActivitiObjectNotFoundException("execution " + executionId + " doesn't exist", Execution.class);
}
return findActiveActivityIds(execution);
}
use of org.activiti.engine.impl.persistence.entity.ExecutionEntityManager in project Activiti by Activiti.
the class EndExecutionOperation method handleProcessInstanceExecution.
protected void handleProcessInstanceExecution(ExecutionEntity processInstanceExecution) {
ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
// No parent execution == process instance id
String processInstanceId = processInstanceExecution.getId();
logger.debug("No parent execution found. Verifying if process instance {} can be stopped.", processInstanceId);
ExecutionEntity superExecution = processInstanceExecution.getSuperExecution();
SubProcessActivityBehavior subProcessActivityBehavior = null;
// copy variables before destroying the ended sub process instance (call activity)
if (superExecution != null) {
FlowNode superExecutionElement = (FlowNode) superExecution.getCurrentFlowElement();
subProcessActivityBehavior = (SubProcessActivityBehavior) superExecutionElement.getBehavior();
try {
subProcessActivityBehavior.completing(superExecution, processInstanceExecution);
} catch (RuntimeException e) {
logger.error("Error while completing sub process of execution {}", processInstanceExecution, e);
throw e;
} catch (Exception e) {
logger.error("Error while completing sub process of execution {}", processInstanceExecution, e);
throw new ActivitiException("Error while completing sub process of execution " + processInstanceExecution, e);
}
}
int activeExecutions = getNumberOfActiveChildExecutionsForProcessInstance(executionEntityManager, processInstanceId);
if (activeExecutions == 0) {
logger.debug("No active executions found. Ending process instance {} ", processInstanceId);
// note the use of execution here vs processinstance execution for getting the flowelement
executionEntityManager.deleteProcessInstanceExecutionEntity(processInstanceId, execution.getCurrentFlowElement() != null ? execution.getCurrentFlowElement().getId() : null, null, false, false);
} else {
logger.debug("Active executions found. Process instance {} will not be ended.", processInstanceId);
}
Process process = ProcessDefinitionUtil.getProcess(processInstanceExecution.getProcessDefinitionId());
// Execute execution listeners for process end.
if (CollectionUtil.isNotEmpty(process.getExecutionListeners())) {
executeExecutionListeners(process, processInstanceExecution, ExecutionListener.EVENTNAME_END);
}
// and trigger execution afterwards if doing a call activity
if (superExecution != null) {
superExecution.setSubProcessInstance(null);
try {
subProcessActivityBehavior.completed(superExecution);
} catch (RuntimeException e) {
logger.error("Error while completing sub process of execution {}", processInstanceExecution, e);
throw e;
} catch (Exception e) {
logger.error("Error while completing sub process of execution {}", processInstanceExecution, e);
throw new ActivitiException("Error while completing sub process of execution " + processInstanceExecution, e);
}
}
}
use of org.activiti.engine.impl.persistence.entity.ExecutionEntityManager in project Activiti by Activiti.
the class DestroyScopeOperation method run.
@Override
public void run() {
// Find the actual scope that needs to be destroyed.
// This could be the incoming execution, or the first parent execution where isScope = true
// Find parent scope execution
ExecutionEntity scopeExecution = execution.isScope() ? execution : findFirstParentScopeExecution(execution);
if (scopeExecution == null) {
throw new ActivitiException("Programmatic error: no parent scope execution found for boundary event");
}
ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
deleteAllChildExecutions(executionEntityManager, scopeExecution);
// Delete all scope tasks
TaskEntityManager taskEntityManager = commandContext.getTaskEntityManager();
deleteAllScopeTasks(scopeExecution, taskEntityManager);
// Delete all scope jobs
TimerJobEntityManager timerJobEntityManager = commandContext.getTimerJobEntityManager();
deleteAllScopeJobs(scopeExecution, timerJobEntityManager);
// Remove variables associated with this scope
VariableInstanceEntityManager variableInstanceEntityManager = commandContext.getVariableInstanceEntityManager();
removeAllVariablesFromScope(scopeExecution, variableInstanceEntityManager);
commandContext.getHistoryManager().recordActivityEnd(scopeExecution, scopeExecution.getDeleteReason());
executionEntityManager.delete(scopeExecution);
}
use of org.activiti.engine.impl.persistence.entity.ExecutionEntityManager in project Activiti by Activiti.
the class AbstractOperation method findFirstParentScopeExecution.
/**
* Returns the first parent execution of the provided execution that is a scope.
*/
protected ExecutionEntity findFirstParentScopeExecution(ExecutionEntity executionEntity) {
ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
ExecutionEntity parentScopeExecution = null;
ExecutionEntity currentlyExaminedExecution = executionEntityManager.findById(executionEntity.getParentId());
while (currentlyExaminedExecution != null && parentScopeExecution == null) {
if (currentlyExaminedExecution.isScope()) {
parentScopeExecution = currentlyExaminedExecution;
} else {
currentlyExaminedExecution = executionEntityManager.findById(currentlyExaminedExecution.getParentId());
}
}
return parentScopeExecution;
}
Aggregations