Results 1 to 7 of 7

Thread: Setup question

  1. #1
    Join Date
    Apr 2010
    Posts
    23

    Default Setup question

    Hi All,

    Could you give me some advised how to setup the following case with spring batch:

    I've have to read several types of objects from the database and I have to write those object to a single xml file.

    Code:
    DB                                                      XML
     |            Locations                                  |
     |----------------------------->|                        |
     |            Vehicles          |                        |
     |----------------------------->|----------------------->|
     |            Movements         |                        |
     |----------------------------->|                        |
    so you could say I've multiple readers where each reader gives a different type of object and one writer

    Now I wondering what the best thing is todo:

    * Should I use multiple steps (reader/writer) to read all data from the database put it somewhere in the cache. And let the last reader/writer, read the cache and write to the file. In this case where should I store the cache? I don't want to those objects in the database? but other job(data/params) have to be stored in the database?

    * Write a composite reader (but I'm not sure if this is possible for my case)?

    * something else?

    Regards,

    D.Reijntjens
    Last edited by Reijnemans; May 3rd, 2011 at 02:02 AM.

  2. #2
    Join Date
    Dec 2010
    Posts
    175

    Smile

    Looks like you want to read from many tables and write to one file.

    Isn't it possible to write SQL joins to fetch data from these table and then write to xml. If they are being written in one xml file, I assume it is relational data.

    else you may also write a stored proc and use StoredProcedureItemReader.

  3. #3
    Join Date
    Apr 2010
    Posts
    23

    Default

    Thanks for your response tiger.spring.

    Unfortunally it is not possible to write it in one query. I already looked at it. And a storedProcedure is not allowed.

    Think the best thing is to have a open stream for multiple writer, Or a second jobcontext one in memroy and one database. however this is not possible.

    Is it possible to keep something in memory during the job besides the (job/step)execution-context.

    Regards,

    D.Reijntjens

  4. #4
    Join Date
    Dec 2010
    Posts
    175

    Smile

    I don't think you should use multiple writer because you want to create one xml file which could be something like:

    Code:
    <Customer>
        <name>
        <Address>
            <street>
            <state>
         </Address>
        <Order>
              <id>
              <products>
                       <id>
                       <qty>
               </products>
         </order>
    </customer>
    You should still be able to write one customItemReader which utilizes a composite service and returns each customer object to the item readers read() method and then write it using xml writer.

  5. #5
    Join Date
    Apr 2010
    Posts
    23

    Default

    Quote Originally Posted by tiger.spring View Post
    I don't think you should use multiple writer because you want to create one xml file which could be something like:
    Correct I prefer not to.

    Quote Originally Posted by tiger.spring View Post
    You should still be able to write one customItemReader which utilizes a composite service and returns each customer object to the item readers read() method and then write it using xml writer.
    This is maybe possible, but I'm not totally sure how a composite service is working. As I read a ItemReader is calling another ItemReader.

    I've have to read one "schedule" (root element) in the schedule is a list of locations, vehicles. movements, ....

    Some of the data (Movements for example) we read about 10.000 records from the database, perform some business logic, and take a small peace of the movement we have to put in the XML. At first I wanted todo this with a HibernatePagingItemReader or HibernateCursorItemReader, to make sure we don't have all Movements in memory, and the transactions doesn't take to long. Do I still have this functionality as I use a composite reader? Or does a composite reader (In my case) read all data for the root element at once in one transaction?

  6. #6
    Join Date
    Apr 2010
    Posts
    23

    Default

    Maybe I have to write all data to ThreadLocal, and when everything is read, create a reader on my ThreadLocal and write it to an xml file.

  7. #7
    Join Date
    Dec 2010
    Posts
    175

    Smile

    Correction: I was referring to composite service and not composite reader.

    Your service will be framework independent and will return list of customer objects to the reader.

    Quote Originally Posted by Reijnemans View Post
    Correct I prefer not to.



    This is maybe possible, but I'm not totally sure how a composite service is working. As I read a ItemReader is calling another ItemReader.

    I've have to read one "schedule" (root element) in the schedule is a list of locations, vehicles. movements, ....

    Some of the data (Movements for example) we read about 10.000 records from the database, perform some business logic, and take a small peace of the movement we have to put in the XML. At first I wanted todo this with a HibernatePagingItemReader or HibernateCursorItemReader, to make sure we don't have all Movements in memory, and the transactions doesn't take to long. Do I still have this functionality as I use a composite reader? Or does a composite reader (In my case) read all data for the root element at once in one transaction?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •