StepDAO { public Long initStep(Integer subPid) { Session session = sessionFactory.openSession(); Long subInstanceExecId = null; try { session.beginTransaction(); Process subProcess = (Process) session.get(Process.class, subPid); Process parentProcess = null; if (subProcess != null) { parentProcess = subProcess.getProcess(); } ExecStatus runningExecState = new ExecStatus(); runningExecState.setExecStateId(2); Criteria checkDeletedProcess = session.createCriteria(Process.class).add(Restrictions.eq("processId", subPid)).add(Restrictions.eq("deleteFlag", true)); Integer deletedProcessCount = checkDeletedProcess.list().size(); LOGGER.info("Deleted process count :" + deletedProcessCount); Criteria checkParentProcessExec = session.createCriteria(InstanceExec.class).add(Restrictions.and(Restrictions.eq(PROCESS, parentProcess), Restrictions.eq(EXECSTATUS, runningExecState))); Integer runningProcessCount = checkParentProcessExec.list().size(); LOGGER.info("Running parent process count : " + runningProcessCount); Criteria checkSubProcessExec = session.createCriteria(InstanceExec.class).add(Restrictions.and(Restrictions.eq(PROCESS, subProcess), Restrictions.eq(EXECSTATUS, runningExecState))); Integer runningSubProcessCount = checkSubProcessExec.list().size(); LOGGER.info("Running sub process count :" + runningSubProcessCount); List<BatchConsumpQueue> batchConsumpQueueList = new ArrayList<BatchConsumpQueue>(); Criteria checkSubProcessBCQ = session.createCriteria(BatchConsumpQueue.class).add(Restrictions.and(Restrictions.eq(PROCESS, subProcess), Restrictions.isNotNull(BATCHBYTARGETBATCHID))); batchConsumpQueueList = checkSubProcessBCQ.list(); LOGGER.info("batchConsumpQueueList is "+batchConsumpQueueList); if (parentProcess == null) { throw new MetadataException("Invalid sub-process. sub_pid =" + subPid); } else if (deletedProcessCount != 0) { throw new MetadataException("This is a deleted sub-process. pid =" + subPid); } else if (runningProcessCount == 0) { throw new MetadataException("The parent process is not under execution, sub_pid=" + subPid); } else if (runningSubProcessCount != 0) { throw new MetadataException("This sub process is already under execution ! sub_pid=" + subPid); } else { InstanceExec subProcessExec = new InstanceExec(); subProcessExec.setProcess(subProcess); java.util.Date date = new java.util.Date(); subProcessExec.setStartTs(new Timestamp(date.getTime())); subProcessExec.setExecStatus(runningExecState); subInstanceExecId = (Long) session.save(subProcessExec); LOGGER.info("The instance-exec-id of sub process inserted :" + subInstanceExecId); for (BatchConsumpQueue bcq : batchConsumpQueueList) { bcq.setStartTs(new Timestamp(date.getTime())); session.update(bcq); } session.getTransaction().commit(); } } catch (MetadataException e) { session.getTransaction().rollback(); LOGGER.error("Error occurred", e); throw e; } finally { session.close(); } return subInstanceExecId; }  Long initStep(Integer subPid); void termStep(Integer subPid); void haltStep(Integer subPid);  }
@Ignore @Test public void testInitStep() throws Exception { Long sub_instance_exec_id = stepDAO.initStep(10805); LOGGER.info("The sub process init step test executed with instance-exec-id :" + sub_instance_exec_id); }