Java Code Examples for org.flowable.engine.impl.persistence.entity.ExecutionEntity#isScope()

The following examples show how to use org.flowable.engine.impl.persistence.entity.ExecutionEntity#isScope() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TakeOutgoingSequenceFlowsOperation.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * @param executionEntityToIgnore
 *            The execution entity which we can ignore to be ended, as it's the execution currently being handled in this operation.
 */
protected ExecutionEntity findNextParentScopeExecutionWithAllEndedChildExecutions(ExecutionEntity executionEntity, ExecutionEntity executionEntityToIgnore) {
    if (executionEntity.getParentId() != null) {
        ExecutionEntity scopeExecutionEntity = executionEntity.getParent();

        // Find next scope
        while (!scopeExecutionEntity.isScope() || !scopeExecutionEntity.isProcessInstanceType()) {
            scopeExecutionEntity = scopeExecutionEntity.getParent();
        }

        // Return when all child executions for it are ended
        if (allChildExecutionsEnded(scopeExecutionEntity, executionEntityToIgnore)) {
            return scopeExecutionEntity;
        }

    }
    return null;
}
 
Example 2
Source File: GatewayActivityBehavior.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void lockFirstParentScope(DelegateExecution execution) {

        ExecutionEntityManager executionEntityManager = CommandContextUtil.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();
    }
 
Example 3
Source File: ParallelMultiInstanceBehavior.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void lockFirstParentScope(DelegateExecution execution) {

        ExecutionEntityManager executionEntityManager = CommandContextUtil.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();
    }
 
Example 4
Source File: AbstractOperation.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the first parent execution of the provided execution that is a scope.
 */
protected ExecutionEntity findFirstParentScopeExecution(ExecutionEntity executionEntity) {
    ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager(commandContext);
    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;
}
 
Example 5
Source File: TakeOutgoingSequenceFlowsOperation.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void cleanupCompensation() {

        // The compensation is at the end here. Simply stop the execution.
        CommandContextUtil.getExecutionEntityManager(commandContext).deleteExecutionAndRelatedData(execution, null, false);

        ExecutionEntity parentExecutionEntity = execution.getParent();
        if (parentExecutionEntity.isScope() && !parentExecutionEntity.isProcessInstanceType()) {

            if (allChildExecutionsEnded(parentExecutionEntity, null)) {

                // Go up the hierarchy to check if the next scope is ended too.
                // This could happen if only the compensation activity is still active, but the
                // main process is already finished.

                ExecutionEntity executionEntityToEnd = parentExecutionEntity;
                ExecutionEntity scopeExecutionEntity = findNextParentScopeExecutionWithAllEndedChildExecutions(parentExecutionEntity, parentExecutionEntity);
                while (scopeExecutionEntity != null) {
                    executionEntityToEnd = scopeExecutionEntity;
                    scopeExecutionEntity = findNextParentScopeExecutionWithAllEndedChildExecutions(scopeExecutionEntity, parentExecutionEntity);
                }

                if (executionEntityToEnd.isProcessInstanceType()) {
                    agenda.planEndExecutionOperation(executionEntityToEnd);
                } else {
                    agenda.planDestroyScopeOperation(executionEntityToEnd);
                }

            }
        }
    }
 
Example 6
Source File: BoundaryEventActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
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 = CommandContextUtil.getExecutionEntityManager(commandContext);
    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 FlowableException("Programmatic error: no parent scope execution found for boundary event");
    }

    deleteChildExecutions(attachedRefScopeExecution, executionEntity, commandContext);

    // set new parent for boundary event execution
    executionEntity.setParent(parentScopeExecution);

    // TakeOutgoingSequenceFlow will not set history correct when no outgoing sequence flow for boundary event
    // (This is a theoretical case ... shouldn't use a boundary event without outgoing sequence flow ...)
    if (executionEntity.getCurrentFlowElement() instanceof FlowNode
            && ((FlowNode) executionEntity.getCurrentFlowElement()).getOutgoingFlows().isEmpty()) {
        CommandContextUtil.getActivityInstanceEntityManager(commandContext).recordActivityEnd(executionEntity, null);
    }

    CommandContextUtil.getAgenda(commandContext).planTakeOutgoingSequenceFlowsOperation(executionEntity, true);
}
 
Example 7
Source File: BoundaryEventActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void executeNonInterruptingBehavior(ExecutionEntity executionEntity, CommandContext commandContext) {
    // Non-interrupting: the current execution is given the first parent
    // scope (which isn't its direct parent)
    //
    // Why? Because this execution does NOT have anything to do with
    // the current parent execution (the one where the boundary event is on): when it is deleted or whatever,
    // this does not impact this new execution at all, it is completely independent in that regard.

    // Note: if the parent of the parent does not exists, this becomes a concurrent execution in the process instance!

    ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager(commandContext);

    ExecutionEntity parentExecutionEntity = executionEntityManager.findById(executionEntity.getParentId());

    ExecutionEntity scopeExecution = null;
    ExecutionEntity currentlyExaminedExecution = executionEntityManager.findById(parentExecutionEntity.getParentId());
    while (currentlyExaminedExecution != null && scopeExecution == null) {
        if (currentlyExaminedExecution.isScope()) {
            scopeExecution = currentlyExaminedExecution;
        } else {
            currentlyExaminedExecution = executionEntityManager.findById(currentlyExaminedExecution.getParentId());
        }
    }

    if (scopeExecution == null) {
        throw new FlowableException("Programmatic error: no parent scope execution found for boundary event");
    }

    CommandContextUtil.getActivityInstanceEntityManager(commandContext).recordActivityEnd(executionEntity, null);

    ExecutionEntity nonInterruptingExecution = executionEntityManager.createChildExecution(scopeExecution);
    nonInterruptingExecution.setActive(false);
    nonInterruptingExecution.setCurrentFlowElement(executionEntity.getCurrentFlowElement());

    CommandContextUtil.getAgenda(commandContext).planTakeOutgoingSequenceFlowsOperation(nonInterruptingExecution, true);
}