@Transactional(propagation = MANDATORY) public int insertWorkflowInstanceAction(final WorkflowInstance instance, final WorkflowInstanceAction action) { int actionId = insertWorkflowInstanceAction(action); insertVariables(action.workflowInstanceId, actionId, instance.getChangedStateVariables()); return actionId; }
@Transactional public void recoverWorkflowInstance(final int instanceId, final WorkflowInstanceAction action) { int executorId = executorInfo.getExecutorId(); int updated = jdbc.update("update nflow_workflow set executor_id = null, status = " + sqlVariants.workflowStatus(inProgress) + " where id = ? and executor_id in (select id from nflow_executor where " + executorInfo.getExecutorGroupCondition() + " and id <> " + executorId + " and expires < current_timestamp)", instanceId); if (updated > 0) { insertWorkflowInstanceAction(action); } }
/** * Update the workflow instance in the database if it is currently not running, and insert the workflow instance action. * If the state of the instance is not null, the status of the instance is updated based on the new state. * If the state of the instance is null, neither state nor status are updated. * @param instance The instance to be updated. * @param action The action to be inserted. Can be null. * @return True if the update was successful, false otherwise. */ @Transactional public boolean updateWorkflowInstance(WorkflowInstance instance, WorkflowInstanceAction action) { Assert.notNull(instance, "Workflow instance can not be null"); Assert.notNull(action, "Workflow instance action can not be null"); WorkflowInstance.Builder builder = new WorkflowInstance.Builder(instance); if (instance.state == null) { builder.setStatus(null); } else { String type = workflowInstanceDao.getWorkflowInstance(instance.id).type; AbstractWorkflowDefinition<?> definition = workflowDefinitionService.getWorkflowDefinition(type); builder.setStatus(definition.getState(instance.state).getType().getStatus(instance.nextActivation)); } WorkflowInstance updatedInstance = builder.build(); boolean updated = workflowInstanceDao.updateNotRunningWorkflowInstance(updatedInstance); if (updated) { String currentState = workflowInstanceDao.getWorkflowInstanceState(updatedInstance.id); WorkflowInstanceAction updatedAction = new WorkflowInstanceAction.Builder(action).setState(currentState).build(); workflowInstanceDao.insertWorkflowInstanceAction(updatedInstance, updatedAction); } return updated; }
@Override protected void doInTransactionWithoutResult(TransactionStatus status) { updateWorkflowInstance(instance); int parentActionId = insertWorkflowInstanceAction(action); insertVariables(action.workflowInstanceId, parentActionId, changedStateVariables); for (WorkflowInstance childTemplate : childWorkflows) { Integer rootWorkflowId = instance.rootWorkflowId == null ? instance.id : instance.rootWorkflowId; WorkflowInstance childWorkflow = new WorkflowInstance.Builder(childTemplate).setRootWorkflowId(rootWorkflowId) .setParentWorkflowId(instance.id).setParentActionId(parentActionId).build(); insertWorkflowInstance(childWorkflow); } for (WorkflowInstance workflow : workflows) { insertWorkflowInstance(workflow); } } });