I need to dump data from a table in oracle to elasticsearch(100 Million record), My memory limit of JVM is 256M, I use the following code and config to get the data from oracle
There are two options:
ResultHandler
That is how you can use custom ResultHandler
:
PersonMapper.xml
PersonMapper.java
public interface PersonMapper {
void selectAllPersons(ResultHandler handler);
}
MyService.java
class PersonResultHandler implements ResultHandler {
@Override
public void handleResult(ResultContext context) {
Person person = (Person)context.getResultObject();
// process person here
}
};
PersonResultHandler handler = new PersonResultHandler();
PersonMapper personMapper = ...;
personMapper.selectAllPersons(handler);
Starting from mybatis 3.4.1 you can return Cursor which is Iterable
and can be used like this (under condition that result is ordered, see above Cursor
API java doc for details):
PersonMapper.java
public interface PersonMapper {
Cursor selectAllPersons();
}
MyService.java
PersonMapper personMapper = ...;
try (Cursor persons = personMapper.selectAllPersons()) {
for (Person person : persons) {
// process one person
}
}