Friday, February 26, 2010

Version 1.2 - Full Support of GAE Types

AuDAO now supports all Google App Engine types including Lists. Although Lists appeared in the version 1.1, it was only a limited solution. Now Lists can contain all types as normal single properties including the new types - GAE core types like Key, Geopt or User.

Let's look how it is easy to work with generated classes:
  OfficeDao dao = DaoFactory.createOfficeDao();

Office off = new Office();
off.setLocation( new GeoPt( latitude, longitude ));
off.setManager( new User( managerMail, "" ));
off.setOnSite( Arrays.asList( off.getManager(), myself ));

dao.insert( off );

FIND (and also COUNT and DELETE):
  // location = geopt
dao.findByLocation( new GeoPt( latitude, longitude ));
// location IN (loc1, loc2, loc3)
dao.findByLocations( Arrays.asList( loc1, loc2, loc3 ));
// manager = user
dao.findByManager( new User( managerMail, "" ));
// onSite IN (john, jack, myself)
dao.findBySomeOnSite( Arrays.asList( john, jack, myself ));
// onSite = manager AND onSite = myself
dao.findByAllOnSite( Arrays.asList( manager, myself ));

The last finder is one of the most interesting one - it automatically expands simple equality condition into several conditions concatenated by "AND" operator.

And all these DTO and DAO classes can be generated automatically from a source config XML file which can have less than 100 lines and 2KB of size! Learn more...

Well, if you need to create conditions dynamically, the DAO can be generated to allow it as well. GQL queries are supported:
  // find the office where the manager is on-site
// 0=offset, 1=maxRecords
dao.findDynamic("manager=USER(:1) AND onSite=USER(:1)", 0, 1, managerEmail);

You can create dynamic queries on keys as well:
  dao.findDynamic("__key__ IN :1", Arrays.asList( id1, id2, id3 ));

More information about GQL Parser you can find at here.

Happy generating !

No comments:

Post a Comment