2
votes

I have two databases, Oracle and MySQL. The target is saving value from a table in Oracle into MySQL, with the requirement: data does not exist in MySQL table.

But I had trouble understanding spring batch. In step, it contains itemReader, itemProcessor, and itemWriter. If my understanding is correct, a step only can have single itemReader (cmiiw)

My plan is to make 2 steps:

Step 1. List from MySQL table

Step 2. Compare T from Oracle with List (step 1) using a primary key ex: id.

If the approach is correct, My question is: how make a List in step? and how passing it into step 2?

I kindly need guidance in this, thank you

1

1 Answers

0
votes

for your requirement , you can use a custom Item reader , for example

public class MyItemReader implements ItemReader<MyDTO> {

    @Override
    public MyDTO read() throws Exception {
        MyDTO myDto = null;

        /*
        your custom code 

        */

        return myDto;
    }
}

But the better approach as per the Sprig batch structure will be

enter image description here

So you can handle your logic in processor , in the processor you can compare data with oracle ,

Step 1. List from MySQL table - will be handled in spring batch reader

Step 2. Compare T from Oracle with List (step 1) using a primary key ex: id. - will be handled in processor

to increase performance , i would suggest you to make use of some cache if oracle data is not too much. If oracle data is large then you can just go with the simple way of looking out for data on oracle DB in your processor