You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by br...@apache.org on 2005/01/10 21:46:46 UTC

cvs commit: db-ojb/src/test/org/apache/ojb/broker QueryTest.java

brj         2005/01/10 12:46:46

  Modified:    src/java/org/apache/ojb/broker/query InCriteria.java
               src/test/org/apache/ojb/broker QueryTest.java
  Log:
  fixed problem with negated InCriteria
  
  Revision  Changes    Path
  1.15      +6 -33     db-ojb/src/java/org/apache/ojb/broker/query/InCriteria.java
  
  Index: InCriteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/InCriteria.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- InCriteria.java	2 Dec 2004 21:37:46 -0000	1.14
  +++ InCriteria.java	10 Jan 2005 20:46:46 -0000	1.15
  @@ -88,17 +88,10 @@
       private InCriterion buildInCriterion(Collection values)
       {
           InCriterion crit;
  -        
  -        if (isNegative())
  -        {
  -			crit = ValueCriteria.buildNotInCriteria(m_attribute, values);
  -        }
  -        else
  -        {
  -			crit = ValueCriteria.buildInCriteria(m_attribute, values);
  -        }
  -        
  +
  +        crit = ValueCriteria.buildInCriteria(m_attribute, values);
           crit.setTranslateAttribute(m_translateAttribute);
  +        
           return crit;
       }
   
  @@ -112,7 +105,7 @@
           List result = new ArrayList();
           Collection inCollection = new ArrayList();
           int inLimit = aPb.getSqlInLimit();
  -
  +       
           if (m_values == null || m_values.isEmpty())
           {
               // OQL creates empty Criteria for late binding
  @@ -153,19 +146,6 @@
           }
       }
   
  -    private void buildNotInCriteria(PersistenceBrokerInternal aPb)
  -    {
  -        List list = buildList(aPb);
  -        int index = 0;
  -        InCriterion inCrit;
  -
  -        for (index = 0; index < list.size(); index++)
  -        {
  -            inCrit = (InCriterion) list.get(index);
  -            addSelectionCriteria(inCrit);
  -        }
  -    }
  -
       /**
        * Preprocess the Criteria using a PersistenceBroker.
        * Build list of InCriterion based on SQL-IN-LIMIT.
  @@ -176,14 +156,7 @@
       {
           if (!m_preprocessed)
           {
  -            if (isNegative())
  -            {
  -                buildNotInCriteria(aPb);
  -            }
  -            else
  -            {
  -                buildInCriteria(aPb);
  -            }
  +            buildInCriteria(aPb);
               m_preprocessed = true;
           }
       }
  
  
  
  1.77      +27 -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.76
  retrieving revision 1.77
  diff -u -r1.76 -r1.77
  --- QueryTest.java	18 Dec 2004 14:01:16 -0000	1.76
  +++ QueryTest.java	10 Jan 2005 20:46:46 -0000	1.77
  @@ -729,7 +729,6 @@
        */
       public void testInCriteria()
       {
  -
           Criteria crit = new Criteria();
           Collection ids = new Vector();
           ids.add(new Integer(1));
  @@ -737,11 +736,37 @@
           ids.add(new Integer(5));
   
           crit.addIn("id", ids);
  -        Query q = QueryFactory.newQuery(Person.class, crit);
  +        QueryByCriteria q = QueryFactory.newQuery(Person.class, crit);
  +        q.addOrderByAscending("id");
   
           Collection results = broker.getCollectionByQuery(q);
           assertNotNull(results);
           assertTrue(results.size() == 3);
  +
  +        // compare with count
  +        int count = broker.getCount(q);
  +        assertEquals(results.size(), count);
  +    }
  +
  +    /**
  +     * test Not In Criteria
  +     */
  +    public void testNotInCriteria()
  +    {
  +        Criteria crit = new Criteria();
  +        Collection ids = new Vector();
  +        ids.add(new Integer(1));
  +        ids.add(new Integer(3));
  +        ids.add(new Integer(5));
  +
  +        crit.addNotIn("id", ids);
  +        crit.addLessOrEqualThan("id", new Integer(10));
  +        QueryByCriteria q = QueryFactory.newQuery(Person.class, crit);
  +        q.addOrderByAscending("id");
  +
  +        Collection results = broker.getCollectionByQuery(q);
  +        assertNotNull(results);
  +        assertTrue(results.size() == 7);
   
           // 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