Search in sources :

Example 1 with ExecutionEntityManager

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);
    }
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) CompensateEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.CompensateEventSubscriptionEntity) ExecutionEntityManager(org.activiti.engine.impl.persistence.entity.ExecutionEntityManager) CompensateEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.CompensateEventSubscriptionEntity) EventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 2 with ExecutionEntityManager

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);
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ExecutionEntityManager(org.activiti.engine.impl.persistence.entity.ExecutionEntityManager)

Example 3 with ExecutionEntityManager

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);
        }
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) ExecutionEntityManager(org.activiti.engine.impl.persistence.entity.ExecutionEntityManager) ActivitiException(org.activiti.engine.ActivitiException) SubProcessActivityBehavior(org.activiti.engine.impl.delegate.SubProcessActivityBehavior) FlowNode(org.activiti.bpmn.model.FlowNode)

Example 4 with ExecutionEntityManager

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);
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) TaskEntityManager(org.activiti.engine.impl.persistence.entity.TaskEntityManager) ExecutionEntityManager(org.activiti.engine.impl.persistence.entity.ExecutionEntityManager) TimerJobEntityManager(org.activiti.engine.impl.persistence.entity.TimerJobEntityManager) VariableInstanceEntityManager(org.activiti.engine.impl.persistence.entity.VariableInstanceEntityManager)

Example 5 with ExecutionEntityManager

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;
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ExecutionEntityManager(org.activiti.engine.impl.persistence.entity.ExecutionEntityManager)

Aggregations

ExecutionEntityManager (org.activiti.engine.impl.persistence.entity.ExecutionEntityManager)30 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)29 ActivitiException (org.activiti.engine.ActivitiException)11 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)6 SubProcess (org.activiti.bpmn.model.SubProcess)5 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)5 FlowElement (org.activiti.bpmn.model.FlowElement)4 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)4 DelegateExecution (org.activiti.engine.delegate.DelegateExecution)4 ArrayList (java.util.ArrayList)3 Activity (org.activiti.bpmn.model.Activity)3 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)3 CallActivity (org.activiti.bpmn.model.CallActivity)3 Process (org.activiti.bpmn.model.Process)2 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)2 CompensateEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.CompensateEventSubscriptionEntity)2 EventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity)2 EventSubscriptionEntityManager (org.activiti.engine.impl.persistence.entity.EventSubscriptionEntityManager)2 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)2 HashMap (java.util.HashMap)1