diff --git a/complete/pom.xml b/complete/pom.xml
index b1f81ee766..c874af5bc6 100644
--- a/complete/pom.xml
+++ b/complete/pom.xml
@@ -43,6 +43,11 @@
http://repo.springsource.org/snapshot
true
+
+ spring-milestones
+ http://repo.springsource.org/milestone
+ true
+
diff --git a/complete/src/main/java/hello/BatchConfiguration.java b/complete/src/main/java/hello/BatchConfiguration.java
index c573113d03..1782cd34a8 100644
--- a/complete/src/main/java/hello/BatchConfiguration.java
+++ b/complete/src/main/java/hello/BatchConfiguration.java
@@ -1,5 +1,9 @@
package hello;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+
import javax.sql.DataSource;
import org.springframework.batch.core.Job;
@@ -19,10 +23,12 @@ import org.springframework.batch.item.file.mapping.DefaultLineMapper;
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;
import org.springframework.bootstrap.SpringApplication;
import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration;
+import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
@Configuration
@EnableBatchProcessing
@@ -30,7 +36,16 @@ import org.springframework.jdbc.core.JdbcTemplate;
public class BatchConfiguration {
public static void main(String[] args) {
- SpringApplication.run(BatchConfiguration.class, args);
+ ApplicationContext ctx = SpringApplication.run(BatchConfiguration.class, args);
+ List results = ctx.getBean(JdbcTemplate.class).query("SELECT first_name, last_name FROM people", new RowMapper() {
+ @Override
+ public Person mapRow(ResultSet rs, int row) throws SQLException {
+ return new Person(rs.getString(1), rs.getString(2));
+ }
+ });
+ for (Person person : results) {
+ System.out.println("Found <" + person + "> in the database.");
+ }
}
@Bean
@@ -42,20 +57,14 @@ public class BatchConfiguration {
public ItemReader reader() {
FlatFileItemReader reader = new FlatFileItemReader();
reader.setResource(new ClassPathResource("sample-data.csv"));
- reader.setLineMapper(new DefaultLineMapper() {
- {
- setLineTokenizer(new DelimitedLineTokenizer() {
- {
- setNames(new String[] { "firstName", "lastName" });
- }
- });
- setFieldSetMapper(new BeanWrapperFieldSetMapper() {
- {
- setTargetType(Person.class);
- }
- });
- }
- });
+ reader.setLineMapper(new DefaultLineMapper() {{
+ setLineTokenizer(new DelimitedLineTokenizer() {{
+ setNames(new String[] { "firstName", "lastName" });
+ }});
+ setFieldSetMapper(new BeanWrapperFieldSetMapper() {{
+ setTargetType(Person.class);
+ }});
+ }});
return reader;
}
@@ -75,16 +84,22 @@ public class BatchConfiguration {
@Bean
public Job importUserJob(JobBuilderFactory jobs, Step s1) {
- Job job = jobs.get("importUserJob").incrementer(new RunIdIncrementer()).flow(s1)
- .end().build();
- return job;
+ return jobs.get("importUserJob")
+ .incrementer(new RunIdIncrementer())
+ .flow(s1)
+ .end()
+ .build();
}
@Bean
public Step step1(StepBuilderFactory stepBuilderFactory, ItemReader reader,
ItemWriter writer, ItemProcessor processor) {
- return stepBuilderFactory.get("step1"). chunk(10).reader(reader)
- .processor(processor).writer(writer).build();
+ return stepBuilderFactory.get("step1")
+ . chunk(10)
+ .reader(reader)
+ .processor(processor)
+ .writer(writer)
+ .build();
}
}
diff --git a/complete/src/main/java/hello/Person.java b/complete/src/main/java/hello/Person.java
index d41f7bc9bd..8d8f3fa252 100644
--- a/complete/src/main/java/hello/Person.java
+++ b/complete/src/main/java/hello/Person.java
@@ -24,22 +24,31 @@ public class Person {
private String lastName;
private String firstName;
- public void setFirstName(final String firstName) {
- this.firstName = firstName;
+ public Person() {
+
}
+ public Person(String firstName, String lastName) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
public String getFirstName() {
return firstName;
}
- public void setLastName(final String lastName) {
- this.lastName = lastName;
- }
-
public String getLastName() {
return lastName;
}
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
@Override
public String toString() {
return "firstName: " + firstName + ", lastName: " + lastName;
diff --git a/complete/src/main/java/hello/PersonItemProcessor.java b/complete/src/main/java/hello/PersonItemProcessor.java
index 61c50a229c..28a7d78b79 100644
--- a/complete/src/main/java/hello/PersonItemProcessor.java
+++ b/complete/src/main/java/hello/PersonItemProcessor.java
@@ -29,9 +29,7 @@ public class PersonItemProcessor implements ItemProcessor {
final String firstName = person.getFirstName().toUpperCase();
final String lastName = person.getLastName().toUpperCase();
- final Person transformedPerson = new Person();
- transformedPerson.setFirstName(firstName);
- transformedPerson.setLastName(lastName);
+ final Person transformedPerson = new Person(firstName, lastName);
System.out.println("Converting (" + person + ") into (" + transformedPerson + ")");
diff --git a/complete/src/main/resources/logging.properties b/complete/src/main/resources/logging.properties
deleted file mode 100644
index de241893a4..0000000000
--- a/complete/src/main/resources/logging.properties
+++ /dev/null
@@ -1,4 +0,0 @@
-handlers = java.util.logging.ConsoleHandler
-.level = ALL
-java.util.logging.ConsoleHandler.level = FINE
-org.springframework.jdbc.core.level = FINE
\ No newline at end of file