DB TO File(Fixed)
-
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="MSmpDBToFixed*Btch"/>
</base-package>
</job-component>
<!--
* Batch job : DB TO FILE(FIXED) sample
* Batch step
- JSmpDBToFixed100 : DB TO FILE(FIXED) sample initialization process
- JSmpDBToFixed200 : Retrieves sample employee information corresponding to the input "deptNo" and performs File Write processing.
-->
<job id="JSmpDBToFixed" xmlns="http://www.bankwareglobal.com/schema/batchex">
<step id="JSmpDBToFixed100" next="JSmpDBToFixed200" parent="parentStep">
<tasklet ref="MSmpDBToFixedInitBtch"/>
</step>
<step id="JSmpDBToFixed200" parent="parentStep">
<tasklet>
<chunk reader="MSmpDBToFixedBtch" processor="MSmpDBToFixedBtch" writer="WJSmpDBToFixed200"/>
</tasklet>
</step>
</job>
<!--
* bean configuration for writing sample employee information to Fixed File
-->
<bean id="WJSmpDBToFixed200" parent="WFix" scope="step">
<property name="resource" value="file:///data1/prod/bxm400/dat/fixed_file_#{jobParameters['oDate']}.txt" />
<property name="encoding" value="UTF-8" />
<property name="targetType" value="bxm.dft.smp.batch.bean.dto.MSmpDBToFixedBtch01Dto" />
</bean>
</beans>
-
Batch source code Sample
@BxmBean("MSmpDBToFixedBtch")
@Scope("step")
@BxmCategory(logicalName = "DB TO FILE(FIXED) sample")
public class MSmpDBToFixedBtch implements ItemStream, ItemReader<MSmpDBToFixedBtch01Dto>,
ItemProcessor<MSmpDBToFixedBtch01Dto, MSmpDBToFixedBtch01Dto> {
final Logger logger = LoggerFactory.getLogger(this.getClass());
private DSmpEmpTst001 dSmpEmpTst001; // sample employee information TST
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 = "open : sample employee information Iterator processing")
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 input "deptNo", retrieve 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 per record from DB or file.
*/
@Override
@BxmCategory(logicalName = "read : sample employee information Read")
public MSmpDBToFixedBtch01Dto read()
throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
MSmpDBToFixedBtch01Dto out = null;
if (iterator.hasNext()) {
out = new MSmpDBToFixedBtch01Dto();
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 per record according to business requirements.
*/
@Override
@BxmCategory(logicalName = "process : sample employee information processing")
public MSmpDBToFixedBtch01Dto process(MSmpDBToFixedBtch01Dto in) throws Exception {
MSmpDBToFixedBtch01Dto out;
/**
* If the manager employee number does not exist, return null to Skip the corresponding Item.
* - Note: If null is returned from process, the item is not passed to write.
*/
if (in.getFeduMngrEmpNo() == 0) {
logger.warn("The manager number for employee number[{}] is 0. It will be skipped.");
return null;
}
/**
* Execute individual business logic
* ...
* ...
*/
out = in;
return out;
}
/**
* 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 = "update")
public void update(ExecutionContext executionContext) throws ItemStreamException {
}
/**
* close
* - A method that must be implemented for resource cleanup, and is called by the framework when the Step is completed.
*/
@Override
@BxmCategory(logicalName = "close")
public void close() throws ItemStreamException {
if (iterator != null)
DasUtils.disconnectDasExecutor(iterator);
}
}