LineageByBatchDAO { public List<GetLineageByBatchInfo> lineageByBatch(GetLineageByBatchInfo getLineageByBatchInfo) { Session session = sessionFactory.openSession(); session.beginTransaction(); Batch batch = (Batch) session.get(Batch.class, getLineageByBatchInfo.getTargetBatchId()); List<GetLineageByBatchInfo> outputList = new ArrayList<GetLineageByBatchInfo>(); try { if (batch != null) { Process process = new Process(); if (batch.getInstanceExec() != null) { Long sourceInstanceExecutionId = batch.getInstanceExec().getInstanceExecId(); LOGGER.info("source instance execution id is" + sourceInstanceExecutionId); process = (Process) session.get(Process.class, batch.getInstanceExec().getProcess().getProcessId()); LOGGER.info("processid is " + batch.getInstanceExec().getProcess().getProcessId()); } List<BatchConsumpQueue> list = session.createCriteria(BatchConsumpQueue.class).add(Restrictions.eq("batchByTargetBatchId", batch)).list(); LOGGER.info("size of baches in the queue" + list.size()); List<ArchiveConsumpQueue> list1 = session.createCriteria(ArchiveConsumpQueue.class).add(Restrictions.eq("batchByTargetBatchId", batch)).list(); LOGGER.info("size of baches completed in the queue" + list1.size()); Iterator iterator = list.iterator(); while (iterator.hasNext()) { BatchConsumpQueue batchConsumpQueue = (BatchConsumpQueue) iterator.next(); GetLineageByBatchInfo getLineageByBatchInfo1 = new GetLineageByBatchInfo(); getLineageByBatchInfo1.setExecState(batch.getInstanceExec().getExecStatus().getExecStateId()); getLineageByBatchInfo1.setTargetBatchId(getLineageByBatchInfo.getTargetBatchId()); getLineageByBatchInfo1.setSourceBatchId(batchConsumpQueue.getBatchBySourceBatchId().getBatchId()); getLineageByBatchInfo1.setInstanceExecId(batch.getInstanceExec().getInstanceExecId()); getLineageByBatchInfo1.setStartTime(new java.sql.Timestamp(batch.getInstanceExec().getStartTs().getTime())); if (batch.getInstanceExec().getEndTs() != null) { getLineageByBatchInfo1.setEndTime(new java.sql.Timestamp(batch.getInstanceExec().getEndTs().getTime())); } getLineageByBatchInfo1.setProcessDesc(process.getDescription()); getLineageByBatchInfo1.setProcessName(process.getProcessName()); getLineageByBatchInfo1.setProcessId(process.getProcessId()); outputList.add(getLineageByBatchInfo1); } Iterator iterator1 = list1.iterator(); while (iterator1.hasNext()) { ArchiveConsumpQueue archiveConsumpQueue = (ArchiveConsumpQueue) iterator1.next(); GetLineageByBatchInfo getLineageByBatchInfo1 = new GetLineageByBatchInfo(); getLineageByBatchInfo1.setExecState(batch.getInstanceExec().getExecStatus().getExecStateId()); getLineageByBatchInfo1.setTargetBatchId(getLineageByBatchInfo.getTargetBatchId()); getLineageByBatchInfo1.setSourceBatchId(archiveConsumpQueue.getBatchBySourceBatchId().getBatchId()); getLineageByBatchInfo1.setInstanceExecId(batch.getInstanceExec().getInstanceExecId()); getLineageByBatchInfo1.setStartTime(new java.sql.Timestamp(batch.getInstanceExec().getStartTs().getTime())); if (batch.getInstanceExec().getEndTs() != null) getLineageByBatchInfo1.setEndTime(new java.sql.Timestamp(batch.getInstanceExec().getEndTs().getTime())); getLineageByBatchInfo1.setProcessDesc(process.getDescription()); getLineageByBatchInfo1.setProcessName(process.getProcessName()); getLineageByBatchInfo1.setProcessId(process.getProcessId()); outputList.add(getLineageByBatchInfo1); } LOGGER.info("total no of objects to be returned is" + outputList.size()); session.getTransaction().commit(); } else { throw new MetadataException("Invalid Target BatchId"); } } catch (Exception e) { session.getTransaction().rollback(); throw new MetadataException(e); } finally { session.close(); } return outputList; }  List<GetLineageByBatchInfo> lineageByBatch(GetLineageByBatchInfo getLineageByBatchInfo);  }
@Test public void testLineageByBatch() { GetLineageByBatchInfo getLineageByBatchInfo = new GetLineageByBatchInfo(); getLineageByBatchInfo.setTargetBatchId(0); List<GetLineageByBatchInfo> outputList = lineageByBatchDAO.lineageByBatch(getLineageByBatchInfo); LOGGER.info("total objects returned is " + outputList.size()); for (GetLineageByBatchInfo output : outputList) { LOGGER.info("TargetBatch Id is " + output.getTargetBatchId() + " source Batch Id is " + output.getSourceBatchId()); } }