You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-dev@db.apache.org by "Andy Jefferson (JIRA)" <ji...@apache.org> on 2015/04/30 09:31:06 UTC

[jira] [Commented] (JDO-736) Change Query API to make use of generics to avoid casting execute() results

    [ https://issues.apache.org/jira/browse/JDO-736?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14521061#comment-14521061 ] 

Andy Jefferson commented on JDO-736:
------------------------------------

Suggestion for execute method(s) to avoid casting

    /**
     * Method to execute the query where there are (potentially) multiple rows and we are returning the candidate type.
     */
    <T> List<T> executeList();

    /**
     * Method to execute the query where there is a single row and we are returning the candidate type.
     */
    <T> T executeUnique();

    /**
     * Method to execute the query where there are (potentially) multiple rows and we are returning a result type for the specified result.
     */
    <R> List<R> executeResultList(Class<R> resultCls);

    /**
     * Method to execute the query where there is a single row and we are returning a result type for the specified result.
     */
    <R> R executeResultUnique(Class<R> resultCls);

    /**
     * Method to execute the query where there are (potentially) multiple rows and we have a result defined but no result class.
     */
    List<Object> executeResultList();

    /**
     * Method to execute the query where there is a single row and we have a result defined but no result class.
     */
    Object executeResultUnique();

    long deletePersistentAll();

    Query<T> setParameter(Expression paramExpr, Object value);

    Query<T> setParameter(String paramName, Object value);

    Query<T> clearParameters();


So key things are, we move parameter specification to pre-execute (to avoid having to have even more execute methods), and specify the resultClass in the execute when it is required. I've left "result" as part of the query in the above, since in traditional JDOQL we only have a String and not an array of result components so can't distinguish the other 2 possible return types from execute (List<Object[]> and Object[]).

This is intended for discussion, so discuss. Somebody got a better, cleaner idea?

> 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)