Hi all,
I've committed some changes to the DAO to the trunk. I've simplified
it quite a bit, but the main changes are:
1) Renamed some methods for consistency.
2) Rather than return a List<T> from the finder methods, I've created
a Result<T> interface that is returned instead. This new interface
extends both Iterable<T> and Iterator<T>. The main reason for this is
to allow the user to decide whether to iterate over the results doing
the object mapping on demand, or map all the results and transform to
a list. Examples:
DAO<Hotel,String> hotelDAO = new DAO<Hotel,String>(...);
Results<Hotel> hotels = hotelDAO.find(new Constraints("stars",
4).limit(10));
for ( Hotel hotel : hotels ) {
...
}
// we can still get the hotels as a java.util.List, just use the
Results<T>.asList() method:
List<Hotel> hotelList = hotelDAO.find().asList();
// same goes for retrieving just the IDs, the Results object will
then be parameterized with the ID class:
Results<String> hotelIds = hotelDAO.findIds();
3) I've added update methods to support the update modifiers listed
here:
http://www.mongodb.org/display/DOCS/Updating
For example:
DAO<Hotel,String> hotelDAO = new DAO<Hotel,String>(...);
// update all 4 star hotels to 5 stars
Modifiers mods = new Modifiers().inc("stars", 1);
hotelDAO.update(new Constraints("stars", 4), mods);
4) Finally, I've removed the methods that accepted java.util.Map as
query object. Use the Constraints object instead. If you need to do
stuff the Constraint object does not support, you can always extend
the DAO<T,K> object with your own finder methods.
Hope you like these changes, the DAO API should be more powerful and
simple at the same time :)
Regards,
OGG
--
Subscription settings:
http://groups.google.com/group/morphia/subscribe?hl=en