JDO and query language

| | bookmark | email
All this has started with a forum discussion on the articles on TSS: JDO Query Part 1 and JDO Query Part 2 I think that JDOQL has gone a long way ... in the good direction and it shows now a lot of power. I like very much the idea of objectual querying, i.e.:
Query q = pm.newQuery (Seller.class, "accountNumber == '0072'");
or the more advanced
Query q = pm.newQuery (AuctionItem.class, "description.matches('.*Connect.*')");
idea that has been used by Hibernate for a while. This is quite impressive and I find it very neat. But in a way reading the articles I had the feeling that the spec stopped in the middle and proposed:
Query q = pm.newQuery (AuctionItem.class, "winningBid.bidAmount > reservePrice"); q.setResult ("title, reservePrice, winningBid.bidAmount, winningBid.bidder.user.userName");
I consider the above unnecessary API. I am not sure (and I mostly believe that currently this is not possible), but I would write the above in the following way (again a form of this is already available in Hibernate):
pm.newQuery("AuctionItem.title", "AuctionItem.reserverPrice",....);
or removing the varargs from above:
pm.newQuery({"AuctionItem.title", "AuctionItem.reserverPrice"}, filter);
Why I would like this? Because in this way all the querying is objectual and no additional API is involved. Unfortunately the above hides a little problem too: compile time check. If I change the AuctionItem, than I will discover that my query is broken only at runtime (this maybe has already required a redeploy of the app). So I think the best solution would allow you to build the query:
pm.newQuery().addResultField(ai.title) .addResultField(ai.reserverPrice)...
(note the missing quotes; but still a problem as I needed an instance of AuctionItem :-( ). Hoping you got my point, I would like to move forward. I like that a lot of aggregate function have been taken into account, but again I feel it is a mix: what does it really mean in objectual model count() or distinct? These are rather DB functions and I would like to have it like this:
addResultField().setAggregateFunction()
or maybe better
addCount(addDistinct(ai.title))
I see the point on having these on a ORM, but in a more generic spec as JDO intend to be, I think they must be more near to objectual model than to RDBMS. And finally - at least for the moment - I would not go for inventing new notations/notions for something already existing: indeed regexp can be seen as a good selection filter but I haven't seen the (?i) till now. Also why bothering to create unbound variables when an implicit variable would solve it? Here I might be wrong as I see some interesting usage in
String filter = "bidder.bids.contains(b) && b.item.seller == seller && b.item != this"; Query q = pm.newQuery (AuctionItem.class, filter); q.declareVariables ("Bidder bidder; Bid b"); Collection results = (Collection)q.execute ();