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, 28 Jul 2004 18:10:18 GMT
brj         2004/07/28 11:10:18

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlQueryStatement.java
               src/test/org/apache/ojb/broker QueryTest.java
  Log:
  do not generate sql for empty criteria
  
  Revision  Changes    Path
  1.80      +11 -9     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.79
  retrieving revision 1.80
  diff -u -r1.79 -r1.80
  --- SqlQueryStatement.java	24 Jul 2004 19:43:47 -0000	1.79
  +++ SqlQueryStatement.java	28 Jul 2004 18:10:18 -0000	1.80
  @@ -616,20 +616,22 @@
               Object o = e.nextElement();
               if (o instanceof Criteria)
               {
  -                String addAtStart;
  -                String addAtEnd;
                   Criteria pc = (Criteria) o;
  +                
  +                if (pc.isEmpty())
  +                {
  +                    continue;	//skip empty criteria
  +                }
  +                
  +                String addAtStart = "";
  +                String addAtEnd = "";
  +
                   // need to add parenthesises?
                   if (pc.isEmbraced())
                   {
                       addAtStart = " (";
                       addAtEnd = ")";
  -                }
  -                else
  -                {
  -                    addAtStart = "";
  -                    addAtEnd = "";
  -                }
  +                }    
   
                   switch (pc.getType())
                   {
  
  
  
  1.69      +43 -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.68
  retrieving revision 1.69
  diff -u -r1.68 -r1.69
  --- QueryTest.java	24 Jul 2004 19:43:47 -0000	1.68
  +++ QueryTest.java	28 Jul 2004 18:10:18 -0000	1.69
  @@ -374,7 +374,6 @@
   	 */
       public void testNullCriteria()
       {
  -
           Criteria crit = new Criteria();
           crit.addIsNull("firstname");
           Query q = QueryFactory.newQuery(Person.class, crit);
  @@ -382,7 +381,50 @@
           Collection results = broker.getCollectionByQuery(q);
           assertNotNull(results);
           assertTrue(results.size() == 0);
  +    }
  +
  +    /**
  +     * Add an empty criteria 
  +     */
  +    public void testEmptyORed() throws Exception
  +    {
  +        Collection result;
  +        Criteria crit1 = new Criteria();
  +        crit1.addEqualTo("articleName", "Hamlet");
  +        crit1.addEqualTo("productGroup.description", "Strange Books...");
  +
  +        Criteria crit2 = new Criteria();
  +
  +        crit1.addOrCriteria(crit2);
  +        QueryByCriteria q = QueryFactory.newQuery(Article.class, crit1);
  +
  +        result = broker.getCollectionByQuery(q);
  +        assertNotNull(result);
  +
  +        int count = broker.getCount(q);
  +        assertEquals(count, result.size());
  +    }
  +
  +    /**
  +     * Add an empty criteria 
  +     */
  +    public void testEmptyANDed() throws Exception
  +    {
  +        Collection result;
  +        Criteria crit1 = new Criteria();
  +        crit1.addEqualTo("articleName", "Hamlet");
  +        crit1.addEqualTo("productGroup.description", "Strange Books...");
  +
  +        Criteria crit2 = new Criteria();
  +
  +        crit1.addAndCriteria(crit2);
  +        QueryByCriteria q = QueryFactory.newQuery(Article.class, crit1);
  +
  +        result = broker.getCollectionByQuery(q);
  +        assertNotNull(result);
   
  +        int count = broker.getCount(q);
  +        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