DB TO DB
-
Batch job Xml Sample
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:batch-int="http://www.springframework.org/schema/batch-integration"
xsi:schemaLocation="http://www.bankwareglobal.com/schema/batchex http://www.bankwareglobal.com/schema/batchex/spring-batch-ex.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/batch-integration http://www.springframework.org/schema/batch-integration/spring-batch-integration.xsd">
<import resource="classpath:JobConfig.xml"/>
<job-component xmlns="http://www.bankwareglobal.com/schema/batchex" id="jobcomp" with-dependon="true">
<base-package name="bxm.dft.smp.batch.bean">
<include name="MSmpDBToDBBtch*"/>
</base-package>
</job-component>
<!--
* BatchJob : DB TO DB Sample
* BatchStep :
- JSmpDBToDB100 : DB TO DB process
-->
<job id="JSmpDBToDB" xmlns="http://www.bankwareglobal.com/schema/batchex">
<step id="JSmpDBToDB100" parent="parentStep">
<tasklet>
<chunk reader="MSmpDBToDBBtch" processor="MSmpDBToDBBtch" writer="MSmpDBToDBBtch"/>
</tasklet>
</step>
</job>
</beans>
-
Batch source code Sample
@BxmBean("MSmpDBToDBBtch")
@Scope("step")
@BxmCategory(logicalName = "DB TO DB sample")
public class MSmpDBToDBBtch implements ItemReader<MSmpDBToDBBtch01Dto>,
ItemProcessor<MSmpDBToDBBtch01Dto, MSmpDBToDBBtch02Dto>, ItemWriter<MSmpDBToDBBtch02Dto>, ItemStream {
final Logger logger = LoggerFactory.getLogger(this.getClass());
private DSmpEmpTst001 dSmpEmpTst001;
private DSmpEmpTmp001 dSmpEmpTmp100;
private Iterator<DSmpEmpTst001selectList01OutDto> iterator;
/**
* open
* - A method that must be implemented for initialization and is called once by the framework before the step starts.
*/
@Override
@BxmCategory(logicalName = "DB TO DB sample open")
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' value does not exist.");
}
/**
* For the received "deptNo", obtain sample employee information as an Iterator.
*/
DSmpEmpTst001selectList01InDto inDto = new DSmpEmpTst001selectList01InDto();
inDto.setFeduDeptNo(Integer.parseInt(feduDeptNo));
iterator = dSmpEmpTst001.selectList01(inDto).iterator();
}
/**
* read
* - Performs the role of reading target data record by record from DB or file.
*/
@Override
@BxmCategory(logicalName = "DB TO DB sample read")
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;
}
/**
* process
* - Performs the role of processing target data record by record according to business requirements.
*/
@Override
@BxmCategory(logicalName = "DB TO DB sample process")
public MSmpDBToDBBtch02Dto process(MSmpDBToDBBtch01Dto in) throws Exception {
MSmpDBToDBBtch02Dto out = new MSmpDBToDBBtch02Dto();
out.setFeduEmpNo(in.getFeduEmpNo()); // set [FW sample employee number]
out.setFeduEmpNm(in.getFeduEmpNm()); // set [FW sample employee name]
out.setFeduOccpNm(in.getFeduOccpNm()); // set [FW sample occupation name]
out.setFeduMngrEmpNo(in.getFeduMngrEmpNo()); // set [FW sample manager employee number]
out.setFeduHireDt(in.getFeduHireDt()); // set [FW sample hire date]
out.setFeduPayAmt(in.getFeduPayAmt()); // set [FW sample salary amount]
out.setFeduDeptNo(in.getFeduDeptNo()); // set [FW sample department number]
return out;
}
/**
* write
* - Performs the role of recording target result data to DB or file per commit unit.
*/
@Override
@BxmCategory(logicalName = "DB TO DB sample write")
public void write(List<? extends MSmpDBToDBBtch02Dto> in) throws Exception {
if(dSmpEmpTmp100 == null) {
dSmpEmpTmp100 = DefaultApplicationContext.getBean(DSmpEmpTmp001.class);
}
/**
* While looping through the Items passed as a List, configure the DTO for DB Insert in List form.
*/
List<DSmpEmpTmp001Dto> dSmpEmpTmp100insert02InDtos = new ArrayList<DSmpEmpTmp001Dto>();
for (MSmpDBToDBBtch02Dto mSmpDBToDBBtch02Dto : in) {
DSmpEmpTmp001Dto smpEmpTmp001Dto = new DSmpEmpTmp001Dto();
smpEmpTmp001Dto.setFeduEmpNo(mSmpDBToDBBtch02Dto.getFeduEmpNo()); // set [FW sample employee number]
smpEmpTmp001Dto.setFeduEmpNm(mSmpDBToDBBtch02Dto.getFeduEmpNm()); // set [FW sample employee name]
smpEmpTmp001Dto.setFeduOccpNm(mSmpDBToDBBtch02Dto.getFeduOccpNm()); // set [FW sample occupation name]
smpEmpTmp001Dto.setFeduMngrEmpNo(mSmpDBToDBBtch02Dto.getFeduMngrEmpNo()); // set [FW sample manager employee number]
smpEmpTmp001Dto.setFeduHireDt(mSmpDBToDBBtch02Dto.getFeduHireDt()); // set [FW sample hire date]
smpEmpTmp001Dto.setFeduPayAmt(mSmpDBToDBBtch02Dto.getFeduPayAmt()); // set [FW sample salary amount]
smpEmpTmp001Dto.setFeduDeptNo(mSmpDBToDBBtch02Dto.getFeduDeptNo()); // set [FW sample department number]
dSmpEmpTmp100insert02InDtos.add(smpEmpTmp001Dto);
}
/**
* insert processing
* - Note 1: For C/U/D processing with CONNECTED_BATCH, queries are executed in bulk at commit time.
* - Note 2: For C/U/D processing with CONNECTED_BATCH, processing is performed at commit time, so the return value is an arbitrary negative value (meaningless).
*/
dSmpEmpTmp100.insert02(dSmpEmpTmp100insert02InDtos);
}
/**
* update
* - A method that must be implemented to record the progress status and is called by the framework at each commit section.
*/
@Override
@BxmCategory(logicalName = "DB TO DB sample update")
public void update(ExecutionContext executionContext) throws ItemStreamException {
}
/**
* close
* - A method that must be implemented for resource cleanup work and is called by the framework when the Step is completed.
*/
@Override
@BxmCategory(logicalName = "DB TO DB sample close")
public void close() throws ItemStreamException {
DasUtils.disconnectDasExecutor(iterator);
}
}