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 Wed, 21 Jul 2004 09:19:21 GMT
brj         2004/07/21 02:19:21

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlQueryStatement.java SqlSelectStatement.java
               src/test/org/apache/ojb/broker QueryTest.java
  Log:
  orderBy and groupBy columns where not used to build the join
  
  Revision  Changes    Path
  1.77      +27 -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.76
  retrieving revision 1.77
  diff -u -r1.76 -r1.77
  --- SqlQueryStatement.java	20 Jul 2004 20:44:59 -0000	1.76
  +++ SqlQueryStatement.java	21 Jul 2004 09:19:20 -0000	1.77
  @@ -466,6 +466,30 @@
       }
   
       /**
  +     * Builds the Join for columns if they are not found among the existingColumns.
  +     * @param columns the list of columns represented by Criteria.Field to ensure
  +     * @param existingColumns the list of column names (String) that are already appended
  +     */
  +    protected void ensureColumns(List columns, List existingColumns)
  +    {
  +        if (columns == null || columns.isEmpty())
  +        {
  +            return;
  +        }
  +        
  +        Iterator iter = columns.iterator();
  +
  +        while (iter.hasNext())
  +        {
  +            FieldHelper cf = (FieldHelper) iter.next();
  +            if (!existingColumns.contains(cf.name))
  +            {
  +                getAttributeInfo(cf.name, false, null, getQuery().getPathClasses());
  +            }
  +        }
  +    }
  +	
  +    /**
        * appends a WHERE-clause to the Statement
        * @param where
        * @param crit
  @@ -1627,7 +1651,8 @@
           }
   
       }
  -
  + 
  +    
       /**
        * Gets the query.
        * @return Returns a Query
  
  
  
  1.24      +7 -4      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.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- SqlSelectStatement.java	20 Jul 2004 20:44:59 -0000	1.23
  +++ SqlSelectStatement.java	21 Jul 2004 09:19:20 -0000	1.24
  @@ -212,6 +212,12 @@
   					getAttributeInfo(joinAttributes[i], false, null, getQuery().getPathClasses());
                   }
               }
  +
  +            groupByFields = query.getGroupBy();
  +            ensureColumns(groupByFields, columnList);
  +            
  +            orderByFields = query.getOrderBy();
  +            ensureColumns(orderByFields, columnList);
             
               /**
                * treeder: going to map superclass tables here, 
  @@ -233,15 +239,12 @@
               {
                   appendSuperClassJoin(cld, cldSuper, stmt, where);
               }
  -
  -            groupByFields = query.getGroupBy();
               
               appendWhereClause(where, whereCrit, stmt);
               appendGroupByClause(groupByFields, stmt);
               appendHavingClause(having, havingCrit, stmt);
           }
   
  -        orderByFields = query.getOrderBy();
           appendOrderByClause(orderByFields, columnList, stmt);
   
           return stmt.toString();
  
  
  
  1.64      +19 -1     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.63
  retrieving revision 1.64
  diff -u -r1.63 -r1.64
  --- QueryTest.java	20 Jul 2004 20:44:59 -0000	1.63
  +++ QueryTest.java	21 Jul 2004 09:19:20 -0000	1.64
  @@ -133,7 +133,25 @@
           int count = broker.getCount(q);
           assertEquals(results.size(), count);        
       }
  -    
  +
  +    /**
  +	 * test OrderBy joined column
  +	 */
  +    public void testOrderByJoined()
  +    {
  +        Criteria crit = new Criteria();
  +        QueryByCriteria q = QueryFactory.newQuery(Project.class, crit, true);
  +        q.addOrderByAscending("persons.lastname");
  +
  +        Collection results = broker.getCollectionByQuery(q);
  +        assertNotNull(results);
  +        assertTrue(results.size() == 6);
  +        
  +        // compare with count
  +        int count = broker.getCount(q);
  +        assertEquals(results.size(), count);        
  +    }
  +
       /**
   	 * test Subquery get all product groups without articles
   	 *
  
  
  

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