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

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

Introduction

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

Prototype

JdbcBatchItemWriter

Source Link

Usage

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

/**
 * Default constructor./*from   ww w.j  a  v a 2s.  c om*/
 */
public BugCustomFieldsWriter() {
    writer = new JdbcBatchItemWriter<BugCustomFieldValue>();
    writer.setItemSqlParameterSourceProvider(
            new BeanPropertyItemSqlParameterSourceProvider<BugCustomFieldValue>());
    writer.setSql(SQL_QUERY);
    writer.setAssertUpdates(false);
}

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

/**
 * Default constructor./*from   w ww.  ja va2 s . co m*/
 */
public BugNotesWriter() {
    writer = new JdbcBatchItemWriter<BugNoteBean>();
    writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<BugNoteBean>());
    writer.setSql(SQL_QUERY);
    writer.setAssertUpdates(false);
}

From source file:com.apress.prospringintegration.batch.JobConfiguration.java

@Bean
public JdbcBatchItemWriter dataWriter() {
    JdbcBatchItemWriter jdbcBatchItemWriter = new JdbcBatchItemWriter();
    jdbcBatchItemWriter.setAssertUpdates(true);
    jdbcBatchItemWriter.setDataSource(dataSource);
    jdbcBatchItemWriter.setSql("insert into USER_REGISTRATION(FIRST_NAME, LAST_NAME, COMPANY,"
            + "ADDRESS, CITY, STATE, ZIP, COUNTY, URL, PHONE_NUMBER, FAX )"
            + "values (:firstName, :lastName, :company, :address, :city ,"
            + ":state, :zip, :county, :url, :phoneNumber, :fax )");

    jdbcBatchItemWriter.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider());

    return jdbcBatchItemWriter;
}

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

/**
 * Default constructor./*  w w w. ja v  a 2  s .co m*/
 */
public BugHistoryWriter() {
    writer = new JdbcBatchItemWriter<BugHistoryBean>();
    writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<BugHistoryBean>());
    writer.setSql(SQL_QUERY);
    writer.setAssertUpdates(false);
}

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

/**
 * Build the writer upserting the data related to the categories of a project.
 * Perform upsert in the mantis_category_table table.
 *
 * @param dataSource//from   ww w  .  j a  v  a 2  s  . c  o m
 *          The datasource
 * @return the writer upserting the data related to the categories of a project
 */
@Bean
@StepScope
public JdbcBatchItemWriter<ProjectCategoryBean> projectCategoriesWriter(final DataSource dataSource) {

    final JdbcBatchItemWriter<ProjectCategoryBean> writer = new JdbcBatchItemWriter<ProjectCategoryBean>();
    writer.setItemSqlParameterSourceProvider(
            new BeanPropertyItemSqlParameterSourceProvider<ProjectCategoryBean>());
    writer.setSql(
            "INSERT INTO mantis_category_table (name, project_id)\n" + " SELECT :name, :projectId FROM dual\n"
                    + " WHERE NOT EXISTS (SELECT 1 FROM mantis_category_table dest\n"
                    + "         WHERE dest.name = :name AND dest.project_id = :projectId)");
    writer.setDataSource(dataSource);
    writer.setAssertUpdates(false);
    return writer;
}

From source file:io.spring.marchmadness.MooreStatConfiguration.java

@Bean
public ItemWriter<MooreNcaaStat> writer(DataSource dataSource) {
    JdbcBatchItemWriter<MooreNcaaStat> writer = new JdbcBatchItemWriter<MooreNcaaStat>();
    writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<MooreNcaaStat>());
    writer.setSql("INSERT INTO MOORE_NCAA_STATS (YEAR, RANK, " + "NAME, " + "WIN, " + "LOSS, " + "TIE, "
            + "SOS, " + "PR ) VALUES (:year, :rank, :name, :win, :loss, :tie, :sos, :pr)");
    writer.setDataSource(dataSource);//from  w ww .  j  a va 2 s.  c om
    return writer;
}

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 a2 s .com*/
    writer.setSql("INSERT INTO CUSTOMER VALUES(:customerName, :qty)");
    writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<Customer>());
    writer.afterPropertiesSet();

    return writer;
}

From source file:io.spring.marchmadness.NcaaStatConfiguration.java

@Bean
public ItemWriter<NcaaStats> writer(DataSource dataSource) {
    JdbcBatchItemWriter<NcaaStats> writer = new JdbcBatchItemWriter<NcaaStats>();
    writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<NcaaStats>());
    writer.setSql("INSERT INTO NCAA_STATS (YEAR," + "RANK, " + "NAME, " + "RATING, " + "WIN, " + "LOSS, "
            + "SCHEDL, " + "SCHEDL_RANK, " + "WIN_TOP_25, " + "LOSS_TOP_25, " + "WIN_TOP_50, " + "LOSS_TOP_50, "
            + "PREDICTOR, " + "PREDICTOR_RANK, " + "GOLDEN_MEAN, " + "GOLDEN_MEAN_RANK, " + "RECENT,"
            + "RECENT_RANK) VALUES (:year, :rank, :name, :rating, :win, :loss, "
            + ":schedl, :schedlRank, :winTop25, :lossTop25, :winTop50, :lossTop50, "
            + ":predictor, :predictorRank, :goldenMean, :goldenMeanRank, :recent, " + ":recentRank)");
    writer.setDataSource(dataSource);/*w  w w  .java  2s  .c  om*/
    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//from   www. j ava2  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:com.github.jrrdev.mantisbtsync.core.jobs.issues.IssuesWritersConfiguration.java

/**
 * Build the writer upserting the data related to an issue.
 * Perform upsert in the mantis_bug_table table.
 *
 * @param dataSource/*from   w w w  .java 2 s . c o  m*/
 *          The datasource
 * @return the writer upserting the data related to an issue
 */
@Bean
@StepScope
public JdbcBatchItemWriter<BugBean> bugsWriter(final DataSource dataSource) {

    final JdbcBatchItemWriter<BugBean> writer = new JdbcBatchItemWriter<BugBean>();
    writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<BugBean>());
    writer.setSql("INSERT INTO mantis_bug_table (id, project_id, reporter_id, handler_id, priority_id,\n"
            + "    severity_id, status_id, resolution_id, description, steps_to_reproduce,\n"
            + "    additional_information, platform, version, fixed_in_version, target_version,\n"
            + "    summary, category, date_submitted, last_updated, last_sync)\n"
            + " VALUES (:id, :projectId, :reporterId, :handlerId, :priorityId,\n"
            + "    :severityId, :statusId, :resolutionId, :description, :stepsToReproduce,\n"
            + "    :additionalInformation, :platform, :version, :fixedInVersion, :targetVersion,\n"
            + "    :summary, :category, :dateSubmitted, :lastUpdated, sysdate())\n"
            + " ON DUPLICATE KEY UPDATE project_id = :projectId, reporter_id = :reporterId,\n"
            + "     handler_id = :handlerId, priority_id = :priorityId,\n"
            + "    severity_id = :severityId, status_id = :statusId, resolution_id = :resolutionId,\n"
            + "    description = :description, steps_to_reproduce = :stepsToReproduce,\n"
            + "    additional_information = :additionalInformation, platform = :platform,\n"
            + "    version = :version, fixed_in_version = :fixedInVersion, target_version = :targetVersion,\n"
            + "    summary = :summary, category = :category, date_submitted = :dateSubmitted,\n"
            + "    last_updated = :lastUpdated, last_sync = sysdate()");
    writer.setDataSource(dataSource);
    writer.setAssertUpdates(false);
    return writer;
}