DB TO File(Fixed)
-
배치 작업 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>
<!--
* 배치작업 : DB TO FILE(FIXED) 샘플
* 배치스텝
- JSmpDBToFixed100 : DB TO FILE(FIXED) 샘플 초기화 처리
- JSmpDBToFixed200 : 입력받은 "deptNo" 에 해당하는 샘플용직원정보를 조회하여 File Write 처리한다.
-->
<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>
<!--
* 샘플용직원정보 Fixed File Write 처리 bean 설정
-->
<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>
-
배치 소스코드 Sample
@BxmBean("MSmpDBToFixedBtch")
@Scope("step")
@BxmCategory(logicalName = "DB TO FILE(FIXED) 샘플")
public class MSmpDBToFixedBtch implements ItemStream, ItemReader<MSmpDBToFixedBtch01Dto>,
ItemProcessor<MSmpDBToFixedBtch01Dto, MSmpDBToFixedBtch01Dto> {
final Logger logger = LoggerFactory.getLogger(this.getClass());
private DSmpEmpTst001 dSmpEmpTst001; // 샘플용직원정보TST
private Iterator<DSmpEmpTst001selectList01OutDto> iterator;
/**
* open
* - 초기화를 위해 구현해야 하는 메소드로서 스텝이 시작되기 전에 프레임워크에서 최초 1번 호출된다.
*/
@Override
@BxmCategory(logicalName = "open : 샘플용 직원정보 Iterator 처리")
public void open(ExecutionContext executionContext) throws ItemStreamException {
if (dSmpEmpTst001 == null) {
dSmpEmpTst001 = DefaultApplicationContext.getBean(DSmpEmpTst001.class);
}
/**
* 배치 입력파라미터 "deptNo" Get
*/
String feduDeptNo = DefaultBatchApplicationContext.getJobParameter("deptNo");
if (StringUtils.isEmpty(feduDeptNo)) {
throw new ItemStreamException("배치 입력아규먼트 'deptNo' 값이 존재하지 않습니다.");
}
/**
* 입력받은 "deptNo" 에 대하여 샘플용 직원정보를 Iterator로 가져온다.
*/
DSmpEmpTst001selectList01InDto inDto = new DSmpEmpTst001selectList01InDto();
inDto.setFeduDeptNo(Integer.parseInt(feduDeptNo));
iterator = dSmpEmpTst001.selectList01(inDto).iterator();
}
/**
* read
* - 처리 대상 데이터를 건 별로 DB 또는 파일에서 읽어오는 역할을 수행한다.
*/
@Override
@BxmCategory(logicalName = "read : 샘플용 직원정보 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샘플 임직원번호]
out.setFeduEmpNm(input.getFeduEmpNm()); // set [FW샘플 임직원명]
out.setFeduOccpNm(input.getFeduOccpNm()); // set [FW샘플 직업명]
out.setFeduMngrEmpNo(input.getFeduMngrEmpNo()); // set [FW샘플 관리자임직원번호]
out.setFeduHireDt(input.getFeduHireDt()); // set [FW샘플 입사일자]
out.setFeduPayAmt(input.getFeduPayAmt()); // set [FW샘플 급여금액]
out.setFeduDeptNo(input.getFeduDeptNo()); // set [FW샘플 부서번호]
}
return out;
}
/**
* process
* - 처리 대상 데이터를 건 별로 업무요건에 따라 처리하는 역할을 수행한다.
*/
@Override
@BxmCategory(logicalName = "process : 샘플용 직원정보 처리")
public MSmpDBToFixedBtch01Dto process(MSmpDBToFixedBtch01Dto in) throws Exception {
MSmpDBToFixedBtch01Dto out;
/**
* 관리자임직원번호가 없는 경우에는 null 를 return 하여 해당 Item에 대하여 Skip 처리한다.
* - 참고 : process에서 null을 return 하면 write로 item이 넘어가지 않는다.
*/
if (in.getFeduMngrEmpNo() == 0) {
logger.warn("임직원번호[{}]에 대한 관리자 번호가 0 입니다. Skip 처리합니다.");
return null;
}
/**
* 개별 업무로직 수행
* ...
* ...
*/
out = in;
return out;
}
/**
* update
* - 진행 상태를 기록하기 위해 구현해야 하는 Method로서 구간 별로 Commit 시에 프레임워크에서 호출된다.
*/
@Override
@BxmCategory(logicalName = "update")
public void update(ExecutionContext executionContext) throws ItemStreamException {
}
/**
* close
* - 리소스 정리 작업을 위해 구현해야 하는 Method로서 Step 완료 시에 프레임워크에서 호출된다.
*/
@Override
@BxmCategory(logicalName = "close")
public void close() throws ItemStreamException {
if (iterator != null)
DasUtils.disconnectDasExecutor(iterator);
}
}