Tasklet

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

    <!--
        * Batch job : Batch Tasklet sample
        * Batch step
            - JSmpTasklet100 : Generate data for the sample employee information TMP table
     -->
    <job id="JSmpTasklet" xmlns="http://www.bankwareglobal.com/schema/batchex">
        <step id="JSmpTasklet100" parent="parentStep" >
           <tasklet ref="MSmpTaskletBtch"/>
        </step>
    </job>
</beans>
  • Batch source code Sample

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

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

    private DSmpEmpTmp001 dSmpEmpTmp100;
    private DSmpEmpTst001 dSmpEmpTst100;

    /**
     * Tasklet
     * - A pattern used in batch jobs that perform simple DB CRUD operations or must be committed/rolled back at once.
     */
    @Override
    @BxmCategory(logicalName = "Tasklet sample(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);
        }

        /**
         * For Tasklet, this is how to get the ExecutionContext of the batch JOB
         * to share data between Steps.
         */
        ExecutionContext executionContext = chunkContext.getStepContext().getStepExecution().getJobExecution()
                .getExecutionContext();
        executionContext.putString("taskletName", "MSmpTaskletBtch"); // Set the value to be shared

        /**
         * Get batch input arguments
         */
        String oDate = DefaultBatchApplicationContext.getJobParameter("oDate");
        if (StringUtils.isEmpty(oDate)) {
            throw new DefaultApplicationException("CMFWE0001", new Object[] { "Batch execution date(oDate)" });
        }

        /**
         * Execute Tasklet business logic
         * - This sample calls DBIO that inserts data from SMP_EMP_TST to SMP_EMP_TMP.
         */
        // Initialize the sample employee information TMP table
        dSmpEmpTmp100.delete01();

        // Generate data for the sample employee information TMP table
        int insertCount = dSmpEmpTmp100.insert01();
        logger.debug("Insert Count : {}", insertCount);

        /**
         * Finish Tasklet processing
         * - Depending on the return value, the Tasklet can be completed or repeatedly processed.
         * - RepeatStatus.FINISHED : Tasklet completed (normal termination)
         * - RepeatStatus.CONTINUABLE : Execute the Tasklet execute method again.
         * - To raise an error, throw an ApplicationException.
         */
        return RepeatStatus.FINISHED;
    }
}
SWLab Bankware Global
  • 전체
  • BXM
  • BXCM
  • BXCP
  • BXI
제품 선택 시 더 정확한 매뉴얼 가이드를 제공해드립니다.

Copyright© Bankwareglobal All Rights Reserved.