Connected Fetch Read
When "CONNECTED_BATCH" is specified as the Executor type of DBIO, DBIO does not copy the retrieved results into a List and deliver them at once. Instead, it fetches the retrieved data while the connection remains open and delivers each record individually. The following example explains how to use DBIO for Connected Fetch Read.
-
DBIO Executor type
-
Using DBIO in ItemReader
@BxmBean("MMdpCustMng01")
@Scope("step")
@BxmCategory(logicalName = "Sample customer processing batch module 01")
public class MMdpCustMng01 implements ItemStream, ItemReader<MMdpCustMng01Dto>
private DEduCustomer001 dEduCustomer001;
private Iterator<DEduCustomer001SelectList01OutDto> iterator; //(1)
@Override
@BxmCategory(logicalName = "Sample customer processing Open")
public void open(ExecutionContext executionContext) throws ItemStreamException {
if(dEduCustomer001 == null)
{
dEduCustomer001 = DefaultApplicationContext.getBean(DEduCustomer001.class);
}
DEduCustomer001SelectList01InDto inDto = new DEduCustomer001SelectList01InDto();
inDto.setAddrCd("A1");
iterator = dEduCustomer001.selectList01(inDto).iterator(); //(1)
}
@Override
@BxmCategory(logicalName = "Sample customer processing Read")
public MMdpCustMng01Dto read() throws Exception, UnexpectedInputException
, ParseException, NonTransientResourceException {
MMdpCustMng01Dto output = null;
if(iterator.hasNext()) //(2)
{
DEduCustomer001SelectList01OutDto customer = iterator.next();
output = new MMdpCustMng01Dto();
output.setCustId(customer.getCustId()); // set [Customer ID]
}
return output;
}
@Override
@BxmCategory(logicalName = "Sample customer processing Update")
public void update(ExecutionContext executionContext) throws ItemStreamException {
}
@Override
@BxmCategory(logicalName = "Sample customer processing Close")
public void close() throws ItemStreamException {
DasUtils.disconnectDasExecutor(iterator); //(3)
}
(1) In a batch application that uses a "CONNECTED_BATCH" Executor DBIO, a large volume of data is retrieved and processed, so a List that delivers the entire result set cannot be used. Instead, as shown in the example code, an Iterator is used.
(2) In the read() method that implements ItemReader, it checks whether there is a next element in the iterator and returns the next data.
(3) In the close() method, which is called when the Step is completed, disconnect() is explicitly called so that the connection session is disconnected for the DBIO whose connection is being maintained.