List of usage examples for org.springframework.batch.item.database JdbcBatchItemWriter setItemSqlParameterSourceProvider
public void setItemSqlParameterSourceProvider( ItemSqlParameterSourceProvider<T> itemSqlParameterSourceProvider)
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);//w w w. ja v a 2 s .c o m 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);/*from w w w. j a v a 2 s . c o m*/ 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// w ww . jav a2s.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; }
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 ww w . j av a 2s.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 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 a v a 2 s .c om * 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:io.spring.batch.configuration.BatchConfiguration.java
@Bean protected JdbcBatchItemWriter<Customer> writer(DataSource dataSource) { JdbcBatchItemWriter<Customer> writer = new JdbcBatchItemWriter<>(); writer.setDataSource(dataSource);//from www .j a v a2 s. c o m writer.setSql("INSERT INTO CUSTOMER VALUES(:customerName, :qty)"); writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<Customer>()); writer.afterPropertiesSet(); 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 w w w . j a v a2s. 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.enums.EnumsWritersConfiguration.java
/** * Build the JdbcBatchItemWriter for the given enums table. * * @param tableName/* ww w .j av a 2 s . c o m*/ * Name of the destination table * @param dataSource * The datasource * @return */ private JdbcBatchItemWriter<ObjectRef> getEnumWriter(final String tableName, final DataSource dataSource) { final JdbcBatchItemWriter<ObjectRef> writer = new JdbcBatchItemWriter<ObjectRef>(); writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<ObjectRef>()); writer.setSql(getMergeStatement(tableName)); 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 www. ja v a2 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:de.codecentric.batch.jobs.FlatFileToDbSkipJobConfiguration.java
@Bean public JdbcBatchItemWriter<Item> jdbcBatchItemWriter() { JdbcBatchItemWriter<Item> itemWriter = new JdbcBatchItemWriter<Item>(); itemWriter.setSql("INSERT INTO ITEM (ID, DESCRIPTION) VALUES (:id,:description)"); itemWriter.setDataSource(dataSource); itemWriter.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<Item>()); return itemWriter; }