db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/broker QueryTest.java
Date Sat, 24 Jul 2004 19:26:41 GMT
brj         2004/07/24 12:26:40

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlQueryStatement.java SqlSelectStatement.java
               src/java/org/apache/ojb/broker/util BrokerHelper.java
               .        release-notes.txt
               src/test/org/apache/ojb/broker QueryTest.java
  Log:
  - add orderBy-columns to select-clause (because of sapdb)
  - use orderBy-columns of query as joinAttributes of count-query
  
  Revision  Changes    Path
  1.78      +33 -2     db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java
  
  Index: SqlQueryStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java,v
  retrieving revision 1.77
  retrieving revision 1.78
  diff -u -r1.77 -r1.78
  --- SqlQueryStatement.java	21 Jul 2004 09:19:20 -0000	1.77
  +++ SqlQueryStatement.java	24 Jul 2004 19:26:40 -0000	1.78
  @@ -488,7 +488,38 @@
               }
           }
       }
  -	
  +
  +    /**
  +     * Builds the Join for columns if they are not found among the existingColumns.
  +     * These <b>columns are added to the statement</b> using a column-alias
"ojb_col_x", 
  +     * x being the number of existing columns
  +     * @param columns the list of columns represented by Criteria.Field to ensure
  +     * @param existingColumns the list of column names (String) that are already appended
  +     * @param buf the statement
  +     */
  +    protected void ensureColumns(List columns, List existingColumns, StringBuffer buf)
  +    {
  +        if (columns == null || columns.isEmpty())
  +        {
  +            return;
  +        }
  +
  +        Iterator iter = columns.iterator();
  +        int ojb_col = existingColumns.size();
  +
  +        while (iter.hasNext())
  +        {
  +            FieldHelper cf = (FieldHelper) iter.next();
  +            if (!existingColumns.contains(cf.name))
  +            {
  +                buf.append(",");
  +                appendColName(cf.name, "ojb_col_" + ojb_col, false, null, buf);
  +                ojb_col++;
  +            }
  +        }
  +    }
  +
  +
       /**
        * appends a WHERE-clause to the Statement
        * @param where
  
  
  
  1.25      +2 -2      db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectStatement.java
  
  Index: SqlSelectStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectStatement.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- SqlSelectStatement.java	21 Jul 2004 09:19:20 -0000	1.24
  +++ SqlSelectStatement.java	24 Jul 2004 19:26:40 -0000	1.25
  @@ -217,7 +217,7 @@
               ensureColumns(groupByFields, columnList);
               
               orderByFields = query.getOrderBy();
  -            ensureColumns(orderByFields, columnList);
  +            ensureColumns(orderByFields, columnList, stmt);
             
               /**
                * treeder: going to map superclass tables here, 
  
  
  
  1.59      +14 -1     db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java
  
  Index: BrokerHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java,v
  retrieving revision 1.58
  retrieving revision 1.59
  diff -u -r1.58 -r1.59
  --- BrokerHelper.java	13 Jul 2004 11:37:57 -0000	1.58
  +++ BrokerHelper.java	24 Jul 2004 19:26:40 -0000	1.59
  @@ -598,6 +598,19 @@
                   countQuery.setPathOuterJoin(path);
               }
           }
  +        
  +        //BRJ: add orderBy Columns asJoinAttributes
  +        List orderBy = aQuery.getOrderBy();
  +        if (orderBy != null && !orderBy.isEmpty())
  +        {
  +            String[] joinAttributes = new String[orderBy.size()];
  +            for (int i=0; i<orderBy.size(); i++)
  +            {
  +                joinAttributes[i] = ((FieldHelper)orderBy.get(i)).name;
  +            }
  +            
  +            countQuery.setJoinAttributes(joinAttributes);            
  +        }
   
           return countQuery;
       }
  
  
  
  1.57      +3 -2      db-ojb/release-notes.txt
  
  Index: release-notes.txt
  ===================================================================
  RCS file: /home/cvs/db-ojb/release-notes.txt,v
  retrieving revision 1.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- release-notes.txt	20 Jul 2004 20:52:55 -0000	1.56
  +++ release-notes.txt	24 Jul 2004 19:26:40 -0000	1.57
  @@ -17,7 +17,8 @@
   - ManageableCollection#afterStore is only called if cascadeStoring is CASCADE_OBJECT
   
   - mixing of mappings 1-table/1-class and 1-table/many classes is now supported
  -- ojb lo longer adds groupBy and orderBy columns to the SELECT-clause
  +- ojb no longer adds groupBy columns to the SELECT-clause, orderBy columns are still added
because of sapdb
  +- orderBy columns of the original query are used as joinAttributes in count-query
   - ALIAS-prefix again works for report-queries (see QueryTest#testReportQueryAlias) 
   
   ---------------------------------------------------------------------
  
  
  
  1.67      +3 -2      db-ojb/src/test/org/apache/ojb/broker/QueryTest.java
  
  Index: QueryTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/QueryTest.java,v
  retrieving revision 1.66
  retrieving revision 1.67
  diff -u -r1.66 -r1.67
  --- QueryTest.java	23 Jul 2004 11:49:46 -0000	1.66
  +++ QueryTest.java	24 Jul 2004 19:26:40 -0000	1.67
  @@ -180,12 +180,13 @@
       public void testOrderByJoined()
       {
           Criteria crit = new Criteria();
  -        QueryByCriteria q = QueryFactory.newQuery(Project.class, crit, true);
  +        QueryByCriteria q = QueryFactory.newQuery(Project.class, crit);
           q.addOrderByAscending("persons.lastname");
  +        q.addOrderByAscending("persons.firstname");
   
           Collection results = broker.getCollectionByQuery(q);
           assertNotNull(results);
  -        assertTrue(results.size() == 6);
  +        assertTrue(results.size() == 14);
           
           // compare with count
           int count = broker.getCount(q);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message