Java Code Examples for org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider

The following examples show how to use org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: SpringAll   Source File: DatabaseItemWriterDemo.java    License: MIT License 6 votes vote down vote up
private ItemWriter<TestData> dataSourceItemWriter() {
    // ItemWriter的实现类之一,mysql数据库数据写入使用JdbcBatchItemWriter,
    // 其他实现:MongoItemWriter,Neo4jItemWriter等
    JdbcBatchItemWriter<TestData> writer = new JdbcBatchItemWriter<>();
    writer.setDataSource(dataSource); // 设置数据源

    String sql = "insert into TEST(id,field1,field2,field3) values (:id,:field1,:field2,:field3)";
    writer.setSql(sql); // 设置插入sql脚本

    // 映射TestData对象属性到占位符中的属性
    BeanPropertyItemSqlParameterSourceProvider<TestData> provider = new BeanPropertyItemSqlParameterSourceProvider<>();
    writer.setItemSqlParameterSourceProvider(provider);

    writer.afterPropertiesSet(); // 设置一些额外属性
    return writer;
}
 
Example 2
@Bean
public JdbcBatchItemWriter<Voltage> writer(final DataSource dataSource) {
    return new JdbcBatchItemWriterBuilder<Voltage>()
            .itemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<>())
            .sql("INSERT INTO voltage (volt, time) VALUES (:volt, :time)")
            .dataSource(dataSource)
            .build();
}
 
Example 3
Source Project: spring-cloud   Source File: PeopleWriter.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@Qualifier("jdbcBatchItemWriter")
public JdbcBatchItemWriter<People> jdbcBatchItemWriter() {
    JdbcBatchItemWriter<People> writer = new JdbcBatchItemWriter<>();
    writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<>());
    writer.setSql("insert into people (person_id, first_name, last_name) VALUES (uuid(), :firstName, :lastName)");
    writer.setDataSource(w_dataSource);
    return writer;
}
 
Example 4
@Bean(name = DATA_WRITER)
public JdbcBatchItemWriter<JavaChampion> writer(DataSource dataSource) throws Exception {
    JdbcBatchItemWriter<JavaChampion> jdbcBatchItemWriter = new JdbcBatchItemWriter<JavaChampion>();
    jdbcBatchItemWriter.setAssertUpdates(true);
    jdbcBatchItemWriter.setDataSource(dataSource);
    jdbcBatchItemWriter.setSql(
            " INSERT INTO java_champion( first_name, last_name, country, year )" +
                    " VALUES ( :firstName , :lastName, :country, :year ) ");
    jdbcBatchItemWriter.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<>());
    return jdbcBatchItemWriter;
}
 
Example 5
@Bean
public JdbcBatchItemWriter<PayrollTo> writer(DataSource dataSource) {
    return new JdbcBatchItemWriterBuilder<PayrollTo>()
            .itemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<>())
            .sql("INSERT INTO PAYROLL (PERSON_IDENTIFICATION, CURRENCY, TX_AMMOUNT, ACCOUNT_TYPE, ACCOUNT_ID, TX_DESCRIPTION, FIRST_LAST_NAME) VALUES (:identification,:currency,:ammount,:accountType, :accountNumber, :description, :firstLastName)")
            .dataSource(dataSource)
            .build();
}
 
Example 6
Source Project: CogStack-Pipeline   Source File: JobConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@StepScope
@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.getRequiredProperty("target.Sql"));
    writer.setDataSource(jdbcDocumentTarget);
    return writer;
}
 
Example 7
Source Project: building-microservices   Source File: BatchConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
JdbcBatchItemWriter<Person> jdbcBatchItemWriter(DataSource h2) {
    JdbcBatchItemWriter<Person> w = new JdbcBatchItemWriter<>();
    w.setDataSource(h2);
    w.setSql("insert into PEOPLE( first, last, email) values ( :first, :last, :email )");
    w.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<>());
    return w;
}
 
Example 8
@Bean
public JdbcBatchItemWriter<Item> jdbcBatchItemWriter() {
	JdbcBatchItemWriter<Item> itemWriter = new JdbcBatchItemWriter<Item>();
	itemWriter.setSql(
			"INSERT INTO ITEM (ID, DESCRIPTION, FIRST_ACTION, SECOND_ACTION) VALUES (:id,:description,:firstAction,:secondAction)");
	itemWriter.setDataSource(dataSource);
	itemWriter.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<Item>());
	return itemWriter;
}
 
Example 9
@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;
}
 
Example 10
@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;
}
 
Example 11
@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;
}
 
Example 12
Source Project: spring4-sandbox   Source File: ConferenceItemWriter.java    License: Apache License 2.0 4 votes vote down vote up
public ConferenceItemWriter(DataSource ds) {
	super();
	setDataSource(ds);
	setSql("update conference set name=:name where id=:id");
	setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<Conference>() );
}