Patch to make SelectQueries work...

From: Mikaël Cluseau (nwr..wrk.dyndns.org)
Date: Fri Apr 15 2005 - 16:32:14 EDT

  • Next message: jira-norepl..bjectstyle.org: "[OS-JIRA] Created: (CAY-306) UI Deprecation Fixes"

    ... with custom DB attributes in queries with multiple tables.

    Thanks for the good work, really.

    As I'm there, is there a way to have subselect queries in Cayenne? Is it
    planned? I ask because in PostgreSQL (at least 7.4 series), a SELECT
    DISTINCT trigger a sort on every wanted field... (in fact, the primary
    key is sufficient since it holds the functionnal dependency). The
    solution is a subquery :

    SELECT t0.* FROM my_table t0 WHERE t0.pk IN (SELECT DISTINCT t0.pk FROM
    my_table t0, my_table t1 WHERE ...)

    On my system, this query runs in 0.3 seconds, while the simple :

    SELECT DISTINCT t0.* FROM my_table t0, my_table t1 WHERE ...

    takes 26 seconds (in case anyone had performance problems with
    PostgreSQL), although it is simpler and strictly equivalent.

    --------- the patch --------

    Index: SelectTranslator.java
    ===================================================================
    RCS file: /cvsroot/cayenne/cayenne/src/cayenne/java/org/objectstyle/cayenne/access/trans/SelectTranslator.java,v
    retrieving revision 1.40
    diff -u -r1.40 SelectTranslator.java
    --- SelectTranslator.java 19 Mar 2005 19:49:22 -0000 1.40
    +++ SelectTranslator.java 15 Apr 2005 20:12:19 -0000
    ..-570,7 +570,8 @@
                             + customAttributes.get(i));
                 }
     
    - columns.add(new ColumnDescriptor(attribute, null));
    + String alias = aliasForTable((DbEntity) attribute.getEntity());
    + columns.add(new ColumnDescriptor(attribute, alias));
             }
     
             return columns;



    This archive was generated by hypermail 2.0.0 : Fri Apr 15 2005 - 16:32:18 EDT