Example usage for org.springframework.batch.item.database JdbcBatchItemWriter afterPropertiesSet

List of usage examples for org.springframework.batch.item.database JdbcBatchItemWriter afterPropertiesSet

Introduction

In this page you can find the example usage for org.springframework.batch.item.database JdbcBatchItemWriter afterPropertiesSet.

Prototype

@Override
public void afterPropertiesSet() 

Source Link

Document

Check mandatory properties - there must be a SimpleJdbcTemplate and an SQL statement plus a parameter source.

Usage

From source file:com.github.jrrdev.mantisbtsync.core.jobs.issues.IssuesWritersConfiguration.java

/**
 * Build the composite item writer that chains all writers related to issues upsert.
 *
 * @param bugsWriter/*from   w ww  .  j av  a  2s .c o m*/
 *          Writer for the data related to an issue
 * @param bugNotesWriter
 *          Writer for the data related to a note
 * @param bugCustomFieldsWriter
 *          Writer for the data related to a custom field value
 * @param bugHistoryWriter
 *          Writer for the date related to the history of an issue
 * @return the composite writer
 */
@Bean
@StepScope
public CompositeItemWriter<BugBean> compositeIssuesWriter(final JdbcBatchItemWriter<BugBean> bugsWriter,
        final BugNotesWriter bugNotesWriter, final BugCustomFieldsWriter bugCustomFieldsWriter,
        final BugHistoryWriter bugHistoryWriter) {

    bugsWriter.afterPropertiesSet();
    bugNotesWriter.afterPropertiesSet();
    bugCustomFieldsWriter.afterPropertiesSet();
    bugHistoryWriter.afterPropertiesSet();

    final CompositeItemWriter<BugBean> compositeWriter = new CompositeItemWriter<BugBean>();
    final List<ItemWriter<? super BugBean>> writerList = new ArrayList<ItemWriter<? super BugBean>>();
    writerList.add(bugsWriter);
    writerList.add(bugNotesWriter);
    writerList.add(bugCustomFieldsWriter);
    writerList.add(bugHistoryWriter);
    compositeWriter.setDelegates(writerList);

    return compositeWriter;
}

From source file:io.spring.batch.configuration.BatchConfiguration.java

@Bean
protected JdbcBatchItemWriter<Customer> writer(DataSource dataSource) {
    JdbcBatchItemWriter<Customer> writer = new JdbcBatchItemWriter<>();
    writer.setDataSource(dataSource);/* w  w w . j a v a  2s. c  o m*/
    writer.setSql("INSERT INTO CUSTOMER VALUES(:customerName, :qty)");
    writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<Customer>());
    writer.afterPropertiesSet();

    return writer;
}

From source file:io.spring.batch.configuration.JobConfiguration.java

@Bean
@StepScope//from   w  w w  . ja v a  2 s.  co m
public JdbcBatchItemWriter<Customer> customerItemWriter() {
    JdbcBatchItemWriter<Customer> itemWriter = new JdbcBatchItemWriter<>();

    itemWriter.setDataSource(this.dataSource);
    itemWriter.setSql("INSERT INTO NEW_CUSTOMER VALUES (:id, :firstName, :lastName, :birthdate)");
    itemWriter.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider());
    itemWriter.afterPropertiesSet();

    return itemWriter;
}

From source file:com.github.jrrdev.mantisbtsync.core.jobs.projects.ProjectsWritersConfiguration.java

/**
 * Build the composite writer upserting the data related to the users of a project.
 * Perform upsert in the mantis_user_table and mantis_project_user_list_table tables.
 *
 * @param dataSource/*  www .  ja  va 2s.  c o m*/
 *          The datasource
 * @return the writer upserting the data related to the users of a project
 */
