BatchEnqueuerDAO { public List<com.wipro.ats.bdre.md.beans.table.BatchConsumpQueue> batchEnqueue(RegisterFileInfo registerFileInfo) { Session session = sessionFactory.openSession(); List<com.wipro.ats.bdre.md.beans.table.BatchConsumpQueue> bcqs = new ArrayList<com.wipro.ats.bdre.md.beans.table.BatchConsumpQueue>(); try { Long finalBatchID; session.beginTransaction(); if (registerFileInfo.getBatchId() == null) { Batch batch = new Batch(); batch.setInstanceExec(null); batch.setBatchType("file"); session.save(batch); finalBatchID = batch.getBatchId(); } else { finalBatchID = registerFileInfo.getBatchId(); } LOGGER.info("FinalBatchId is" + finalBatchID); File file = new File(); Batch batch = new Batch(); batch.setBatchId(finalBatchID); file.setBatch(batch); Servers servers = new Servers(); servers.setServerId(registerFileInfo.getServerId()); file.setServers(servers); FileId fileId = new FileId(); fileId.setBatchId(finalBatchID); fileId.setServerId(registerFileInfo.getServerId()); fileId.setCreationTs(registerFileInfo.getCreationTs()); fileId.setFileHash(registerFileInfo.getFileHash()); fileId.setFileSize(registerFileInfo.getFileSize()); fileId.setPath(registerFileInfo.getPath()); file.setId(fileId); session.save(file); Integer proId; List<Process> list = session.createCriteria(Process.class).add(Restrictions.eq("enqueuingProcessId", registerFileInfo.getParentProcessId())).list(); Iterator<Process> iterator = list.iterator(); LOGGER.info("Total number of processes is" + list.size()); while (iterator.hasNext()) { proId = iterator.next().getProcessId(); BatchConsumpQueue batchConsumpQueue = new BatchConsumpQueue(); Batch sourceBatch = (Batch) session.get(Batch.class, finalBatchID); batchConsumpQueue.setBatchBySourceBatchId(sourceBatch); batchConsumpQueue.setSourceProcessId(registerFileInfo.getParentProcessId()); batchConsumpQueue.setInsertTs(new Date()); batchConsumpQueue.setBatchStatus((BatchStatus) session.get(BatchStatus.class, 0)); batchConsumpQueue.setBatchMarking(registerFileInfo.getBatchMarking()); batchConsumpQueue.setProcess((Process) session.get(Process.class, proId)); session.save(batchConsumpQueue); } Batch batch1 = (Batch) session.get(Batch.class, finalBatchID); List<BatchConsumpQueue> list1 = session.createCriteria(BatchConsumpQueue.class).add(Restrictions.eq("batchBySourceBatchId", batch1)).list(); LOGGER.info("Total size of Batches in queue is" + list1.size()); Iterator iterator1 = list1.iterator(); while (iterator1.hasNext()) { BatchConsumpQueue batchConsumpQueue = (BatchConsumpQueue) iterator1.next(); com.wipro.ats.bdre.md.beans.table.BatchConsumpQueue batchConsumpQueue1 = new com.wipro.ats.bdre.md.beans.table.BatchConsumpQueue(); batchConsumpQueue1.setSourceBatchId(batchConsumpQueue.getBatchBySourceBatchId().getBatchId()); if (batchConsumpQueue.getBatchByTargetBatchId() != null) batchConsumpQueue1.setTargetBatchId(batchConsumpQueue.getBatchByTargetBatchId().getBatchId()); batchConsumpQueue1.setQueueId(batchConsumpQueue.getQueueId()); batchConsumpQueue1.setInsertTs(batchConsumpQueue.getInsertTs()); batchConsumpQueue1.setSourceProcessId(batchConsumpQueue.getSourceProcessId()); batchConsumpQueue1.setStartTs(batchConsumpQueue.getStartTs()); bcqs.add(batchConsumpQueue1); } session.getTransaction().commit(); return bcqs; } catch (MetadataException e) { LOGGER.error("Error occurred", e); session.getTransaction().rollback(); return bcqs; } finally { session.close(); } }  List<com.wipro.ats.bdre.md.beans.table.BatchConsumpQueue> batchEnqueue(RegisterFileInfo registerFileInfo);  }
@Test public void batchEnqueuerTest() throws Exception { RegisterFileInfo registerFileInfo = new RegisterFileInfo(); registerFileInfo.setParentProcessId(1); registerFileInfo.setServerId(123461); registerFileInfo.setPath("1"); registerFileInfo.setFileSize(Long.valueOf(1)); registerFileInfo.setFileHash("1"); Calendar calendar = Calendar.getInstance(); java.util.Date now = calendar.getTime(); registerFileInfo.setCreationTs(new Timestamp(now.getTime())); registerFileInfo.setBatchId(Long.valueOf(0)); registerFileInfo.setBatchMarking("1"); List<BatchConsumpQueue> batchConsumpQueues = batchEnqueuerDAO.batchEnqueue(registerFileInfo); LOGGER.info("batchConsumption Queues are " + batchConsumpQueues); }