@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); } } });
/** * Insert the workflow instance to the database and return the id of the * instance. If the instance already exists, return the id of the existing * instance. * @param instance The workflow instance to be inserted. * @return The id of the inserted or existing workflow instance. */ @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "getInitialState().toString() has no cast") public int insertWorkflowInstance(WorkflowInstance instance) { WorkflowInstance processedInstance = workflowInstancePreProcessor.process(instance); int id = workflowInstanceDao.insertWorkflowInstance(processedInstance); if (id == -1 && !isEmpty(instance.externalId)) { QueryWorkflowInstances query = new QueryWorkflowInstances.Builder().addTypes(instance.type).setExternalId(instance.externalId).build(); id = workflowInstanceDao.queryWorkflowInstances(query).get(0).id; } return id; }