MULTI FILE WRITE

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

    <!--
        * Batch job: MULTI FILE WRITE sample
        * Batch step
            - JSmpMultiFileWrite100 : MULTI FILE WRITE sample initialization process
            - JSmpMultiFileWrite200 : Directly open two files and perform File Write processing
     -->

    <job id="JSmpMultiFileWrite" xmlns="http://www.bankwareglobal.com/schema/batchex">
        <step id="JSmpMultiFileWrite100" next="JSmpMultiFileWrite200" parent="parentStep">
            <tasklet ref="MSmpMultiFileWriteInitBtch"/>
        </step>
        <step id="JSmpMultiFileWrite200" parent="parentStep">
            <tasklet>
                <chunk reader="MSmpMultiFileWriteBtch" processor="MSmpMultiFileWriteBtch" writer="MSmpMultiFileWriteBtch"/>
            </tasklet>
        </step>
    </job>
</beans>
  • Batch source code Sample

@BxmBean("MSmpMultiFileWriteBtch")
@Scope("step")
@BxmCategory(logicalName = "MULTI FILE WRITE sample")
public class MSmpMultiFileWriteBtch implements ItemStream, ItemReader<MSmpMultiFileWriteBtch01Dto>,
        ItemProcessor<MSmpMultiFileWriteBtch01Dto, MSmpMultiFileWriteBtch01Dto>,
        ItemWriter<MSmpMultiFileWriteBtch01Dto> {

    final Logger logger = LoggerFactory.getLogger(this.getClass());

    private DSmpEmpTst001 dSmpEmpTst100; // Sample employee information TST

    private Iterator<DSmpEmpTst001selectList01OutDto> iterator;

    private FixedFileWriter<MSmpMultiFileWriteBtch02Dto> empInfoFixedWriter;
    private DelimitedFileWriter<MSmpMultiFileWriteBtch03Dto> empInfoDelimitedWriter;

    /
     * open
     * - Method that must be implemented for initialization and is called once by FW before the step starts.
     */
    @Override
    @BxmCategory(logicalName = "open : Sample employee information File Open processing")
    public void open(ExecutionContext executionContext) throws ItemStreamException {
        if (dSmpEmpTst100 == null) {
            dSmpEmpTst100 = DefaultApplicationContext.getBean(DSmpEmpTst001.class);
        }

        /
         * Retrieve "oDate" from the batch input argument.
         */
        String oDate = DefaultBatchApplicationContext.getJobParameter("oDate");
        if (StringUtils.isEmpty(oDate)) {
            throw new ItemStreamException("The batch input argument 'oDate' does not exist.");
        }

        /
         * Retrieve "deptNo" from the batch input argument.
         */
        String feduDeptNo = DefaultBatchApplicationContext.getJobParameter("deptNo");
        if (StringUtils.isEmpty(feduDeptNo)) {
            throw new ItemStreamException("The batch input argument 'deptNo' does not exist.");
        }

        /
         * Sample employee information Fixed File Open
         */
        String empInfoFixedFileName = "/data1/prod/bxm400/dat/fixed_file_" + oDate + ".txt";
        empInfoFixedWriter = DefaultFileUtils.getFixedFileWriter(empInfoFixedFileName,
                MSmpMultiFileWriteBtch02Dto.class, "UTF-8");
        empInfoFixedWriter.open(executionContext); // File Open

        /
         * Sample employee information Delimited File Open
         */
        String empInfoDelimitedFileName = "/data1/prod/bxm400/dat/delimited_file_" + oDate + ".txt";
        empInfoDelimitedWriter = DefaultFileUtils.getDelimitedFileWriter(empInfoDelimitedFileName,
                MSmpMultiFileWriteBtch03Dto.class, ",", "UTF-8");
        empInfoDelimitedWriter.open(executionContext); // File Open

        /
         * For the input "deptNo", retrieve the sample employee information as an Iterator.
         */
        DSmpEmpTst001selectList01InDto inDto = new DSmpEmpTst001selectList01InDto();
        inDto.setFeduDeptNo(Integer.parseInt(feduDeptNo));
        iterator = dSmpEmpTst100.selectList01(inDto).iterator();
        if (iterator == null) {
            throw new ItemStreamException("connected result is not prepared.");
        }
    }

    /
     * read
     * - Performs the role of reading the target data to be processed from DB or file per record.
     */
    @Override
    @BxmCategory(logicalName = "read : Sample employee information Read")
    public MSmpMultiFileWriteBtch01Dto read()
            throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
        MSmpMultiFileWriteBtch01Dto out = null;
        if (iterator.hasNext()) {
            out = new MSmpMultiFileWriteBtch01Dto();
            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 the target data per record according to business requirements.
     */
    @Override
    @BxmCategory(logicalName = "process : Sample employee information processing")
    public MSmpMultiFileWriteBtch01Dto process(MSmpMultiFileWriteBtch01Dto in) throws Exception {
        MSmpMultiFileWriteBtch01Dto out;

        /
         *  If the manager employee number does not exist, return null and perform Skip processing for the relevant Item.
         *  - Note: If process returns null, the item is not passed to write.
         */
        if (in.getFeduMngrEmpNo() == 0) {
            logger.warn("The manager number for employee number[{}] is 0. Skip processing.");
            return null;
        }

        /
         * Execute individual business logic
         * ...
         * ...
         */
        out = in;

        return out;
    }

    /
     * write
     * - Performs the role of recording the target result data to DB or file per commit unit.
     */
    @Override
    @BxmCategory(logicalName = "write : Sample employee information processing")
    public void write(List<? extends MSmpMultiFileWriteBtch01Dto> in) throws Exception {
        List<MSmpMultiFileWriteBtch02Dto> mSmpMultiFileWriteBtch02Dtos = new ArrayList<MSmpMultiFileWriteBtch02Dto>();
        List<MSmpMultiFileWriteBtch03Dto> mSmpMultiFileWriteBtch03Dtos = new ArrayList<MSmpMultiFileWriteBtch03Dto>();

        for (MSmpMultiFileWriteBtch01Dto mSmpMultiFileWriteBtch01Dto : in) {
            /
             * Set data for Fixed File processing
             */
            MSmpMultiFileWriteBtch02Dto mSmpMultiFileWriteBtch02Dto = new MSmpMultiFileWriteBtch02Dto();

            mSmpMultiFileWriteBtch02Dto.setFeduEmpNo(mSmpMultiFileWriteBtch01Dto.getFeduEmpNo()); // set [FW sample employee number]
            mSmpMultiFileWriteBtch02Dto.setFeduEmpNm(mSmpMultiFileWriteBtch01Dto.getFeduEmpNm()); // set [FW sample employee name]
            mSmpMultiFileWriteBtch02Dto.setFeduOccpNm(mSmpMultiFileWriteBtch01Dto.getFeduOccpNm()); // set [FW sample occupation name]
            mSmpMultiFileWriteBtch02Dto.setFeduMngrEmpNo(mSmpMultiFileWriteBtch01Dto.getFeduMngrEmpNo()); // set [FW sample manager employee number]
            mSmpMultiFileWriteBtch02Dto.setFeduHireDt(mSmpMultiFileWriteBtch01Dto.getFeduHireDt()); // set [FW sample hire date]
            mSmpMultiFileWriteBtch02Dto.setFeduPayAmt(mSmpMultiFileWriteBtch01Dto.getFeduPayAmt()); // set [FW sample salary amount]
            mSmpMultiFileWriteBtch02Dto.setFeduDeptNo(mSmpMultiFileWriteBtch01Dto.getFeduDeptNo()); // set [FW sample department number]

            mSmpMultiFileWriteBtch02Dtos.add(mSmpMultiFileWriteBtch02Dto);

            /
             * Set data for Delimited File processing
             */
            MSmpMultiFileWriteBtch03Dto mSmpMultiFileWriteBtch03Dto = new MSmpMultiFileWriteBtch03Dto();

            mSmpMultiFileWriteBtch03Dto.setFeduEmpNo(mSmpMultiFileWriteBtch01Dto.getFeduEmpNo()); // set [FW sample employee number]
            mSmpMultiFileWriteBtch03Dto.setFeduEmpNm(mSmpMultiFileWriteBtch01Dto.getFeduEmpNm()); // set [FW sample employee name]
            mSmpMultiFileWriteBtch03Dto.setFeduOccpNm(mSmpMultiFileWriteBtch01Dto.getFeduOccpNm()); // set [FW sample occupation name]
            mSmpMultiFileWriteBtch03Dto.setFeduMngrEmpNo(mSmpMultiFileWriteBtch01Dto.getFeduMngrEmpNo()); // set [FW sample manager employee number]
            mSmpMultiFileWriteBtch03Dto.setFeduHireDt(mSmpMultiFileWriteBtch01Dto.getFeduHireDt()); // set [FW sample hire date]
            mSmpMultiFileWriteBtch03Dto.setFeduPayAmt(mSmpMultiFileWriteBtch01Dto.getFeduPayAmt()); // set [FW sample salary amount]
            mSmpMultiFileWriteBtch03Dto.setFeduDeptNo(mSmpMultiFileWriteBtch01Dto.getFeduDeptNo()); // set [FW sample department number]

            mSmpMultiFileWriteBtch03Dtos.add(mSmpMultiFileWriteBtch03Dto);
        }

        /
         * File Write processing
         */
        empInfoFixedWriter.write(mSmpMultiFileWriteBtch02Dtos); // Fixed File Write
        empInfoDelimitedWriter.write(mSmpMultiFileWriteBtch03Dtos); // Delimited File Write
    }

    /
     * update
     * - Method that must be implemented to record the progress status and is called by FW at each section commit.
     */
    @Override
    @BxmCategory(logicalName = "update")
    public void update(ExecutionContext executionContext) throws ItemStreamException {
        if (empInfoFixedWriter != null)
            empInfoFixedWriter.update(executionContext);
        if (empInfoDelimitedWriter != null)
            empInfoDelimitedWriter.update(executionContext);
    }

    /
     * close
     * - Method that must be implemented for resource cleanup and is called by FW when the Step is completed.
     */
    @Override
    @BxmCategory(logicalName = "close")
    public void close() throws ItemStreamException {
        if (empInfoFixedWriter != null)
            empInfoFixedWriter.close();
        if (empInfoDelimitedWriter != null)
            empInfoDelimitedWriter.close();
    }
}
SWLab Bankware Global
  • 전체
  • BXM
  • BXCM
  • BXCP
  • BXI
제품 선택 시 더 정확한 매뉴얼 가이드를 제공해드립니다.

Copyright© Bankwareglobal All Rights Reserved.