I have a Set<String> catNames
which contains a huge list of cats names (~35K) and I need to load from the database (Sybase) all of those Cat
objects and put them into a Map<String, Cat> cats
: each line contain the cat name and the corresponding cat object.
Knowing that I'm using OJB 1.4 (it load the object Cat
and all of its dependencies like Food
, Clothes
...), which is the better way to load such enormous list of cats ?
Solution 1 : one access to the database per catName
cat = getCatByName(catName);
then cats.put(catName, cat);
and return cats;
Solution 2 : one access to the database for all those cat names
cats = getCatsByNames(catNames);
then
for (Iterator iterator = cats.iterator(); iterator.hasNext();) {
cat = (Cat)iterator.next();
cats.put(cat.getName(), cat);
}
and return cats;
PS : getCatsByNames
uses criteria.addIn("catName", catNames);