Tasklet

  • 배치 작업 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="MSmpTaskletBtch*"/>
        </base-package>
    </job-component>

    <!--
        * 배치작업 : 배치 Tasklet 샘플
        * 배치스텝
            - JSmpTasklet100 : 샘플용직원정보TMP 테이블 데이터 생성
     -->
    <job id="JSmpTasklet" xmlns="http://www.bankwareglobal.com/schema/batchex">
        <step id="JSmpTasklet100" parent="parentStep" >
           <tasklet ref="MSmpTaskletBtch"/>
        </step>
    </job>
</beans>
  • 배치 소스코드 Sample

@BxmBean("MSmpTaskletBtch")
@Scope("step")
@BxmCategory(logicalName = "Tasklet 샘플")
public class MSmpTaskletBtch implements Tasklet {

    final Logger logger = LoggerFactory.getLogger(MSmpTaskletBtch.class);

    private DSmpEmpTmp001 dSmpEmpTmp100;
    private DSmpEmpTst001 dSmpEmpTst100;

    /**
     * Tasklet
     * - 단순 DB CRUD 수행이나 반드시 한번에 Commit/Rollback 되어야 하는 배치에서 사용하는 패턴.
     */
    @Override
    @BxmCategory(logicalName = "Tasklet 샘플(execute)")
    public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
        if (dSmpEmpTmp100 == null) {
            dSmpEmpTmp100 = DefaultApplicationContext.getBean(DSmpEmpTmp001.class);
        }
        if (dSmpEmpTst100 == null) {
            dSmpEmpTst100 = DefaultApplicationContext.getBean(DSmpEmpTst001.class);
        }

        /**
         * Tsklet의 경우 Step 간에 데이터 공유하기 위한 배치 JOB의 ExecutionContext를 가져오는 방법.
         */
        ExecutionContext executionContext = chunkContext.getStepContext().getStepExecution().getJobExecution()
                .getExecutionContext();
        executionContext.putString("taskletName", "MSmpTaskletBtch"); // 공유할 값 설정

        /**
         * 배치입력아규먼트 Get
         */
        String oDate = DefaultBatchApplicationContext.getJobParameter("oDate");
        if (StringUtils.isEmpty(oDate)) {
            throw new DefaultApplicationException("CMFWE0001", new Object[] { "배치실행일자(oDate)" });
        }

        /**
         * Tasklet 업무로직 수행
         * - 해당 Sample은 SMP_EMP_TST 에서 SMP_EMP_TMP로 데이터를 insert 하는 DBIO를 호출한다.
         */
        // 샘플용직원정보TMP 테이블 초기화
        dSmpEmpTmp100.delete01();

        // 샘플용직원정보TMP 테이블 데이터 생성
        int insertCount = dSmpEmpTmp100.insert01();
        logger.debug("Insert Count : {}", insertCount);

        /**
         * Tasklet을 종료처리
         * - Tasklet을 완료처리/ 혹은 반복 처리등을 Return 값에 따라 처리 할 수 있다.
         * - RepeatStatus.FINISHED : Tasklet 완료(정상종료)
         * - RepeatStatus.CONTINUABLE : Tasklet의 excute메소드 다시 수행.
         * - 만일 에러를 발생하고 싶다면 ApplicationException을 throw 하면 된다.
         */
        return RepeatStatus.FINISHED;
    }
}
SWLab Bankware Global
  • 전체
  • BXM
  • BXCM
  • BXCP
  • BXI
제품 선택 시 더 정확한 매뉴얼 가이드를 제공해드립니다.

Copyright© Bankwareglobal All Rights Reserved.