I did some searching but couldn't find any sample/example.
I've a requirement where geo coordinates from one table (input) are read, processed to generate POI's associated to coordinate. So one geo coordinate will result in one or more POI's that needs to be inserted into another table (output).
I'm currently using a JdbcCursorItemReader and JdbcBatchItemWriter to read one item/record and write one item/record. There is also an ItemProcessor that generates the POI's for a give geo coordinate.
Does a custom JdbcBatchItemWriter help me achieve this?
Any ideas? TIA.
What you are really looking for is called a Splitter pattern:
Here is how it is defined in Spring Integration:
A Splitter is a type of Message Endpoint whose responsibility is to accept a Message from its input channel, split that Message into multiple Messages, and then send each of those to its output channel. This is typically used for dividing a "composite" payload object into a group of Messages containing the sub-divided payloads.
Configuration is extremely simple:
<channel id="inputChannel"/>
<splitter id="splitter"
ref="splitterBean"
method="split"
input-channel="inputChannel"
output-channel="outputChannel" />
<channel id="outputChannel"/>
<beans:bean id="splitterBean" class="sample.PojoSplitter"/>
Or you can use annotations:
@Splitter
List<LineItem> extractItems(Order order) {
return order.getItems()
}
You can of course write your own JdbcBatchItemWriter
if it feels simpler. However Spring Integration already does it for you.
You can use Spring Integration JDBC Support => jdbc:inbound-channel-adapter
/ jdbc:outbound-channel-adapter
and the above splitter to achieve what you want and.. simplicity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With