简体   繁体   中英

How to select/insert using Spring Integration

I have a requirement of

  • Select * from User where id=:id

  • Insert into table UserDump (< all User table columns >, processedDate) values (< all User table column >, getDate)

What I have done :-

  1. I have one < int-jdbc:inbound-channel-adapter > which I am using for select statement.

  2. I have one Transformer which is taking the output(List< Map > resultset) and updating my model.

  3. I have one activator which is accepting my Transformer's output and inserting into my UserDump table. Values are coming from updated model earlier.

My program is running fine as expected but

  1. How to update "id" param in my select statement. Currently I have hard coded for testing the functionality.

  2. My program is just running indefintly. Not halting. ie once the insertion is done it should stop by itself.

  3. I know, < poller > is something that I have to have in my xml but I want to run it on demand. Not like after every fix time interval.

Not exact code but direction would be enough.

If your application is simply for moving data from a source to destination, I would suggest you take a look at Spring Batch . It's an extension of the Spring framework specifically used for batch jobs like this. If you're already fairly familiar with the Spring framework, defining a simple job with Spring Batch shouldn't be too hard. (This might help you with having the application end at an appropriate time without having to do any polling).

Also, if you want to define SQL templates which you can send parameters to, I would suggest you take a look at MyBatis . It eliminates the need to write any JDBC code and let's you call pre-defined SQL statements like a method call with parameters. This should let you send many select statements, each with a different "id" parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM