Let's look how it is easy to work with generated classes:
CREATE:
OfficeDao dao = DaoFactory.createOfficeDao();
Office off = new Office();
off.setLocation( new GeoPt( latitude, longitude ));
off.setManager( new User( managerMail, "gmail.com" ));
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, "gmail.com" ));
...
// 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