dobbs       02/04/29 10:53:30

  Modified:    src/java/org/apache/torque/util Criteria.java
  Log:
  applying a patch from Sam Joseph <gaijinATyha.att.ne.jp> that
  fixes the precidence problem in Criterion
  
  Revision  Changes    Path
  1.21      +68 -80    
jakarta-turbine-torque/src/java/org/apache/torque/util/Criteria.java
  
  Index: Criteria.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/util/Criteria.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- Criteria.java     10 Apr 2002 19:41:54 -0000      1.20
  +++ Criteria.java     29 Apr 2002 17:53:30 -0000      1.21
  @@ -92,7 +92,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Brett McLaughlin</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Eric Dobbs</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Henning P. Schmiedehausen</a>
  - * @version $Id: Criteria.java,v 1.20 2002/04/10 19:41:54 dlr Exp $
  + * @version $Id: Criteria.java,v 1.21 2002/04/29 17:53:30 dobbs Exp $
    */
   public class Criteria extends Hashtable
   {
  @@ -3231,15 +3231,11 @@
           private DB db;
   
           /**
  -         * Another Criterion connected to this one by an OR clause.
  +         * other connected criteria and their conjunctions.
            */
  -        private Criterion or;
  -
  -        /**
  -         * Another criterion connected to this one by an AND clause.
  -         */
  -        private Criterion and;
  -
  +        private List clauses = new ArrayList(); 
  +        private List conjunctions = new ArrayList(); 
  +        
           /**
            * Creates a new instance, initializing a couple members.
            */
  @@ -3412,13 +3408,10 @@
           public void setDB(DB  v)
           {
               this.db = v;
  -            if ( and != null )
  -            {
  -                and.setDB(v);
  -            }
  -            if ( or != null )
  +            
  +            for(int i=0;i<this.clauses.size();i++)
               {
  -                or.setDB(v);
  +              ((Criterion)(clauses.get(i))).setDB(v);
               }
           }
   
  @@ -3445,50 +3438,38 @@
            }
   
           /**
  -         *  get the criterion from this Criterion's AND field.
  +         *  get the list of clauses in this Criterion
            */
  -        public Criterion getAnd()
  +        private List getClauses()
           {
  -            return and;
  +            return clauses;
           }
   
           /**
  -         * Append a Criteria onto this Criteria's AND field.
  +         *  get the list of conjunctions in this Criterion
            */
  -        public Criterion and(Criterion criterion)
  +        private List getConjunctions()
           {
  -            if (this.and == null)
  -            {
  -                this.and = criterion;
  -            }
  -            else
  -            {
  -                this.and.and(criterion);
  -            }
  -            return this;
  +            return conjunctions;
           }
   
           /**
  -         *  get the criterion from this Criterion's AND field.
  +         * Append an AND Criterion onto this Criterion's list.
            */
  -        public Criterion getOr()
  +        public Criterion and(Criterion criterion)
           {
  -            return or;
  +            this.clauses.add(criterion);
  +            this.conjunctions.add(AND);
  +            return this;
           }
   
           /**
  -         * Append a Criterion onto this Criterion's OR field.
  +         * Append an OR Criterion onto this Criterion's list.
            */
           public Criterion or(Criterion criterion)
           {
  -            if (this.or == null)
  -            {
  -                this.or = criterion;
  -            }
  -            else
  -            {
  -                this.or.or(criterion);
  -            }
  +            this.clauses.add(criterion);
  +            this.conjunctions.add(OR);
               return this;
           }
   
  @@ -3506,7 +3487,9 @@
                   return;
               }
   
  -            sb.append('(');
  +            Criterion clause = null;
  +            for(int j=0;j<this.clauses.size();j++)
  +              sb.append('(');
               if ( CUSTOM == comparison )
               {
                   if ( value != null && ! "".equals(value) )
  @@ -3532,18 +3515,13 @@
                                       ignoreStringCase, getDb(), sb);
               }
   
  -            if (or != null)
  +            for(int i=0;i<this.clauses.size();i++)
               {
  -                sb.append(OR);
  -                or.appendTo(sb);
  +                sb.append(this.conjunctions.get(i));
  +                clause = (Criterion)(this.clauses.get(i));
  +                clause.appendTo(sb);
  +                sb.append(')');
               }
  -
  -            if (and != null)
  -            {
  -                sb.append(AND);
  -                and.appendTo(sb);
  -            }
  -            sb.append(')');
           }
   
           /**
  @@ -3563,7 +3541,8 @@
   
               DB db = getDb();
   
  -            sb.append('(');
  +            for(int j=0;j<this.clauses.size();j++)
  +              sb.append('(');
               if ( CUSTOM == comparison )
               {
                   if ( !"".equals(value) )
  @@ -3640,18 +3619,13 @@
                   }
               }
   
  -            if (or != null)
  -            {
  -                sb.append(OR);
  -                or.appendPsTo(sb,params);
  -            }
  -
  -            if (and != null)
  +            for(int i=0;i<this.clauses.size();i++)
               {
  -                sb.append(AND);
  -                and.appendPsTo(sb,params);
  +                sb.append(this.conjunctions.get(i));
  +                Criterion clause = (Criterion)(this.clauses.get(i));
  +                clause.appendPsTo(sb,params);
  +                sb.append(')');
               }
  -            sb.append(')');
           }
   
           /**
  @@ -3717,12 +3691,16 @@
               }
   
               // check chained criterion
  -            isEquiv &= (and == null && crit.getAnd() == null )
  -                || (and != null && and.equals(crit.getAnd()));
  -
  -            isEquiv &= (or == null && crit.getOr() == null )
  -                || (or != null && or.equals(crit.getOr()));
  -
  +            
  +            isEquiv &= this.clauses.size() == crit.getClauses().size();
  +            for(int i=0;i<this.clauses.size();i++)
  +            {
  +              isEquiv &=  ((String)(conjunctions.get(i)))
  +                  .equals((String)(crit.getConjunctions().get(i))); 
  +              isEquiv &=  ((Criterion)(clauses.get(i)))
  +                  .equals((Criterion)(crit.getClauses().get(i))); 
  +            }
  +                
               return isEquiv;
           }
   
  @@ -3743,19 +3721,17 @@
                   h ^= column.hashCode();
               }
   
  -            if (and != null)
  -            {
  -                h ^= and.hashCode();
  -            }
  -
  -            if (or != null)
  +            for(int i=0;i<this.clauses.size();i++)
               {
  -                h ^= or.hashCode();
  +                h ^= ((Criterion)(clauses.get(i))).hashCode();
               }
   
               return h;
           }
   
  +        /**
  +         * get all tables from nested criterion objects
  +         */
           public String[] getAllTables()
           {
               StringStack tables = new StringStack();
  @@ -3763,16 +3739,24 @@
               return tables.toStringArray();
           }
   
  +        /**
  +         * method supporting recursion through all criterions to give
  +         * us a StringStack of tables from each criterion
  +         */
           private void addCriterionTable(Criterion c, StringStack s)
           {
               if ( c != null )
               {
                   s.add(c.getTable());
  -                addCriterionTable(c.getAnd(), s);
  -                addCriterionTable(c.getOr(), s);
  +                for(int i=0;i<c.getClauses().size();i++)
  +                  addCriterionTable((Criterion)(c.getClauses().get(i)), s);
               }
           }
   
  +        /**
  +         * get an array of all criterion attached to this
  +         * recursing through all sub criterion
  +         */
           public Criterion[] getAttachedCriterion()
           {
               ArrayList crits = new ArrayList();
  @@ -3786,13 +3770,17 @@
               return crita;
           }
   
  +        /**
  +         * method supporting recursion through all criterions to give
  +         * us an ArrayList of them
  +         */
           private void traverseCriterion(Criterion c, ArrayList a)
           {
               if ( c != null )
               {
                   a.add(c);
  -                traverseCriterion(c.getAnd(), a);
  -                traverseCriterion(c.getOr(), a);
  +                for(int i=0;i<c.getClauses().size();i++)
  +                  traverseCriterion((Criterion)(c.getClauses().get(i)), a);
               }
           }
       }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to