Search in sources :

Example 11 with ExecutionEntityManager

use of org.activiti.engine.impl.persistence.entity.ExecutionEntityManager in project Activiti by Activiti.

the class GatewayActivityBehavior method lockFirstParentScope.

protected void lockFirstParentScope(DelegateExecution execution) {
    ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager();
    boolean found = false;
    ExecutionEntity parentScopeExecution = null;
    ExecutionEntity currentExecution = (ExecutionEntity) execution;
    while (!found && currentExecution != null && currentExecution.getParentId() != null) {
        parentScopeExecution = executionEntityManager.findById(currentExecution.getParentId());
        if (parentScopeExecution != null && parentScopeExecution.isScope()) {
            found = true;
        }
        currentExecution = parentScopeExecution;
    }
    parentScopeExecution.forceUpdate();
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ExecutionEntityManager(org.activiti.engine.impl.persistence.entity.ExecutionEntityManager)

Example 12 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)

Example 13 with ExecutionEntityManager

use of org.activiti.engine.impl.persistence.entity.ExecutionEntityManager in project Activiti by Activiti.

the class BoundaryEventActivityBehavior method executeInterruptingBehavior.

protected void executeInterruptingBehavior(ExecutionEntity executionEntity, CommandContext commandContext) {
    // The destroy scope operation will look for the parent execution and
    // destroy the whole scope, and leave the boundary event using this parent execution.
    // 
    // The take outgoing seq flows operation below (the non-interrupting else clause) on the other hand uses the
    // child execution to leave, which keeps the scope alive.
    // Which is what we need here.
    ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
    ExecutionEntity attachedRefScopeExecution = executionEntityManager.findById(executionEntity.getParentId());
    ExecutionEntity parentScopeExecution = null;
    ExecutionEntity currentlyExaminedExecution = executionEntityManager.findById(attachedRefScopeExecution.getParentId());
    while (currentlyExaminedExecution != null && parentScopeExecution == null) {
        if (currentlyExaminedExecution.isScope()) {
            parentScopeExecution = currentlyExaminedExecution;
        } else {
            currentlyExaminedExecution = executionEntityManager.findById(currentlyExaminedExecution.getParentId());
        }
    }
    if (parentScopeExecution == null) {
        throw new ActivitiException("Programmatic error: no parent scope execution found for boundary event");
    }
    deleteChildExecutions(attachedRefScopeExecution, executionEntity, commandContext);
    // set new parent for boundary event execution
    executionEntity.setParent(parentScopeExecution);
    Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(executionEntity, true);
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ExecutionEntityManager(org.activiti.engine.impl.persistence.entity.ExecutionEntityManager)

Example 14 with ExecutionEntityManager

use of org.activiti.engine.impl.persistence.entity.ExecutionEntityManager in project Activiti by Activiti.

the class CancelEndEventActivityBehavior method deleteChildExecutions.

protected void deleteChildExecutions(ExecutionEntity parentExecution, ExecutionEntity notToDeleteExecution, CommandContext commandContext, String deleteReason) {
    // Delete all child executions
    ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
    Collection<ExecutionEntity> childExecutions = executionEntityManager.findChildExecutionsByParentExecutionId(parentExecution.getId());
    if (CollectionUtil.isNotEmpty(childExecutions)) {
        for (ExecutionEntity childExecution : childExecutions) {
            if (!(childExecution.getId().equals(notToDeleteExecution.getId()))) {
                deleteChildExecutions(childExecution, notToDeleteExecution, commandContext, deleteReason);
            }
        }
    }
    executionEntityManager.deleteExecutionAndRelatedData(parentExecution, deleteReason);
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ExecutionEntityManager(org.activiti.engine.impl.persistence.entity.ExecutionEntityManager)

Example 15 with ExecutionEntityManager

use of org.activiti.engine.impl.persistence.entity.ExecutionEntityManager in project Activiti by Activiti.

the class EndExecutionOperation method handleRegularExecution.

protected void handleRegularExecution() {
    ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
    // There will be a parent execution (or else we would be in the process instance handling method)
    ExecutionEntity parentExecution = executionEntityManager.findById(execution.getParentId());
    // If the execution is a scope, all the child executions must be deleted first.
    if (execution.isScope()) {
        executionEntityManager.deleteChildExecutions(execution, null);
    }
    // Delete current execution
    logger.debug("Ending execution {}", execution.getId());
    executionEntityManager.deleteExecutionAndRelatedData(execution, null);
    logger.debug("Parent execution found. Continuing process using execution {}", parentExecution.getId());
    // When ending an execution in a multi instance subprocess , special care is needed
    if (isEndEventInMultiInstanceSubprocess(execution)) {
        handleMultiInstanceSubProcess(executionEntityManager, parentExecution);
        return;
    }
    SubProcess subProcess = execution.getCurrentFlowElement().getSubProcess();
    // If not (eg an embedded subprocess still has active elements, we cannot continue)
    if (getNumberOfActiveChildExecutionsForExecution(executionEntityManager, parentExecution.getId()) == 0 || isAllEventScopeExecutions(executionEntityManager, parentExecution)) {
        ExecutionEntity executionToContinue = null;
        if (subProcess != null) {
            if (subProcess.isForCompensation()) {
                Context.getAgenda().planEndExecutionOperation(parentExecution);
            } else {
                executionToContinue = handleSubProcessEnd(executionEntityManager, parentExecution, subProcess);
            }
        } else {
            // In the 'regular' case (not being in a subprocess), we use the parent execution to
            // continue process instance execution
            executionToContinue = handleRegularExecutionEnd(executionEntityManager, parentExecution);
        }
        if (executionToContinue != null) {
            // not the process instance root execution (otherwise the process instance is finished)
            if (executionToContinue.isProcessInstanceType()) {
                handleProcessInstanceExecution(executionToContinue);
            } else {
                Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(executionToContinue, true);
            }
        }
    }
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) 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