I have a method to get a load of objects from a database, which returns an Iterable
.
For now, I am loading a resultset from a database, building objects from it and populating a collection with those objects.
Obviously, I'm memory constrained as to how much data can be loaded using this method and if I run out Bad Things Happen.
I'd like to modify the implementation to chunk data from the database instead of getting it all at once and then expose the resulting objects to the client through the Iterable
interface. My database drivers can do their bit, so my first thought is a custom implementation of Iterable
that does this.
Is this a good approach? It strikes me as something that might already be supported in the runtime or libraries - not involving ORM solutions please.
Iterable
and not just anIterator
? The later would probably be easier as you wouldn't have to add the ability to re-start the iteration. – Joachim Sauer Oct 28 '11 at 8:39