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

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

Introduction

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

Prototype

public void setDataSource(DataSource dataSource) 

Source Link

Document

Public setter for the data source for injection purposes.

Usage

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

@Bean
@StepScope//w  ww.ja  v  a 2 s  .  c o m
@Qualifier("simpleJdbcItemWriter")
@Profile("jdbc_out")
public ItemWriter<Document> simpleJdbcItemWriter(@Qualifier("targetDataSource") DataSource jdbcDocumentTarget) {
    JdbcBatchItemWriter<Document> writer = new JdbcBatchItemWriter<>();
    writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<>());
    writer.setSql(env.getProperty("target.Sql"));
    writer.setDataSource(jdbcDocumentTarget);
    return writer;
}

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 2s . 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:com.github.jrrdev.mantisbtsync.core.jobs.projects.ProjectsWritersConfiguration.java

/**
 * Build the writer upserting the data related to the versions of a project.
 * Perform upsert in the mantis_project_version_table table.
 *
 * @param dataSource/*from w w  w .j  av  a 2 s .  c o m*/
 *          The datasource
 * @return the writer upserting the data related to the versions of a project
 */
@Bean
@StepScope
public JdbcBatchItemWriter<ProjectVersionData> projectVersionsWriter(final DataSource dataSource) {

    final JdbcBatchItemWriter<ProjectVersionData> writer = new JdbcBatchItemWriter<ProjectVersionData>();
    writer.setItemSqlParameterSourceProvider(
            new BeanPropertyItemSqlParameterSourceProvider<ProjectVersionData>());
    writer.setSql("INSERT INTO mantis_project_version_table\n"
            + " (id, version, project_id, description, released, obsolete)"
            + " VALUES (:id, :name, :project_id, :description, :released, :obsolete)\n"
            + " ON DUPLICATE KEY UPDATE version = :name, project_id = :project_id,\n"
            + "   description = :description, released = :released, obsolete = :obsolete");
    writer.setDataSource(dataSource);
    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   w  w  w. j a  v  a  2s  .  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;
}

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);
    return writer;
}

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   ww w  . j ava 2s  . co 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;
}