Announcement Announcement Module
Collapse
No announcement yet.
Late binding use in JdbcCursorItemReader Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Late binding use in JdbcCursorItemReader

    Hi, i would like JdbcCursorItemReader's sql parameter to use late-binding, but my test is not working this is my xml file:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans
    <bean
    class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="location" value="ensemble-ivr.properties" />
    </bean>

    <bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource" ref="ensemble-cdlintdev-datasource" />
    </bean>

    <bean id="ensemble-cdlintdev-datasource" destroy-method="close"
    class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="oracle.jdbc.driver.OracleDriver"></property>
    <property name="jdbcUrl" value="jdbc:oracle:thin:@${ensemble.jdbcUrl}" />
    <property name="user" value="${ensemble.username}" />
    <property name="password" value="${ensemble.password}" />
    </bean>
    <bean id="jobRepository"
    class="org.springframework.batch.core.repository.s upport.MapJobRepositoryFactoryBean">
    <property name="transactionManager" ref="transactionManager" />
    </bean>
    <bean id="jobLauncher"
    class="org.springframework.batch.core.launch.suppo rt.SimpleJobLauncher">
    <property name="jobRepository" ref="jobRepository" />
    </bean>

    <context:component-scan base-package="com.codetel.ensemble.interfaces" />

    <!-- <bean id="logInterceptor" class="com.codetel.alarm.util.LoggingInterceptor"
    /> -->

    <batch:job id="simpleJob">
    <batch:step id="step1">
    <batch:tasklet>
    <batch:chunk reader="cursorReader" writer="flatFileWriter"
    commit-interval="1000" />
    </batch:tasklet>
    </batch:step>
    </batch:job>

    <bean id="cursorReader" scope="step"
    class="org.springframework.batch.item.database.Jdb cCursorItemReader">
    <property name="dataSource" ref="ensemble-cdlintdev-datasource" />
    <property name="sql" value="#{jobParameters['sqlQuery']}" />
    <property name="rowMapper" ref="bancatelCustomerMapper" />
    </bean>

    <bean id="flatFileWriter" class="org.springframework.batch.item.file.FlatFil eItemWriter"
    scope="step">
    <property name="resource" value="file:#jobParameters['filename']" />
    <property name="lineAggregator">
    <bean
    class="org.springframework.batch.item.file.transfo rm.DelimitedLineAggregator">
    <property name="delimiter" value="," />
    <property name="fieldExtractor">
    <bean
    class="org.springframework.batch.item.file.transfo rm.BeanWrapperFieldExtractor">
    <property name="names" value="msd,name,balance,type,subscriberStatus" />
    </bean>
    </property>
    </bean>
    </property>
    </bean>
    </beans>


    And this is my test class:

    @ContextConfiguration(locations = "classpath:ensemble-ivr-context.xml")
    @TestExecutionListeners({ DependencyInjectionTestExecutionListener.class,
    StepScopeTestExecutionListener.class })
    @RunWith(SpringJUnit4ClassRunner.class)
    public class ExampleJob {

    private String sqlQueryNameParam = "sqlQuery";

    @Autowired
    private ItemReader<BancatelCustomer> reader;

    @After
    public void tearDown() {
    ((ItemStream) reader).close();
    }

    public StepExecution getStepExecution() {
    StringBuilder strb = new StringBuilder();

    strb.append(" select ba.ban as ban,S.SUBSCRIBER_NO as sub, \n");
    strb.append(" to_char(case when s.SUB_MASTER_SERVICE_DATE is null then \n");
    strb.append(" to_date(to_char(s.INIT_ACTIVATION_DATE,'DDMMYYYY') ,'DDMMYYYY') \n");
    strb.append(" else to_date(to_char(s.SUB_MASTER_SERVICE_DATE,'DDMMYYY Y'),'DDMMYYYY') end,'DDMMYYYY') as msd, \n");
    strb.append(" rpad(case when replace (n.FIRST_NAME,chr(9),'') is null then trim(replace(n.LAST_BUSINESS_NAME,chr(9),'')) \n");
    strb.append(" else trim(replace (n.FIRST_NAME,chr(9),''))||' '||trim(n.middle_initial) \n");
    strb.append(" ||' '||trim(replace(n.LAST_BUSINESS_NAME,chr(9),''))|| ' '||trim(replace(n.second_last_name,chr(9),'')) end,31,' ') as Nombre, \n");
    strb.append(" replace(to_char(nvl(ba.AR_BALANCE,0),'S00000000000 0.99'),'.','') as balance, \n");
    strb.append(" ba.ACCOUNT_TYPE||ba.ACCOUNT_SUB_TYPE as tipo, \n");
    strb.append(" s.sub_status as estatus, \n");
    strb.append(" ba.ban_status as stban, \n");
    strb.append(" ba.BL_LAST_RG_BL_SEQ_NO as secu, decode(ba.payment_indicator, null,'Y',payment_indicator) as ind_pago \n");
    strb.append(" , s.PRODUCT_TYPE as prod_type \n");
    strb.append(" , c.market_seg_code as market_seg_code \n");
    strb.append(" from address_name_link anl, name_data n , \n");
    strb.append(" customer c, \n");
    strb.append(" billing_account ba, subscriber s \n");
    strb.append(" where s.customer_id = ba.ban \n");
    strb.append(" and ba.ban = anl.customer_id \n");
    strb.append(" and anl.name_id = n.name_id \n");
    strb.append(" and ba.ban = c.customer_id \n");
    strb.append(" and anl.link_type = 'B' \n");
    strb.append(" and (anl.EXPIRATION_DATE is null or trunc(anl.EXPIRATION_DATE) > trunc(sysdate) ) \n");
    strb.append(" and ba.BL_LAST_RG_BL_SEQ_NO is not null \n");
    strb.append(" and ba.bl_bill_prod_ind = 'Y' \n");
    strb.append(" and (ba.SYS_UPDATE_DATE >= (sysdate-3)) \n");
    strb.append(" and (sub_status in ('A','S') or (sub_status = 'C' and sub_status_rsn_code <> 'MIGR' and s.SUB_STATUS_DATE >= trunc(sysdate-3) )) \n");

    strb.append(" and not exists ( \n");
    strb.append(" select 1 from tn_dup tn \n");
    strb.append(" where tn.BAN = ba.BAN \n");
    strb.append(" and tn.SUBSCRIBER = s.subscriber_no \n");
    strb.append(" and tn.PRODUCT_TYPE = s.product_type \n");
    strb.append(" and tn.STATUS_TEL = s.sub_status ) \n");
    strb.append(" UNION all \n");

    strb.append(" SELECT \n");
    strb.append(" tn.ban, \n");
    strb.append(" tn.subscriber as sub, \n");
    strb.append(" to_char(case when s.SUB_MASTER_SERVICE_DATE is null then \n");
    strb.append(" to_date(to_char(s.INIT_ACTIVATION_DATE,'DDMMYYYY') ,'DDMMYYYY') \n");
    strb.append(" else to_date(to_char(s.SUB_MASTER_SERVICE_DATE,'DDMMYYY Y'),'DDMMYYYY') end,'DDMMYYYY') as msd, \n");
    strb.append(" rpad(case when replace (n.FIRST_NAME,chr(9),'') is null then trim(replace(n.LAST_BUSINESS_NAME,chr(9),'')) \n");
    strb.append(" else trim(replace (n.FIRST_NAME,chr(9),''))||' '||trim(n.middle_initial) \n");
    strb.append(" ||' '||trim(replace(n.LAST_BUSINESS_NAME,chr(9),''))|| ' '||trim(replace(n.second_last_name,chr(9),'')) end,31,' ') as Nombre, \n");
    strb.append(" replace(to_char(nvl(ba.AR_BALANCE,0),'S00000000000 0.99'),'.','') as balance, \n");
    strb.append(" ba.ACCOUNT_TYPE||ba.ACCOUNT_SUB_TYPE as tipo, \n");
    strb.append(" s.sub_status as estatus, \n");
    strb.append(" ba.ban_status as stban, \n");
    strb.append(" ba.BL_LAST_RG_BL_SEQ_NO as secu, decode(ba.payment_indicator, null,'Y',payment_indicator) as ind_pago \n");
    strb.append(" , tn.PRODUCT_TYPE as prod_type \n");
    strb.append(" , c.market_seg_code as market_seg_code \n");
    strb.append(" FROM \n");
    strb.append(" tn_dup tn, \n");
    strb.append(" address_name_link anl, name_data n, subscriber s, \n");
    strb.append(" customer c, \n");
    strb.append(" billing_account ba \n");
    strb.append(" where \n");
    strb.append(" tn.BAN = ba.BAN \n");
    strb.append(" and s.customer_id = ba.ban \n");
    strb.append(" and ba.ban = c.customer_id \n");
    strb.append(" and ba.ban = anl.customer_id \n");
    strb.append(" and anl.name_id = n.name_id \n");
    strb.append(" and anl.link_type = 'B' \n");
    strb.append(" and anl.EXPIRATION_DATE is null \n");
    strb.append(" and ba.bl_bill_prod_ind = 'Y' \n");
    strb.append(" and ba.BL_LAST_RG_BL_SEQ_NO is not null \n");
    strb.append(" and tn.PAGAR_X_IVR=1 \n");
    strb.append(" and tn.SUBSCRIBER = s.subscriber_no \n");
    strb.append(" and tn.PRODUCT_TYPE = s.product_type \n");
    strb.append(" and tn.STATUS_TEL = s.sub_status \n");
    strb.append(" and (sub_status in ('A','S') or (sub_status = 'C' and sub_status_rsn_code <> 'MIGR' and s.SUB_STATUS_DATE >= trunc(sysdate-3) )) \n");
    JobParameters jobParameters = new JobParametersBuilder()
    //
    .addString(sqlQueryNameParam, strb.toString())
    .toJobParameters();
    StepExecution execution = MetaDataInstanceFactory
    .createStepExecution(jobParameters);
    return execution;
    }

    @Test
    @DirtiesContext
    public void testJob() throws Exception {
    final StepExecution stepExecution = getStepExecution();
    StepScopeTestUtils.doInStepScope(stepExecution,
    new Callable<Integer>() {

    public Integer call() throws Exception {
    int count = 0;
    ((ItemStream) reader).open(stepExecution
    .getExecutionContext());

    while (reader.read() != null) {
    count++;
    }

    ((ItemStream) reader).close();
    return count;
    }

    });
    }
    }

  • #2
    Found out the problem.

    The maven spring-batch-core 2.1.8 dependency was using some old Spring AOP and Context jars that aparently, i removed it and left the spring-batch-test one, now it is working perfectly .

    Comment

    Working...
    X