[ https://issues.apache.org/jira/browse/JDO-736?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14521298#comment-14521298 ]
Tilmann Zäschke commented on JDO-736: ------------------------------------- Instead of having all these methods in the Query API, would it make sense to move them into a separate class 'QueryProjector' or so? Query.java would get have only one additional method <T> execute(QueryProjector<T> def); I think of something like the factory or builder pattern To allow flow-style programming, one could use: MyClass t = QueryProjector.executeUnique(pm.newQuery(Myclass.class)); or List<MyResultClass> list = QueryProjector.executeList(ResultClass.class, pm.newQuery(Myclass.class)); This would allow to maintain different projections for the same query. Would that be useful? Another solution to the unique() problem would be to return a dedicated result class, such as QueryResult. QueryResult qr = query.execute(); MyClass o = qr.getUniqe(); //returns the result or 'null', may also close the query result Query result would also implement List<>, so it could be used as follows: for (MyClass o: qr) { //do something } > Change Query API to make use of generics to avoid casting execute() results > --------------------------------------------------------------------------- > > Key: JDO-736 > URL: https://issues.apache.org/jira/browse/JDO-736 > Project: JDO > Issue Type: New Feature > Components: api, specification, tck > Reporter: Andy Jefferson > Fix For: JDO 3.2 > > > The query API is dated, requiring casting of results to the required type. > Let's make use of generics etc and remove the pain. This will mean changing > the API so that the resultClass (and possibly more) will need passing into > the > execute() method(s). Could also specify parameters via setter rather than > just on the execute. > See JDO-652 also, we need to have a consistent way of executing queries > whether created using strings or typesafe, so that no casting of results is > needed with either -- This message was sent by Atlassian JIRA (v6.3.4#6332)