Reputation: 49067
I am creating a web service and I wondered if there was a solution to paginate all queries.
Currently I am creating overloaded methods such as findAll(int offset, int limit)
etc. But I wondered if there was another solution to this which doesn't create that much duplication of logic in the finders. I want to this at database level. Or is the solution that I came up with an OK approach?
Upvotes: 0
Views: 125
Reputation: 34367
I think you may want to use method overloading to avoid duplication of logic, if duplication is the primary concern.
Change all your existing findAll
methods to support pagination as you have mentioned:
findAll(int offset, int limit)
Then create overloaded findAll()
method and internally call the findAll
methods created in step 1 with default values e.g. below:
findAll(){
//set appropriate defaults, Integer.MAX_VALUE is just an example
findAll(0, Integer.MAX_VALUE);
}
Upvotes: 4