ItemStream, ItemReader Interface
Implement the ItemStream and ItemReader Interface to read data for batch processing.
(1) Implementing ItemStream
In the open method, check the input parameter values and call the DBIO that performs data retrieval processing (Iterator).
In the close method, terminate the DB connection information.
public class MSmpDBToDBBtch implements ItemStream { // Add ItemStream Interface
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException
{
if(dSmpEmpTst001 == null)
{
dSmpEmpTst001 = DefaultApplicationContext.getBean(DSmpEmpTst001.class);
}
/**
* Get batch input parameter "deptNo"
*/
String feduDeptNo = DefaultBatchApplicationContext.getJobParameter("deptNo");
if(StringUtils.isEmpty(feduDeptNo))
{
throw new ItemStreamException("The batch input argument 'deptNo' does not exist.");
}
/**
* For the received "deptNo", retrieve sample employee information as an Iterator.
*/
DSmpEmpTst001selectList01InDto inDto = new DSmpEmpTst001selectList01InDto();
inDto.setFeduDeptNo(Integer.parseInt(feduDeptNo));
iterator = dSmpEmpTst001.selectList01(inDto).iterator();
}
@Override
public void update(ExecutionContext executionContext) throws ItemStreamException
{
}
@Override
public void close() throws ItemStreamException
{
DasUtils.disconnectDasExecutor(iterator);
}
}
(2) Implementing ItemReader
From the Iterator that performed the retrieval processing, fetch the data one record at a time, return it to the ItemProcessor, and when no data exists, return null to terminate the process.
public class MSmpDBToDBBtch implements ItemReader<MSmpDBToDBBtch01Dto>, ItemStream { // Add ItemReader Interface
@Override
public MSmpDBToDBBtch01Dto read() throws Exception, UnexpectedInputException,
ParseException, NonTransientResourceException
{
MSmpDBToDBBtch01Dto out = null;
if(iterator.hasNext())
{
out = new MSmpDBToDBBtch01Dto();
DSmpEmpTst001selectList01OutDto input = iterator.next();
out.setFeduEmpNo(input.getFeduEmpNo()); // set [FW sample employee number]
out.setFeduEmpNm(input.getFeduEmpNm()); // set [FW sample employee name]
out.setFeduOccpNm(input.getFeduOccpNm()); // set [FW sample occupation name]
out.setFeduMngrEmpNo(input.getFeduMngrEmpNo()); // set [FW sample manager employee number]
out.setFeduHireDt(input.getFeduHireDt()); // set [FW sample hire date]
out.setFeduPayAmt(input.getFeduPayAmt()); // set [FW sample salary amount]
out.setFeduDeptNo(input.getFeduDeptNo()); // set [FW sample department number]
}
return out;
}