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

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

Introduction

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

Prototype

public void setAssertUpdates(boolean assertUpdates) 

Source Link

Document

Public setter for the flag that determines whether an assertion is made that all items cause at least one row to be updated.

Usage

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.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   www.  ja  v a2 s .  co 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/*w w  w . j  a va 2  s  . c om*/
 *          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.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 av a2 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: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 .ja  va  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;
}