Example usage for org.springframework.batch.item.support CompositeItemWriter CompositeItemWriter

List of usage examples for org.springframework.batch.item.support CompositeItemWriter CompositeItemWriter

Introduction

In this page you can find the example usage for org.springframework.batch.item.support CompositeItemWriter CompositeItemWriter.

Prototype

CompositeItemWriter

Source Link

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// w ww  .j av a  2 s.  co 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:com.create.application.configuration.BatchConfiguration.java

@Bean
public ItemWriter<Ticket> ticketWriter(final TicketRepository repository, final JmsTemplate jmsTemplate) {
    final CompositeItemWriter<Ticket> writer = new CompositeItemWriter<>();
    final RepositoryItemWriter<Ticket> repositoryItemWriter = new RepositoryItemWriter<>();
    repositoryItemWriter.setRepository(repository);
    repositoryItemWriter.setMethodName("saveAndFlush");
    final JmsItemWriter<Ticket> jmsItemWriter = new JmsItemWriter();
    jmsItemWriter.setJmsTemplate(jmsTemplate);
    final List<ItemWriter<? super Ticket>> delegates = Stream.of(repositoryItemWriter, jmsItemWriter)
            .collect(Collectors.toList());
    writer.setDelegates(delegates);/*from  ww  w  . j a  v a 2s. co m*/
    return writer;
}

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/*w w  w .  j a  v a 2  s.c o 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;
}

From source file:uk.ac.kcl.batch.JobConfiguration.java

@Bean
@Qualifier("compositeItemWriter")
public ItemWriter<Document> compositeESandJdbcItemWriter() {
    CompositeItemWriter writer = new CompositeItemWriter<>();
    ArrayList<ItemWriter<Document>> delegates = new ArrayList<>();
    if (esItemWriter != null)
        delegates.add(esItemWriter);/*from   ww  w  .  j a  v a2  s  .c o m*/
    if (esRestItemWriter != null)
        delegates.add(esRestItemWriter);
    if (jdbcItemWriter != null)
        delegates.add(jdbcItemWriter);
    if (jdbcMapItemWriter != null)
        delegates.add(jdbcMapItemWriter);
    if (jsonFileItemWriter != null)
        delegates.add(jsonFileItemWriter);
    writer.setDelegates(delegates);
    return writer;
}

From source file:org.cbio.portal.pipelines.foundation.BatchConfiguration.java

@Bean
@StepScope/*  w  ww.ja v a 2  s  .co  m*/
public CompositeItemWriter<CompositeResultBean> compositeWriter() {
    CompositeItemWriter writer = new CompositeItemWriter();
    List delegates = new ArrayList();
    delegates.add(clinicalWriter());
    delegates.add(mutationWriter());
    delegates.add(fusionWriter());

    writer.setDelegates(delegates);
    return writer;
}

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/*from  w  ww . jav  a  2  s. 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;
}