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, 31 Mar 2004 19:16:09 GMT
brj         2004/03/31 11:16:09

  Modified:    src/java/org/apache/ojb/broker/query QueryByCriteria.java
               src/java/org/apache/ojb/broker/util BrokerHelper.java
               src/test/org/apache/ojb/broker QueryTest.java
  Log:
  copy pathOuterJoin to count query
  
  Revision  Changes    Path
  1.24      +19 -4     db-ojb/src/java/org/apache/ojb/broker/query/QueryByCriteria.java
  
  Index: QueryByCriteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/QueryByCriteria.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- QueryByCriteria.java	11 Mar 2004 18:16:13 -0000	1.23
  +++ QueryByCriteria.java	31 Mar 2004 19:16:08 -0000	1.24
  @@ -16,6 +16,7 @@
    */
   
   import java.util.ArrayList;
  +import java.util.Collection;
   import java.util.HashMap;
   import java.util.List;
   import java.util.Map;
  @@ -240,7 +241,7 @@
        */
       public boolean isPathOuterJoin(String aPath)
       {
  -        Boolean result = (Boolean)getPathOuterJoin().get(aPath);
  +        Boolean result = (Boolean)getPathOuterJoinMap().get(aPath);
   
           if (result != null)
           {
  @@ -259,7 +260,7 @@
        */
       public void setPathOuterJoin(String aPath)
       {
  -        getPathOuterJoin().put(aPath, Boolean.TRUE);
  +        getPathOuterJoinMap().put(aPath, Boolean.TRUE);
       }
   
       /* (non-Javadoc)
  @@ -496,11 +497,25 @@
           return temp;
       }
   
  -    protected Map getPathOuterJoin()
  +	/**
  +     * Get a Map containing hints about the Outer-Join-Setting
  +     * of a Path, key is the Path value a Boolean
  +	 * @return a Map containing Outer-Join-Settings for the Paths.
  +	 */
  +    protected Map getPathOuterJoinMap()
       {
           return m_pathOuterJoin;
       }
   
  +	/**
  +     * Get a Collection containing all Paths having an Outer-Joins-Setting
  +	 * @return a Collection containing the Paths
  +	 */
  +    public Collection getOuterJoinPaths()
  +    {
  +        return getPathOuterJoinMap().keySet();
  +    }
  +    
       public String getObjectProjectionAttribute()
       {
           return m_objectProjectionAttribute;
  
  
  
  1.44      +12 -2     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.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- BrokerHelper.java	27 Mar 2004 18:19:05 -0000	1.43
  +++ BrokerHelper.java	31 Mar 2004 19:16:08 -0000	1.44
  @@ -540,7 +540,6 @@
                       keyColumns[i] = pkFields[i].getAttributeName();
                   }
               }
  -
               columns[0] = "count(distinct " + getPlatform().concatenate(keyColumns) + ")";
           }
           else
  @@ -563,6 +562,17 @@
               countQuery = new ReportQueryByCriteria(searchClass, columns, countCrit);
           }
   
  +        // BRJ: we have to preserve outer-join-settings (by André Markwalder)
  +        Iterator outerJoinPath = aQuery.getOuterJoinPaths().iterator();
  +        while (outerJoinPath.hasNext())
  +        {
  +            String path = (String) outerJoinPath.next();
  +            if (aQuery.isPathOuterJoin(path))
  +            {
  +                countQuery.setPathOuterJoin(path);
  +            }
  +        }     
  +        
           return countQuery;
       }
   
  
  
  
  1.54      +52 -0     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.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- QueryTest.java	12 Mar 2004 20:31:54 -0000	1.53
  +++ QueryTest.java	31 Mar 2004 19:16:09 -0000	1.54
  @@ -1370,4 +1370,56 @@
           assertNotNull(result);
           assertTrue(result.size() == 5); // bob, tom, cindy, albert ,betrand
       }
  +    
  +    public void testQueryCommutative12() throws Exception
  +    {
  +        Collection result;
  +        Criteria crit1 = new Criteria();
  +        crit1.addEqualTo("articleName", "Hamlet");
  +        crit1.addEqualTo("productGroup.description", "Strange Books...");
  +
  +        Criteria crit2 = new Criteria();
  +        crit2.addEqualTo("stock", new Integer(32));
  +
  +        Criteria crit3 = new Criteria();
  +        crit3.addEqualTo("stock", new Integer(42));
  +
  +        crit2.addOrCriteria(crit3);
  +        crit1.addAndCriteria(crit2);
  +        QueryByCriteria qry12 = QueryFactory.newQuery(Article.class, crit1);
  +        qry12.setPathOuterJoin("productGroup");
  +
  +        result = broker.getCollectionByQuery(qry12);
  +        assertNotNull(result);
  +        
  +        int count = broker.getCount(qry12);
  +        assertEquals(count, result.size());
  +    }
  +    
  +    
  +    public void testQueryCommutative21()
  +    {
  +        Collection result;
  +        Criteria crit1 = new Criteria();
  +        crit1.addEqualTo("articleName", "Hamlet");
  +        crit1.addEqualTo("productGroup.description", "Strange Books...");
  +
  +        Criteria crit2 = new Criteria();
  +        crit2.addEqualTo("stock", new Integer(32));
  +
  +        Criteria crit3 = new Criteria();
  +        crit3.addEqualTo("stock", new Integer(42));
  +        
  +        crit2.addOrCriteria(crit3);
  +        crit2.addAndCriteria(crit1);
  +        QueryByCriteria qry21 = QueryFactory.newQuery(Article.class, crit2);
  +        qry21.setPathOuterJoin("productGroup");
  +
  +        result = broker.getCollectionByQuery(qry21);
  +        assertNotNull(result);
  +
  +        int count = broker.getCount(qry21);
  +        assertEquals(count, result.size());
  +    }
  +
   }
  
  
  

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