@Bean
@StepScope
public CompositeItemWriter<AccountData> projectUsersWriter(final DataSource dataSource,
        @Value("#{jobExecutionContext['mantis.loop.project_id']}") final BigInteger projectId) {

    final JdbcBatchItemWriter<AccountData> writer1 = new JdbcBatchItemWriter<AccountData>();
    writer1.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<AccountData>());
    writer1.setSql("INSERT INTO mantis_user_table (id, name)\n" + " VALUES (:id, :name)\n"
            + " ON DUPLICATE KEY UPDATE name = :name");
    writer1.setDataSource(dataSource);
    writer1.afterPropertiesSet();

    final JdbcBatchItemWriter<AccountData> writer2 = new JdbcBatchItemWriter<AccountData>();
    writer2.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<AccountData>());
    writer2.setSql("INSERT INTO mantis_project_user_list_table (user_id, project_id)\n" + " VALUES (:id, "
            + projectId + ")\n" + " ON DUPLICATE KEY UPDATE project_id = project_id");
    writer2.setDataSource(dataSource);
    writer2.setAssertUpdates(false);
    writer2.afterPropertiesSet();

    final CompositeItemWriter<AccountData> compositeWriter = new CompositeItemWriter<AccountData>();
    final List<ItemWriter<? super AccountData>> writerList = new ArrayList<ItemWriter<? super AccountData>>();
    writerList.add(writer1);
    writerList.add(writer2);
    compositeWriter.setDelegates(writerList);

    return compositeWriter;
}

From source file:com.github.jrrdev.mantisbtsync.core.jobs.projects.ProjectsWritersConfiguration.java

/**
 * Build the composite writer upserting the data related to the custom fields of a project.
 * Perform upsert in the mantis_custom_field_table and mantis_custom_field_project_table tables.
 *
 * @param dataSource/*from  ww  w  .j a v a2  s . co m*/
 *          The datasource
 * @return the writer upserting the data related to the custom fields of a project
 */
@Bean
@StepScope
public CompositeItemWriter<ProjectCustomFieldBean> projectCustomFieldsWriter(final DataSource dataSource) {

    final JdbcBatchItemWriter<ProjectCustomFieldBean> writer1 = new JdbcBatchItemWriter<ProjectCustomFieldBean>();
    writer1.setItemSqlParameterSourceProvider(
            new BeanPropertyItemSqlParameterSourceProvider<ProjectCustomFieldBean>());
    writer1.setSql("INSERT INTO mantis_custom_field_table\n"
            + " (id, name, type_id, possible_values, default_value, valid_regexp)\n"
            + " VALUES (:id, :name, :typeId, :possibleValues, :defaultValue, :validRegexp)\n"
            + " ON DUPLICATE KEY UPDATE name = :name, type_id = :typeId, possible_values = :possibleValues,\n"
            + " default_value = :defaultValue, valid_regexp = :validRegexp");
    writer1.setDataSource(dataSource);
    writer1.afterPropertiesSet();

    final JdbcBatchItemWriter<ProjectCustomFieldBean> writer2 = new JdbcBatchItemWriter<ProjectCustomFieldBean>();
    writer2.setItemSqlParameterSourceProvider(
            new BeanPropertyItemSqlParameterSourceProvider<ProjectCustomFieldBean>());
    writer2.setSql("INSERT INTO mantis_custom_field_project_table (field_id, project_id)\n"
            + " VALUES (:id, :projectId)\n" + " ON DUPLICATE KEY UPDATE project_id = project_id");
    writer2.setDataSource(dataSource);
    writer2.setAssertUpdates(false);
    writer2.afterPropertiesSet();

    final CompositeItemWriter<ProjectCustomFieldBean> compositeWriter = new CompositeItemWriter<ProjectCustomFieldBean>();
    final List<ItemWriter<? super ProjectCustomFieldBean>> writerList = new ArrayList<ItemWriter<? super ProjectCustomFieldBean>>();
    writerList.add(writer1);
    writerList.add(writer2);
    compositeWriter.setDelegates(writerList);

    return compositeWriter;
}