Update docs with new features of v4.1.0.M3
This commit is contained in:
committed by
Michael Minella
parent
57c4acdf22
commit
80d0015bb7
@@ -58,7 +58,8 @@
|
||||
Spring Data repository implementation.
|
||||
|StoredProcedureItemReader|Reads from a database cursor resulting from the
|
||||
execution of a database stored procedure. See link:readersAndWriters.html#StoredProcedureItemReader[`StoredProcedureItemReader`]
|
||||
|StaxEventItemReader|Reads via StAX. see link:readersAndWriters.html#flatFileItemReader[`FlatFileItemReader`].
|
||||
|StaxEventItemReader|Reads via StAX. see link:readersAndWriters.html#StaxEventItemReader[`StaxEventItemReader`].
|
||||
|JsonItemReader|Reads items from a Json document. see link:readersAndWriters.html#JsonItemReader[`JsonItemReader`].
|
||||
|
||||
|===============
|
||||
|
||||
@@ -119,5 +120,7 @@
|
||||
|StaxEventItemWriter|Uses a `Marshaller` implementation to
|
||||
convert each item to XML and then writes it to an XML file using
|
||||
StAX.
|
||||
|JsonFileItemWriter|Uses a `JsonObjectMarshaller` implementation to
|
||||
convert each item to Json and then writes it to an Json file.
|
||||
|
||||
|===============
|
||||
|
||||
@@ -1348,6 +1348,25 @@ In the previous example, the `BeanWrapperFieldExtractor` described earlier in th
|
||||
chapter is used to turn the name and credit fields within `CustomerCredit` into an object
|
||||
array, which is then written out with commas between each field.
|
||||
|
||||
It is also possible to use the `FlatFileItemWriterBuilder.DelimitedBuilder` to
|
||||
automatically create the `BeanWrapperFieldExtractor` and `DelimitedLineAggregator`
|
||||
as shown in the following example:
|
||||
|
||||
.Java Configuration
|
||||
[source, java, role="javaContent"]
|
||||
----
|
||||
@Bean
|
||||
public FlatFileItemWriter<CustomerCredit> itemWriter(Resource outputResource) throws Exception {
|
||||
return new FlatFileItemWriterBuilder<CustomerCredit>()
|
||||
.name("customerCreditWriter")
|
||||
.resource(outputResource)
|
||||
.delimited()
|
||||
.delimiter(",")
|
||||
.names(new String[] {"name", "credit"})
|
||||
.build();
|
||||
}
|
||||
----
|
||||
|
||||
[[fixedWidthFileWritingExample]]
|
||||
===== Fixed Width File Writing Example
|
||||
|
||||
@@ -1418,6 +1437,25 @@ The underlying implementation is built using the same
|
||||
language. Most details on how to configure a formatter can be found in
|
||||
the Javadoc of link:$$https://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html$$[Formatter].
|
||||
|
||||
It is also possible to use the `FlatFileItemWriterBuilder.FormattedBuilder` to
|
||||
automatically create the `BeanWrapperFieldExtractor` and `FormatterLineAggregator`
|
||||
as shown in following example:
|
||||
|
||||
.Java Configuration
|
||||
[source, java, role="javaContent"]
|
||||
----
|
||||
@Bean
|
||||
public FlatFileItemWriter<CustomerCredit> itemWriter(Resource outputResource) throws Exception {
|
||||
return new FlatFileItemWriterBuilder<CustomerCredit>()
|
||||
.name("customerCreditWriter")
|
||||
.resource(outputResource)
|
||||
.formatted()
|
||||
.format("%-9s%-2.0f")
|
||||
.names(new String[] {"name", "credit"})
|
||||
.build();
|
||||
}
|
||||
----
|
||||
|
||||
[[handlingFileCreation]]
|
||||
===== Handling File Creation
|
||||
|
||||
|
||||
@@ -254,3 +254,69 @@ public BeanValidatingItemProcessor<Person> beanValidatingItemProcessor() throws
|
||||
}
|
||||
----
|
||||
|
||||
=== JSR-305 support
|
||||
|
||||
This release adds support for JSR-305 annotations. It leverages Spring Framework’s
|
||||
link:$$https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#null-safety$$[Null-safety]
|
||||
annotations and adds them on all public APIs of Spring Batch.
|
||||
|
||||
These annotations will not only enforce null-safety when using Spring Batch APIs,
|
||||
but also can be used by IDEs to provide useful information related to nullability.
|
||||
For example, if a user wants to implement the `ItemReader` interface, any IDE
|
||||
supporting JSR-305 annotations will generate something like:
|
||||
|
||||
[source, java]
|
||||
----
|
||||
public class MyItemReader implements ItemReader<String> {
|
||||
|
||||
@Nullable
|
||||
public String read() throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
The `@Nullable` annotation present on the `read` method makes it clear that the
|
||||
contract of this method says it may return `null`. This enforces what is said in its
|
||||
Javadoc, that the `read` method should return `null` when the data source is exhausted.
|
||||
|
||||
=== `FlatFileItemWriterBuilder` enhancements
|
||||
|
||||
Another small feature added in this release is a simplification of the configuration
|
||||
for the writing of a flat file. Specifically, these updates simplify the configuration
|
||||
of both a delimited and fixed width file. Below is an example of before and after the change.
|
||||
|
||||
[source, java]
|
||||
----
|
||||
// Before
|
||||
@Bean
|
||||
public FlatFileItemWriter<Item> itemWriter(Resource resource) {
|
||||
BeanWrapperFieldExtractor<Item> fieldExtractor =
|
||||
new BeanWrapperFieldExtractor<Item>();
|
||||
fieldExtractor.setNames(new String[] {"field1", "field2", "field3"});
|
||||
fieldExtractor.afterPropertiesSet();
|
||||
|
||||
DelimitedLineAggregator aggregator = new DelimitedLineAggregator();
|
||||
aggregator.setFieldExtractor(fieldExtractor);
|
||||
aggregator.setDelimiter(";");
|
||||
|
||||
return new FlatFileItemWriterBuilder<Item>()
|
||||
.name("itemWriter")
|
||||
.resource(resource)
|
||||
.lineAggregator(aggregator)
|
||||
.build();
|
||||
}
|
||||
|
||||
// After
|
||||
@Bean
|
||||
public FlatFileItemWriter<Item> itemWriter(Resource resource) {
|
||||
return new FlatFileItemWriterBuilder<Item>()
|
||||
.name("itemWriter")
|
||||
.resource(resource)
|
||||
.delimited()
|
||||
.delimiter(";")
|
||||
.names(new String[] {"field1", "field2", "field3"})
|
||||
.build();
|
||||
}
|
||||
----
|
||||
|
||||
Reference in New Issue
Block a user