db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jakob Braeuchi <jbraeu...@gmx.ch>
Subject Re: query Criteria: per path-segment alias
Date Sat, 29 May 2004 17:25:11 GMT
hi phil,

we now have user alias and hint classes per path-segment. another thing that may 
come up is the use of outer joins per path-segment. i think we should therefore 
internally model the pathSegment instead of having different maps with different 
meanings. the api of criteria could remain the same except that we shouls also 
provide setPathOuterJoin on criteria level.

what do you think about it?

jakob

Phil Warrick wrote:

> Hi Jakob,
> 
> I've got this working now so that for a given criteria, you can specify 
> which path segments participate in the alias (patches below).  So you 
> can do the following type of query (from PathTest.java):
> 
> ---------------------------------------------------
> /*
>  *  Find all As having a B with both a particular C-D combination and
>  *  another particular C-D combination
>  */
> 
> // d1 criteria
> Criteria crit1 = new Criteria();
> crit1.setAlias("bToCToD1", "cSet.d");
> crit1.addEqualTo("bSet.cSet.d.dAttrib", new Integer("10010"));
> 
> // d2 criteria
> Criteria crit2 = new Criteria();
> crit2.setAlias("bToCToD2", "cSet.d");
> crit2.addEqualTo("bSet.cSet.d.dAttrib", new Integer("10110"));
> 
> crit1.addAndCriteria(crit2);
> 
> Query query = new QueryByCriteria(A.class, crit1);
> ---------------------------------------------------
> 
> In the past, all segments (including bSet) participated in the alias. So 
> this provides a bit more flexibility.
> 
> If there is ambiguity in specifying the segments, a new class UserAlias 
> can be used explicitly (it is now always used internally).  Ambiguity 
> can occur if there are cycles in the path (e.g. bSet.cSet in 
> allAs.bSet.cSet.bSet.cSet).  The following is equivalent to the previous 
> example (note that there is no ambiguity in this case):
> 
> ---------------------------------------------------
> UserAlias userAlias1 = new UserAlias("alias1");
> userAlias1.add("bSet.cSet");
> userAlias1.add("bSet.cSet.d");
> 
> // d1 criteria
> Criteria crit1 = new Criteria();
> crit1.setAlias(userAlias1);
> crit1.addEqualTo("bSet.cSet.d.dAttrib", new Integer("10010"));
> 
> // d2 criteria
> UserAlias userAlias2 = new UserAlias("alias2");
> userAlias1.add("bSet.cSet");
> userAlias1.add("bSet.cSet.d");
> 
> Criteria crit2 = new Criteria();
> crit2.setAlias(userAlias2);
> crit2.addEqualTo("bSet.cSet.d.dAttrib", new Integer("10110"));
> 
> crit1.addAndCriteria(crit2);
> 
> Query query = new QueryByCriteria(A.class, crit1);
> ---------------------------------------------------
> 
> With the patches below applied to the head, junit test ran successfully.
> 
> Phil
> 
> 
> 
> Index: BetweenCriteria.java
> ===================================================================
> RCS file: 
> /home/cvspublic/jakarta-ojb/src/java/org/apache/ojb/broker/query/BetweenCriteria.java,v 
> 
> retrieving revision 1.9
> diff -u -r1.9 BetweenCriteria.java
> --- BetweenCriteria.java    24 Apr 2004 08:25:37 -0000    1.9
> +++ BetweenCriteria.java    17 May 2004 05:00:22 -0000
> @@ -25,12 +25,19 @@
>  public class BetweenCriteria extends ValueCriteria
>  {
>      private Object value2;
> +   
> +    BetweenCriteria(Object anAttribute, Object aValue1, Object aValue2, 
> String aClause, String anAlias)
> +    {
> +        super(anAttribute, aValue1, aClause, anAlias);
> +        setValue2(aValue2);
> +    }
> 
> -    BetweenCriteria(Object anAttribute, Object aValue1, Object aValue2, 
> String aClause, String anAlias)
> -    {
> -        super(anAttribute, aValue1, aClause, anAlias);
> -        setValue2(aValue2);
> -    }
> +    // PAW
> +    BetweenCriteria(Object anAttribute, Object aValue1, Object aValue2, 
> String aClause, UserAlias aUserAlias)
> +    {
> +        super(anAttribute, aValue1, aClause, aUserAlias);
> +        setValue2(aValue2);
> +    }
> 
>      /**
>       * sets the value of the criteria to newValue.
> Index: Criteria.java
> ===================================================================
> RCS file: 
> /home/cvspublic/jakarta-ojb/src/java/org/apache/ojb/broker/query/Criteria.java,v 
> 
> retrieving revision 1.44
> diff -u -r1.44 Criteria.java
> --- Criteria.java    24 Apr 2004 08:25:37 -0000    1.44
> +++ Criteria.java    17 May 2004 05:00:25 -0000
> @@ -69,10 +69,17 @@
>      private List groupby = null;
>      private List prefetchedRelationships = null;
> 
> -    // an optional alias to be used for this criteria
> -    private String m_alias = null;
> +    // an optional alias to be used for this criteria
> +    private String m_alias = null;
> 
> -    /** the max. number of parameters in a IN-statement */
> +    // PAW
> +    // an aliasPath to be used for this criteria
> +    private String m_aliasPath = null;
> +
> +    // holds the path segment(s) to which the alias applies
> +    private UserAlias m_userAlias = null;
> +   
> +    /** the max. number of parameters in a IN-statement */
>      protected static final int IN_LIMIT = getSqlInLimit();
> 
>      private QueryByCriteria m_query;
> @@ -207,11 +214,15 @@
>      {
>          if (negative)
>          {
> -            return ValueCriteria.buildNotInCriteria(attribute, values, 
> getAlias());
> +            // PAW
> +            // return ValueCriteria.buildNotInCriteria(attribute, 
> values, getAlias());
> +            return ValueCriteria.buildNotInCriteria(attribute, values, 
> getUserAlias(attribute));
>          }
>          else
>          {
> -            return ValueCriteria.buildInCriteria(attribute, values, 
> getAlias());
> +            // PAW
> +            // return ValueCriteria.buildInCriteria(attribute, values, 
> getAlias());
> +            return ValueCriteria.buildInCriteria(attribute, values, 
> getUserAlias(attribute));
>          }
>      }
> 
> @@ -278,7 +289,9 @@
>       */
>      public void addEqualTo(String attribute, Object value)
>      {
> - addSelectionCriteria(ValueCriteria.buildEqualToCriteria(attribute, 
> value, getAlias()));
> +        // PAW
> +//        
> addSelectionCriteria(ValueCriteria.buildEqualToCriteria(attribute, 
> value, getAlias()));
> +        
> addSelectionCriteria(ValueCriteria.buildEqualToCriteria(attribute, 
> value, getUserAlias(attribute)));
>      }
> 
>      /**
> @@ -291,7 +304,9 @@
>       */
>      public void addColumnEqualTo(String column, Object value)
>      {
> -        SelectionCriteria c = 
> ValueCriteria.buildEqualToCriteria(column, value, getAlias());
> +        // PAW
> +//        SelectionCriteria c = 
> ValueCriteria.buildEqualToCriteria(column, value, getAlias());
> +        SelectionCriteria c = 
> ValueCriteria.buildEqualToCriteria(column, value, getUserAlias(column));
>          c.setTranslateAttribute(false);
>          addSelectionCriteria(c);
>      }
> @@ -306,7 +321,9 @@
>       */
>      public void addColumnEqualToField(String column, Object fieldName)
>      {
> -        SelectionCriteria c = 
> FieldCriteria.buildEqualToCriteria(column, fieldName, getAlias());
> +        // PAW
> +        //SelectionCriteria c = 
> FieldCriteria.buildEqualToCriteria(column, fieldName, getAlias());
> +        SelectionCriteria c = 
> FieldCriteria.buildEqualToCriteria(column, fieldName, 
> getUserAlias(column));
>          c.setTranslateAttribute(false);
>          addSelectionCriteria(c);
>      }
> @@ -322,7 +339,9 @@
>       */
>      public void addEqualToField(String attribute, String fieldName)
>      {
> -        FieldCriteria c = FieldCriteria.buildEqualToCriteria(attribute, 
> fieldName, getAlias());
> +        // PAW
> +        // FieldCriteria c = 
> FieldCriteria.buildEqualToCriteria(attribute, fieldName, getAlias());
> +        FieldCriteria c = FieldCriteria.buildEqualToCriteria(attribute, 
> fieldName, getUserAlias(attribute));
>          addSelectionCriteria(c);
>      }
> 
> @@ -337,7 +356,9 @@
>       */
>      public void addNotEqualToField(String attribute, String fieldName)
>      {
> -        SelectionCriteria c = 
> FieldCriteria.buildNotEqualToCriteria(attribute, fieldName, getAlias());
> +        // PAW
> +        // SelectionCriteria c = 
> FieldCriteria.buildNotEqualToCriteria(attribute, fieldName, getAlias());
> +        SelectionCriteria c = 
> FieldCriteria.buildNotEqualToCriteria(attribute, fieldName, 
> getUserAlias(attribute));
>          addSelectionCriteria(c);
>      }
> 
> @@ -352,7 +373,9 @@
>       */
>      public void addNotEqualToColumn(String attribute, String colName)
>      {
> -        FieldCriteria c = 
> FieldCriteria.buildNotEqualToCriteria(attribute, colName, getAlias());
> +        // PAW
> +        // FieldCriteria c = 
> FieldCriteria.buildNotEqualToCriteria(attribute, colName, getAlias());
> +        FieldCriteria c = 
> FieldCriteria.buildNotEqualToCriteria(attribute, colName, 
> getUserAlias(attribute));
>          c.setTranslateField(false);
>          addSelectionCriteria(c);
>      }
> @@ -368,7 +391,8 @@
>       */
>      public void addEqualToColumn(String attribute, String colName)
>      {
> -        FieldCriteria c = FieldCriteria.buildEqualToCriteria(attribute, 
> colName, getAlias());
> +        // FieldCriteria c = 
> FieldCriteria.buildEqualToCriteria(attribute, colName, getAlias());
> +        FieldCriteria c = FieldCriteria.buildEqualToCriteria(attribute, 
> colName, getUserAlias(attribute));
>          c.setTranslateField(false);
>          addSelectionCriteria(c);
>      }
> @@ -382,7 +406,9 @@
>       */
>      public void addGreaterOrEqualThan(Object attribute, Object value)
>      {
> - addSelectionCriteria(ValueCriteria.buildNotLessCriteria(attribute, 
> value, getAlias()));
> +        // PAW
> +        // 
> addSelectionCriteria(ValueCriteria.buildNotLessCriteria(attribute, 
> value, getAlias()));
> +        
> addSelectionCriteria(ValueCriteria.buildNotLessCriteria(attribute, 
> value, getUserAlias(attribute)));
>      }
> 
>      /**
> @@ -394,7 +420,9 @@
>       */
>      public void addGreaterOrEqualThanField(String attribute, Object value)
>      {
> - addSelectionCriteria(FieldCriteria.buildNotLessCriteria(attribute, 
> value, getAlias()));
> +        // PAW
> +        // 
> addSelectionCriteria(FieldCriteria.buildNotLessCriteria(attribute, 
> value, getAlias()));
> +        
> addSelectionCriteria(FieldCriteria.buildNotLessCriteria(attribute, 
> value, getUserAlias(attribute)));
>      }
> 
>      /**
> @@ -406,7 +434,9 @@
>       */
>      public void addLessOrEqualThan(Object attribute, Object value)
>      {
> - addSelectionCriteria(ValueCriteria.buildNotGreaterCriteria(attribute, 
> value, getAlias()));
> +        // PAW
> +        // 
> addSelectionCriteria(ValueCriteria.buildNotGreaterCriteria(attribute, 
> value, getAlias()));
> +        
> addSelectionCriteria(ValueCriteria.buildNotGreaterCriteria(attribute, 
> value, getUserAlias(attribute)));
>      }
> 
>      /**
> @@ -418,7 +448,9 @@
>       */
>      public void addLessOrEqualThanField(String attribute, Object value)
>      {
> - addSelectionCriteria(FieldCriteria.buildNotGreaterCriteria(attribute, 
> value, getAlias()));
> +        // PAW
> +        // 
> addSelectionCriteria(FieldCriteria.buildNotGreaterCriteria(attribute, 
> value, getAlias()));
> +        
> addSelectionCriteria(FieldCriteria.buildNotGreaterCriteria(attribute, 
> value, getUserAlias(attribute)));
>      }
> 
>      /**
> @@ -431,7 +463,9 @@
>       */
>      public void addLike(Object attribute, Object value)
>      {
> -        addSelectionCriteria(ValueCriteria.buildLikeCriteria(attribute, 
> value, getAlias()));
> +        // PAW
> +        // 
> addSelectionCriteria(ValueCriteria.buildLikeCriteria(attribute, value, 
> getAlias()));
> +        addSelectionCriteria(ValueCriteria.buildLikeCriteria(attribute, 
> value, getUserAlias(attribute)));
>      }
> 
>      /**
> @@ -444,7 +478,9 @@
>       */
>      public void addNotLike(String attribute, Object value)
>      {
> - addSelectionCriteria(ValueCriteria.buildNotLikeCriteria(attribute, 
> value, getAlias()));
> +        // PAW
> +        // 
> addSelectionCriteria(ValueCriteria.buildNotLikeCriteria(attribute, 
> value, getAlias()));
> +        
> addSelectionCriteria(ValueCriteria.buildNotLikeCriteria(attribute, 
> value, getUserAlias(attribute)));
>      }
> 
>      /**
> @@ -456,7 +492,9 @@
>       */
>      public void addNotEqualTo(Object attribute, Object value)
>      {
> - addSelectionCriteria(ValueCriteria.buildNotEqualToCriteria(attribute, 
> value, getAlias()));
> +        // PAW
> +        // 
> addSelectionCriteria(ValueCriteria.buildNotEqualToCriteria(attribute, 
> value, getAlias()));
> +        
> addSelectionCriteria(ValueCriteria.buildNotEqualToCriteria(attribute, 
> value, getUserAlias(attribute)));
>      }
> 
>      /**
> @@ -468,7 +506,9 @@
>       */
>      public void addGreaterThan(Object attribute, Object value)
>      {
> - addSelectionCriteria(ValueCriteria.buildGreaterCriteria(attribute, 
> value, getAlias()));
> +        // PAW
> +        // 
> addSelectionCriteria(ValueCriteria.buildGreaterCriteria(attribute, 
> value, getAlias()));
> +        
> addSelectionCriteria(ValueCriteria.buildGreaterCriteria(attribute, 
> value, getUserAlias(attribute)));
>      }
> 
>      /**
> @@ -480,7 +520,9 @@
>       */
>      public void addGreaterThanField(String attribute, Object value)
>      {
> - addSelectionCriteria(FieldCriteria.buildGreaterCriteria(attribute, 
> value, getAlias()));
> +        // PAW
> +        // 
> addSelectionCriteria(FieldCriteria.buildGreaterCriteria(attribute, 
> value, getAlias()));
> +        
> addSelectionCriteria(FieldCriteria.buildGreaterCriteria(attribute, 
> value, getUserAlias(attribute)));
>      }
> 
>      /**
> @@ -492,7 +534,9 @@
>       */
>      public void addLessThan(Object attribute, Object value)
>      {
> -        addSelectionCriteria(ValueCriteria.buildLessCriteria(attribute, 
> value, getAlias()));
> +        // PAW
> +        // 
> addSelectionCriteria(ValueCriteria.buildLessCriteria(attribute, value, 
> getAlias()));
> +        addSelectionCriteria(ValueCriteria.buildLessCriteria(attribute, 
> value, getUserAlias(attribute)));
>      }
> 
>      /**
> @@ -504,7 +548,9 @@
>       */
>      public void addLessThanField(String attribute, Object value)
>      {
> -        addSelectionCriteria(FieldCriteria.buildLessCriteria(attribute, 
> value, getAlias()));
> +        // PAW
> +        // 
> addSelectionCriteria(FieldCriteria.buildLessCriteria(attribute, value, 
> getAlias()));
> +        addSelectionCriteria(FieldCriteria.buildLessCriteria(attribute, 
> value, getUserAlias(attribute)));
>      }
> 
>      /**
> @@ -628,7 +674,9 @@
>       */
>      public void addIsNull(String attribute)
>      {
> -        addSelectionCriteria(ValueCriteria.buildNullCriteria(attribute, 
> getAlias()));
> +        // PAW
> +        
> //addSelectionCriteria(ValueCriteria.buildNullCriteria(attribute, 
> getAlias()));
> +        addSelectionCriteria(ValueCriteria.buildNullCriteria(attribute, 
> getUserAlias(attribute)));
>      }
> 
>      /**
> @@ -640,7 +688,9 @@
>       */
>      public void addColumnIsNull(String column)
>      {
> -        SelectionCriteria c = ValueCriteria.buildNullCriteria(column, 
> getAlias());
> +        // PAW
> +        //SelectionCriteria c = ValueCriteria.buildNullCriteria(column, 
> getAlias());
> +        SelectionCriteria c = ValueCriteria.buildNullCriteria(column, 
> getUserAlias(column));
>          c.setTranslateAttribute(false);
>          addSelectionCriteria(c);
>      }
> @@ -653,7 +703,9 @@
>       */
>      public void addNotNull(String attribute)
>      {
> - addSelectionCriteria(ValueCriteria.buildNotNullCriteria(attribute, 
> getAlias()));
> +        // PAW
> +        
> //addSelectionCriteria(ValueCriteria.buildNotNullCriteria(attribute, 
> getAlias()));
> +        
> addSelectionCriteria(ValueCriteria.buildNotNullCriteria(attribute, 
> getUserAlias(attribute)));
>      }
> 
>      /**
> @@ -665,7 +717,9 @@
>       */
>      public void addColumnNotNull(String column)
>      {
> -        SelectionCriteria c = 
> ValueCriteria.buildNotNullCriteria(column, getAlias());
> +        // PAW
> +        // SelectionCriteria c = 
> ValueCriteria.buildNotNullCriteria(column, getAlias());
> +        SelectionCriteria c = 
> ValueCriteria.buildNotNullCriteria(column, getUserAlias(column));
>          c.setTranslateAttribute(false);
>          addSelectionCriteria(c);
>      }
> @@ -680,7 +734,9 @@
>       */
>      public void addBetween(Object attribute, Object value1, Object value2)
>      {
> - addSelectionCriteria(ValueCriteria.buildBeweenCriteria(attribute, 
> value1, value2, getAlias()));
> +        // PAW
> +        // 
> addSelectionCriteria(ValueCriteria.buildBeweenCriteria(attribute, 
> value1, value2, getAlias()));
> +        
> addSelectionCriteria(ValueCriteria.buildBeweenCriteria(attribute, 
> value1, value2, getUserAlias(attribute)));
>      }
> 
>      /**
> @@ -693,7 +749,9 @@
>       */
>      public void addNotBetween(Object attribute, Object value1, Object 
> value2)
>      {
> - addSelectionCriteria(ValueCriteria.buildNotBeweenCriteria(attribute, 
> value1, value2, getAlias()));
> +        // PAW
> +        // 
> addSelectionCriteria(ValueCriteria.buildNotBeweenCriteria(attribute, 
> value1, value2, getAlias()));
> +        
> addSelectionCriteria(ValueCriteria.buildNotBeweenCriteria(attribute, 
> value1, value2, getUserAlias(attribute)));
>      }
> 
>      /**
> @@ -784,7 +842,9 @@
>       */
>      public void addIn(Object attribute, Query subQuery)
>      {
> -        addSelectionCriteria(ValueCriteria.buildInCriteria(attribute, 
> subQuery, getAlias()));
> +        // PAW
> +        // 
> addSelectionCriteria(ValueCriteria.buildInCriteria(attribute, subQuery, 
> getAlias()));
> +        addSelectionCriteria(ValueCriteria.buildInCriteria(attribute, 
> subQuery, getUserAlias(attribute)));
>      }
> 
>      /**
> @@ -794,7 +854,9 @@
>       */
>      public void addNotIn(String attribute, Query subQuery)
>      {
> - addSelectionCriteria(ValueCriteria.buildNotInCriteria(attribute, 
> subQuery, getAlias()));
> +        // PAW
> +        // 
> addSelectionCriteria(ValueCriteria.buildNotInCriteria(attribute, 
> subQuery, getAlias()));
> +        
> addSelectionCriteria(ValueCriteria.buildNotInCriteria(attribute, 
> subQuery, getUserAlias(attribute)));
>      }
> 
>      /**
> @@ -969,38 +1031,124 @@
>          }
>      }
> 
> -    /**
> -     * @return String
> -     */
> -    public String getAlias()
> -    {
> -        return m_alias;
> -    }
> -
> -    /**
> -     * Sets the alias. Empty String is regarded as null.
> -     * @param alias The alias to set
> -     */
> -    public void setAlias(String alias)
> -    {
> -        if (alias == null || alias.trim().equals(""))
> -        {
> -            m_alias = null;
> -        }
> -        else
> -        {
> -            m_alias = alias;
> -        }
> +    /**
> +     * @return String
> +     */
> +    public String getAlias()
> +    {
> +        return m_alias;
> +    }
> +
> +    /**
> +     * @return String
> +     */
> +    // PAW
> +    public UserAlias getUserAlias()
> +    {
> +        return m_userAlias;
> +    }
> +   
> +    // PAW
> +    /**
> +     * Retrieves or if necessary, creates a user alias to be used
> +     * by a child criteria
> +     * @param userAlias The alias to set
> +     */
> +    private UserAlias getUserAlias(Object attribute)
> +    {
> +        if (m_userAlias != null)
> +        {
> +            return m_userAlias;
> +        }
> +        if (!(attribute instanceof String))
> +        {   
> +            return null;
> +        }
> +        if (m_alias == null)
> +        {
> +            return null;
> +        }
> +        if (m_aliasPath == null)
> +        {
> +            boolean allPathsAliased = true;
> +            return new UserAlias(m_alias, (String)attribute, 
> allPathsAliased);
> +        }
> +        return new UserAlias(m_alias, (String)attribute, m_aliasPath);
> +    }
> +
> +
> +    /**
> +     * Sets the alias. Empty String is regarded as null.
> +     * @param alias The alias to set
> +     */
> +    public void setAlias(String alias)
> +    {
> +        if (alias == null || alias.trim().equals(""))
> +        {
> +            m_alias = null;
> +        }
> +        else
> +        {
> +            m_alias = alias;
> +        }
> +
> +        // propagate to SelectionCriteria,not to Criteria
> +        for (int i = 0; i < m_criteria.size(); i++)
> +        {
> +            if (!(m_criteria.elementAt(i) instanceof Criteria))
> +            {
> +                ((SelectionCriteria) 
> m_criteria.elementAt(i)).setAlias(m_alias);
> +            }
> +        }
> +    }
> +
> +    // PAW
> +    /**
> +     * Sets the alias. Empty String is regarded as null.
> +     * @param alias The alias to set
> +     * @param aliasPath The path segment(s) to which the alias applies
> +     */
> +    public void setAlias(String alias, String aliasPath)
> +    {
> +        if (alias == null || alias.trim().equals(""))
> +        {
> +            m_alias = null;
> +        }
> +        else
> +        {
> +            m_alias = alias;
> +            m_aliasPath = aliasPath;
> +        }
> +
> +        // propagate to SelectionCriteria,not to Criteria
> +        for (int i = 0; i < m_criteria.size(); i++)
> +        {
> +            if (!(m_criteria.elementAt(i) instanceof Criteria))
> +            {
> +                ((SelectionCriteria) 
> m_criteria.elementAt(i)).setAlias(m_alias, aliasPath);
> +            }
> +        }
> +    }
> +
> +    // PAW
> +    /**
> +     * Sets the alias using a userAlias object.
> +     * @param userAlias The alias to set
> +     */
> +    public void setAlias(UserAlias userAlias)
> +    {
> +        m_alias = userAlias.getName();
> +
> +        // propagate to SelectionCriteria,not to Criteria
> +        for (int i = 0; i < m_criteria.size(); i++)
> +        {
> +            if (!(m_criteria.elementAt(i) instanceof Criteria))
> +            {
> +                ((SelectionCriteria) 
> m_criteria.elementAt(i)).setAlias(userAlias);
> +            }
> +        }
> +    }
> 
> -        // propagate to SelectionCriteria,not to Criteria
> -        for (int i = 0; i < m_criteria.size(); i++)
> -        {
> -            if (!(m_criteria.elementAt(i) instanceof Criteria))
> -            {
> -                ((SelectionCriteria) 
> m_criteria.elementAt(i)).setAlias(m_alias);
> -            }
> -        }
> -    }
> 
>      /**
>       * @return the query containing the criteria
> Index: FieldCriteria.java
> ===================================================================
> RCS file: 
> /home/cvspublic/jakarta-ojb/src/java/org/apache/ojb/broker/query/FieldCriteria.java,v 
> 
> retrieving revision 1.8
> diff -u -r1.8 FieldCriteria.java
> --- FieldCriteria.java    4 Apr 2004 23:53:36 -0000    1.8
> +++ FieldCriteria.java    17 May 2004 05:00:25 -0000
> @@ -23,32 +23,44 @@
>   */
>  public class FieldCriteria extends SelectionCriteria
>  {
> -    static FieldCriteria buildEqualToCriteria(Object anAttribute, 
> Object aValue, String anAlias)
> +    // PAW
> +//    static FieldCriteria buildEqualToCriteria(Object anAttribute, 
> Object aValue, String anAlias)
> +    static FieldCriteria buildEqualToCriteria(Object anAttribute, 
> Object aValue, UserAlias anAlias)
>      {
>          return new FieldCriteria(anAttribute, aValue, EQUAL, anAlias);
>      }
> 
> -    static FieldCriteria buildNotEqualToCriteria(Object anAttribute, 
> Object aValue, String anAlias)
> +    // PAW
> +//    static FieldCriteria buildNotEqualToCriteria(Object anAttribute, 
> Object aValue, String anAlias)
> +    static FieldCriteria buildNotEqualToCriteria(Object anAttribute, 
> Object aValue, UserAlias anAlias)
>      {
>          return new FieldCriteria(anAttribute, aValue, NOT_EQUAL, anAlias);
>      }
> 
> -    static FieldCriteria buildGreaterCriteria(Object anAttribute, 
> Object aValue, String anAlias)
> +    // PAW
> +//    static FieldCriteria buildGreaterCriteria(Object anAttribute, 
> Object aValue, String anAlias)
> +    static FieldCriteria buildGreaterCriteria(Object anAttribute, 
> Object aValue, UserAlias anAlias)
>      {
>          return new FieldCriteria(anAttribute, aValue,GREATER, anAlias);
>      }
> 
> -    static FieldCriteria buildNotGreaterCriteria(Object anAttribute, 
> Object aValue, String anAlias)
> +    // PAW
> +//    static FieldCriteria buildNotGreaterCriteria(Object anAttribute, 
> Object aValue, String anAlias)
> +    static FieldCriteria buildNotGreaterCriteria(Object anAttribute, 
> Object aValue, UserAlias anAlias)
>      {
>          return new FieldCriteria(anAttribute, aValue, NOT_GREATER, 
> anAlias);
>      }
> 
> -    static FieldCriteria buildLessCriteria(Object anAttribute, Object 
> aValue, String anAlias)
> +    // PAW
> +//    static FieldCriteria buildLessCriteria(Object anAttribute, Object 
> aValue, String anAlias)
> +    static FieldCriteria buildLessCriteria(Object anAttribute, Object 
> aValue, UserAlias anAlias)
>      {
>          return new FieldCriteria(anAttribute, aValue, LESS, anAlias);
>      }
> 
> -    static FieldCriteria buildNotLessCriteria(Object anAttribute, 
> Object aValue, String anAlias)
> +    // PAW
> +//    static FieldCriteria buildNotLessCriteria(Object anAttribute, 
> Object aValue, String anAlias)
> +    static FieldCriteria buildNotLessCriteria(Object anAttribute, 
> Object aValue, UserAlias anAlias)
>      {
>          return new FieldCriteria(anAttribute, aValue, NOT_LESS, anAlias);
>      }
> @@ -65,9 +77,11 @@
>       * @param negative  criteria is negated (ie NOT LIKE instead of LIKE)
>       * @param alias  use alias to link anAttribute to
>       */
> -    FieldCriteria(Object anAttribute, Object aValue, String aClause, 
> String alias)
> +    // PAW
> +//    FieldCriteria(Object anAttribute, Object aValue, String aClause, 
> String alias)
> +    FieldCriteria(Object anAttribute, Object aValue, String aClause, 
> UserAlias alias)
>      {
> -        super(anAttribute, aValue, alias);
> +        super(anAttribute, aValue, alias, false);
>          m_clause = aClause;
>      }
> 
> Index: InCriteria.java
> ===================================================================
> RCS file: 
> /home/cvspublic/jakarta-ojb/src/java/org/apache/ojb/broker/query/InCriteria.java,v 
> 
> retrieving revision 1.10
> diff -u -r1.10 InCriteria.java
> --- InCriteria.java    4 Apr 2004 23:53:36 -0000    1.10
> +++ InCriteria.java    17 May 2004 05:00:25 -0000
> @@ -25,10 +25,16 @@
>   */
>  public class InCriteria extends ValueCriteria
>  {
> -    InCriteria(Object anAttribute, Object aValue, String aClause, 
> String anAlias)
> -    {
> -        super(anAttribute, aValue, aClause, anAlias);
> -    }
> +    InCriteria(Object anAttribute, Object aValue, String aClause, 
> String anAlias)
> +    {
> +        super(anAttribute, aValue, aClause, anAlias);
> +    }
> +
> +    // PAW
> +    InCriteria(Object anAttribute, Object aValue, String aClause, 
> UserAlias anAlias)
> +    {
> +        super(anAttribute, aValue, aClause, anAlias);
> +    }
> 
>      /**
>       * @see org.apache.ojb.broker.query.SelectionCriteria#isBindable()
> Index: LikeCriteria.java
> ===================================================================
> RCS file: 
> /home/cvspublic/jakarta-ojb/src/java/org/apache/ojb/broker/query/LikeCriteria.java,v 
> 
> retrieving revision 1.8
> diff -u -r1.8 LikeCriteria.java
> --- LikeCriteria.java    4 Apr 2004 23:53:36 -0000    1.8
> +++ LikeCriteria.java    17 May 2004 05:00:25 -0000
> @@ -34,16 +34,28 @@
>  public class LikeCriteria extends ValueCriteria
>  {
> 
> -    /**
> -     * @param anAttribute
> -     * @param aValue
> -     * @param aClause
> -     * @param anAlias
> -     */
> -    public LikeCriteria(Object anAttribute, Object aValue, String 
> aClause, String anAlias)
> -    {
> -        super(anAttribute, generateSQLSearchPattern((String) aValue), 
> aClause, anAlias);
> -    }
> +    /**
> +     * @param anAttribute
> +     * @param aValue
> +     * @param aClause
> +     * @param anAlias
> +     */
> +    public LikeCriteria(Object anAttribute, Object aValue, String 
> aClause, String anAlias)
> +    {
> +        super(anAttribute, generateSQLSearchPattern((String) aValue), 
> aClause, anAlias);
> +    }
> +
> +    /**
> +     * @param anAttribute
> +     * @param aValue
> +     * @param aClause
> +     * @param aUserAlias
> +     */
> +    // PAW
> +    public LikeCriteria(Object anAttribute, Object aValue, String 
> aClause, UserAlias anAlias)
> +    {
> +        super(anAttribute, generateSQLSearchPattern((String) aValue), 
> aClause, anAlias);
> +    }
> 
>      /**
>       * The Character used for Escaping Wildcards
> Index: NullCriteria.java
> ===================================================================
> RCS file: 
> /home/cvspublic/jakarta-ojb/src/java/org/apache/ojb/broker/query/NullCriteria.java,v 
> 
> retrieving revision 1.8
> diff -u -r1.8 NullCriteria.java
> --- NullCriteria.java    4 Apr 2004 23:53:36 -0000    1.8
> +++ NullCriteria.java    17 May 2004 05:00:26 -0000
> @@ -23,10 +23,16 @@
>   */
>  public class NullCriteria extends ValueCriteria
>  {
> -    NullCriteria(String anAttribute, String aClause, String anAlias)
> -    {
> -        super(anAttribute, null, aClause, anAlias);
> -    }
> +    NullCriteria(String anAttribute, String aClause, String anAlias)
> +    {
> +        super(anAttribute, null, aClause, anAlias);
> +    }
> +
> +    // PAW
> +    NullCriteria(String anAttribute, String aClause, UserAlias anAlias)
> +    {
> +        super(anAttribute, null, aClause, anAlias);
> +    }
> 
>      public String toString()
>      {
> Index: SelectionCriteria.java
> ===================================================================
> RCS file: 
> /home/cvspublic/jakarta-ojb/src/java/org/apache/ojb/broker/query/SelectionCriteria.java,v 
> 
> retrieving revision 1.16
> diff -u -r1.16 SelectionCriteria.java
> --- SelectionCriteria.java    24 Apr 2004 08:25:37 -0000    1.16
> +++ SelectionCriteria.java    17 May 2004 05:00:26 -0000
> @@ -58,8 +58,10 @@
>      // BRJ: the criterion must be bound for the main class and for all 
> extents
>      private int m_numberOfExtentsToBind = 0; // BRJ:
> 
> +    // PAW
>      private String m_alias = null;
> -
> +    private UserAlias m_userAlias = null;
> +   
>      // BRJ: indicate whether attribute name should be translated into 
> column name
>      private boolean m_translateAttribute = true;
> 
> @@ -75,15 +77,40 @@
>       */
>      SelectionCriteria(Object anAttribute, Object aValue, String alias)
>      {
> -        if (!(anAttribute instanceof String || anAttribute instanceof 
> Query))
> -        {
> -            throw new IllegalArgumentException("An attribute must be a 
> String or a Query !");
> -        }
> +        if (!(anAttribute instanceof String || anAttribute instanceof 
> Query))
> +        {
> +            throw new IllegalArgumentException("An attribute must be a 
> String or a Query !");
> +        }
> 
>          m_attribute = anAttribute;
>          m_value = aValue;
>          this.m_bound = !isBindable();
>          this.m_alias = alias;
> +        this.m_userAlias  = m_alias == null ? null : new 
> UserAlias(m_alias, (String)getAttribute(), true);
> +    }
> +
> +    /**
> +     * Constructor declaration
> +     *
> +     * @param anAttribute  column- or fieldName or a Query
> +     * @param aValue  the value to compare with
> +     * @param negative  criteria is negated (ie NOT LIKE instead of LIKE)
> +     * @param userAlias  userAlias to link anAttribute to
> +     * @param dummy used so that subclass constructors calling with null
> +     * parameters have an unambiguous signature
> +     */
> +    SelectionCriteria(Object anAttribute, Object aValue, UserAlias 
> aUserAlias, boolean dummy)
> +    {
> +        if (!(anAttribute instanceof String || anAttribute instanceof 
> Query))
> +        {
> +            throw new IllegalArgumentException("An attribute must be a 
> String or a Query !");
> +        }
> +
> +        m_attribute = anAttribute;
> +        m_value = aValue;
> +        this.m_bound = !isBindable();
> +        this.m_userAlias = aUserAlias;
> +        this.m_alias = m_userAlias == null ? null : m_userAlias.getName();
>      }
> 
>      /**
> @@ -186,14 +213,45 @@
>      }
> 
>      /**
> +     * Sets the alias. By default the entire attribute path 
> participates in the alias
> +     * @param alias The name of the alias to set
> +     */
> +    public void setAlias(String alias)
> +    {
> +        m_alias = alias;
> +        // PAW
> +        String attributePath = (String)getAttribute();
> +        boolean allPathsAliased = true;
> +        m_userAlias = new UserAlias(alias, attributePath, 
> allPathsAliased);
> +       
> +    }
> +
> +    // PAW
> +    /**
>       * Sets the alias.
>       * @param alias The alias to set
>       */
> -    public void setAlias(String alias)
> +    public void setAlias(String alias, String aliasPath)
>      {
>          m_alias = alias;
> +        m_userAlias = new UserAlias(alias, (String)getAttribute(), 
> aliasPath);
> +    }
> +   
> +    // PAW
> +    /**
> +     * Sets the alias using a userAlias object.
> +     * @param userAlias The alias to set
> +     */
> +    public void setAlias(UserAlias userAlias)
> +    {
> +        m_alias = userAlias.getName();
> +        m_userAlias = userAlias;
>      }
> 
> +    public UserAlias getUserAlias()
> +    {
> +        return m_userAlias;
> +    }
>      /**
>       * @return true if attribute name should be translated into column 
> name
>       */
> Index: UserAlias.java
> ===================================================================
> RCS file: UserAlias.java
> diff -N UserAlias.java
> --- /dev/null    1 Jan 1970 00:00:00 -0000
> +++ UserAlias.java    17 May 2004 05:00:27 -0000
> @@ -0,0 +1,153 @@
> +/*
> + * Created on May 1, 2004
> + *
> + * To change the template for this generated file go to
> + * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
> + */
> +package org.apache.ojb.broker.query;
> +
> +import java.util.ArrayList;
> +import java.util.HashMap;
> +import java.util.Iterator;
> +import java.util.Map;
> +
> +import org.apache.ojb.broker.util.logging.Logger;
> +import org.apache.ojb.broker.util.logging.LoggerFactory;
> +
> +/**
> + * @author PAW
> + * This class is used to specify the path segments of a Criteria
> + * that should have associated table aliases.  Previously, the default
> + * behaviour was that all path segments participated in the alias
> + */
> +public class UserAlias
> +{
> +    private Map m_mapping = new HashMap();
> +    private String m_name = null;
> +    private String m_attributePath = null;
> +    private boolean m_allPathsAliased = false;
> +    private Logger m_logger = LoggerFactory.getLogger(UserAlias.class);
> +
> +    /**
> +     * Constructor declaration
> +     *
> +     * @param name the name of the alias
> +     * @param attributePath the full path of the SelectionCriteria 
> attribute
> +     */   
> +    public UserAlias(String name)
> +    {
> +        m_name = name;
> +    }
> +
> +
> +    /**
> +     * Constructor declaration
> +     *
> +     * @param name the name of the alias
> +     * @param attributePath the full path of the SelectionCriteria 
> attribute
> +     * @param aliasPath the portion of the attributePath which should 
> be aliased.
> +     * This should be unambiguous.  If ambiguous portions need aliasing 
> (e.g.
> +     * B.C in allAs.B.C.B.C), use add() instead
> +     */
> +    public UserAlias(String name, String attributePath, String aliasPath)
> +        {
> +        m_name = name;
> +        m_attributePath = attributePath;
> +        if (attributePath.lastIndexOf(aliasPath) == -1)
> +        {
> +            m_logger.warn("aliasPath should be a substring of 
> attributePath");
> +        }
> +        initMapping(attributePath, aliasPath);
> +    }
> +
> +    /**
> +     * Constructor declaration
> +     *
> +     * @param name the name of the alias
> +     * @param attributePath the full path of the SelectionCriteria 
> attribute
> +     * @param allPathsAliased indicates that all path portions of 
> attributePath
> +     * should be aliased (previously was the default)
> +     */
> +    public UserAlias(String name, String attributePath, boolean 
> allPathsAliased)
> +    {
> +        m_name = name;
> +        m_attributePath = attributePath;
> +        m_allPathsAliased = allPathsAliased;
> +    }
> +
> +    /**
> +     * generates the mapping from the aliasPath
> +     * @param aliasPath the portion of attributePath which should be 
> aliased
> +     *
> +     */
> +    private void initMapping(String attributePath, String aliasPath)
> +    {   
> +        Iterator aliasSegmentItr = pathToSegments(aliasPath).iterator();
> +        String currPath = "";
> +        String separator = "";
> +        while (aliasSegmentItr.hasNext())
> +        {
> +            currPath = currPath + separator + 
> (String)aliasSegmentItr.next();
> +            int beginIndex = attributePath.indexOf(currPath);
> +            if (beginIndex == -1)
> +            {
> +                break;
> +            }
> +            int endIndex = beginIndex + currPath.length();
> +            m_mapping.put(attributePath.substring(0, endIndex), m_name);
> +            separator = ".";
> +        }
> +    }
> +
> +    private ArrayList pathToSegments(String path)
> +    {
> +        ArrayList segments = new ArrayList();
> +        int sp = path.indexOf('.');
> +        while (sp != -1)
> +        {
> +            segments.add(path.substring(0, sp));
> +            path = path.substring(sp+1);
> +            sp = path.indexOf('.');
> +        }
> +        segments.add(path);
> +        return segments;
> +    }
> +   
> +    /**
> +     * Returns the name of this alias
> +     */
> +    public String getName()
> +    {
> +        return m_name;
> +    }
> +
> +    /**
> +     * Returns the name of this alias if path has been added
> +     * to the aliased portions of attributePath
> +     *
> +     * @param path the path to test for inclusion in the alias
> +     */
> +    public String getAlias(String path)
> +    {
> +        if (m_allPathsAliased && m_attributePath.lastIndexOf(path) != -1)
> +        {
> +            return m_name;
> +        }
> +        Object retObj = m_mapping.get(path);
> +        if (retObj != null)
> +        {
> +            return (String)retObj;   
> +        }
> +        return null;
> +    }
> +
> +    /**
> +     * Adds a path to the aliased paths
> +     *
> +     * @param path the path to add to the aliased paths
> +     */
> +    public void add(String path)
> +    {
> +        m_mapping.put(path, m_name);
> +    }
> +}
> Index: ValueCriteria.java
> ===================================================================
> RCS file: 
> /home/cvspublic/jakarta-ojb/src/java/org/apache/ojb/broker/query/ValueCriteria.java,v 
> 
> retrieving revision 1.7
> diff -u -r1.7 ValueCriteria.java
> --- ValueCriteria.java    4 Apr 2004 23:53:36 -0000    1.7
> +++ ValueCriteria.java    17 May 2004 05:00:27 -0000
> @@ -24,91 +24,163 @@
>   */
>  public class ValueCriteria extends SelectionCriteria
>  {
> -    static ValueCriteria buildEqualToCriteria(Object anAttribute, 
> Object aValue, String anAlias)
> -    {
> -        return new ValueCriteria(anAttribute, aValue, EQUAL, anAlias);
> -    }
> -
> -    static ValueCriteria buildNotEqualToCriteria(Object anAttribute, 
> Object aValue, String anAlias)
> -    {
> -        return new ValueCriteria(anAttribute, aValue, NOT_EQUAL, anAlias);
> -    }
> -
> -    static ValueCriteria buildGreaterCriteria(Object anAttribute, 
> Object aValue, String anAlias)
> -    {
> -        return new ValueCriteria(anAttribute, aValue,GREATER, anAlias);
> -    }
> -
> -    static ValueCriteria buildNotGreaterCriteria(Object anAttribute, 
> Object aValue, String anAlias)
> -    {
> -        return new ValueCriteria(anAttribute, aValue, NOT_GREATER, 
> anAlias);
> -    }
> -
> -    static ValueCriteria buildLessCriteria(Object anAttribute, Object 
> aValue, String anAlias)
> -    {
> -        return new ValueCriteria(anAttribute, aValue, LESS, anAlias);
> -    }
> -
> -    static ValueCriteria buildNotLessCriteria(Object anAttribute, 
> Object aValue, String anAlias)
> -    {
> -        return new ValueCriteria(anAttribute, aValue, NOT_LESS, anAlias);
> -    }
> -
> -    static ValueCriteria buildLikeCriteria(Object anAttribute, Object 
> aValue, String anAlias)
> -    {
> -        return new LikeCriteria(anAttribute, aValue, LIKE, anAlias);
> -    }
> -
> -    static ValueCriteria buildNotLikeCriteria(Object anAttribute, 
> Object aValue, String anAlias)
> -    {
> -        return new ValueCriteria(anAttribute, aValue, NOT_LIKE, anAlias);
> -    }
> -
> -    static InCriteria buildInCriteria(Object anAttribute, Object 
> aValue, String anAlias)
> -    {
> -        return new InCriteria(anAttribute, aValue, IN, anAlias);
> -    }
> -
> -    static InCriteria buildNotInCriteria(Object anAttribute, Object 
> aValue, String anAlias)
> -    {
> -        return new InCriteria(anAttribute, aValue, NOT_IN, anAlias);
> -    }
> -
> -    static NullCriteria buildNullCriteria(String anAttribute, String 
> anAlias)
> -    {
> -        return new NullCriteria(anAttribute, IS_NULL, anAlias);
> -    }
> -
> -    static NullCriteria buildNotNullCriteria(String anAttribute, String 
> anAlias)
> -    {
> -        return new NullCriteria(anAttribute, NOT_IS_NULL, anAlias);
> -    }
> +    static ValueCriteria buildEqualToCriteria(Object anAttribute, 
> Object aValue, String anAlias)
> +    {
> +        return new ValueCriteria(anAttribute, aValue, EQUAL, anAlias);
> +    }
> +    // PAW
> +    static ValueCriteria buildEqualToCriteria(Object anAttribute, 
> Object aValue, UserAlias anAlias)
> +    {
> +        return new ValueCriteria(anAttribute, aValue, EQUAL, anAlias);
> +    }
> +
> +    static ValueCriteria buildNotEqualToCriteria(Object anAttribute, 
> Object aValue, String anAlias)
> +    {
> +        return new ValueCriteria(anAttribute, aValue, NOT_EQUAL, anAlias);
> +    }
> +    static ValueCriteria buildNotEqualToCriteria(Object anAttribute, 
> Object aValue, UserAlias anAlias)
> +    {
> +        return new ValueCriteria(anAttribute, aValue, NOT_EQUAL, anAlias);
> +    }
> +
> +    static ValueCriteria buildGreaterCriteria(Object anAttribute, 
> Object aValue, String anAlias)
> +    {
> +        return new ValueCriteria(anAttribute, aValue,GREATER, anAlias);
> +    }
> +    static ValueCriteria buildGreaterCriteria(Object anAttribute, 
> Object aValue, UserAlias anAlias)
> +    {
> +        return new ValueCriteria(anAttribute, aValue,GREATER, anAlias);
> +    }
> +
> +    static ValueCriteria buildNotGreaterCriteria(Object anAttribute, 
> Object aValue, String anAlias)
> +    {
> +        return new ValueCriteria(anAttribute, aValue, NOT_GREATER, 
> anAlias);
> +    }
> +    static ValueCriteria buildNotGreaterCriteria(Object anAttribute, 
> Object aValue, UserAlias anAlias)
> +    {
> +        return new ValueCriteria(anAttribute, aValue, NOT_GREATER, 
> anAlias);
> +    }
> +
> +    static ValueCriteria buildLessCriteria(Object anAttribute, Object 
> aValue, String anAlias)
> +    {
> +        return new ValueCriteria(anAttribute, aValue, LESS, anAlias);
> +    }
> +    static ValueCriteria buildLessCriteria(Object anAttribute, Object 
> aValue, UserAlias anAlias)
> +    {
> +        return new ValueCriteria(anAttribute, aValue, LESS, anAlias);
> +    }
> +
> +    static ValueCriteria buildNotLessCriteria(Object anAttribute, 
> Object aValue, String anAlias)
> +    {
> +        return new ValueCriteria(anAttribute, aValue, NOT_LESS, anAlias);
> +    }
> +    static ValueCriteria buildNotLessCriteria(Object anAttribute, 
> Object aValue, UserAlias anAlias)
> +    {
> +        return new ValueCriteria(anAttribute, aValue, NOT_LESS, anAlias);
> +    }
> +
> +    static ValueCriteria buildLikeCriteria(Object anAttribute, Object 
> aValue, String anAlias)
> +    {
> +        return new LikeCriteria(anAttribute, aValue, LIKE, anAlias);
> +    }
> +    static ValueCriteria buildLikeCriteria(Object anAttribute, Object 
> aValue, UserAlias anAlias)
> +    {
> +        return new LikeCriteria(anAttribute, aValue, LIKE, anAlias);
> +    }
> +
> +    static ValueCriteria buildNotLikeCriteria(Object anAttribute, 
> Object aValue, String anAlias)
> +    {
> +        return new ValueCriteria(anAttribute, aValue, NOT_LIKE, anAlias);
> +    }
> +    static ValueCriteria buildNotLikeCriteria(Object anAttribute, 
> Object aValue, UserAlias anAlias)
> +    {
> +        return new ValueCriteria(anAttribute, aValue, NOT_LIKE, anAlias);
> +    }
> +
> +    static InCriteria buildInCriteria(Object anAttribute, Object 
> aValue, String anAlias)
> +    {
> +        return new InCriteria(anAttribute, aValue, IN, anAlias);
> +    }
> +    static InCriteria buildInCriteria(Object anAttribute, Object 
> aValue, UserAlias anAlias)
> +    {
> +        return new InCriteria(anAttribute, aValue, IN, anAlias);
> +    }
> +
> +    static InCriteria buildNotInCriteria(Object anAttribute, Object 
> aValue, String anAlias)
> +    {
> +        return new InCriteria(anAttribute, aValue, NOT_IN, anAlias);
> +    }
> +    static InCriteria buildNotInCriteria(Object anAttribute, Object 
> aValue, UserAlias anAlias)
> +    {
> +        return new InCriteria(anAttribute, aValue, NOT_IN, anAlias);
> +    }
> +
> +    static NullCriteria buildNullCriteria(String anAttribute, String 
> anAlias)
> +    {
> +        return new NullCriteria(anAttribute, IS_NULL, anAlias);
> +    }
> +    static NullCriteria buildNullCriteria(String anAttribute, UserAlias 
> anAlias)
> +    {
> +        return new NullCriteria(anAttribute, IS_NULL, anAlias);
> +    }
> +
> +    static NullCriteria buildNotNullCriteria(String anAttribute, String 
> anAlias)
> +    {
> +        return new NullCriteria(anAttribute, NOT_IS_NULL, anAlias);
> +    }
> +    static NullCriteria buildNotNullCriteria(String anAttribute, 
> UserAlias anAlias)
> +    {
> +        return new NullCriteria(anAttribute, NOT_IS_NULL, anAlias);
> +    }
> 
> -    static BetweenCriteria buildBeweenCriteria(Object anAttribute, 
> Object aValue1, Object aValue2, String anAlias)
> -    {
> -        return new BetweenCriteria(anAttribute, aValue1, aValue2, 
> BETWEEN, anAlias);
> -    }
> -
> -    static BetweenCriteria buildNotBeweenCriteria(Object anAttribute, 
> Object aValue1, Object aValue2, String anAlias)
> -    {
> -        return new BetweenCriteria(anAttribute, aValue1, aValue2, 
> NOT_BETWEEN, anAlias);
> -    }
> +    static BetweenCriteria buildBeweenCriteria(Object anAttribute, 
> Object aValue1, Object aValue2, String anAlias)
> +    {
> +        return new BetweenCriteria(anAttribute, aValue1, aValue2, 
> BETWEEN, anAlias);
> +    }
> +    static BetweenCriteria buildBeweenCriteria(Object anAttribute, 
> Object aValue1, Object aValue2, UserAlias anAlias)
> +    {
> +        return new BetweenCriteria(anAttribute, aValue1, aValue2, 
> BETWEEN, anAlias);
> +    }
> +
> +    static BetweenCriteria buildNotBeweenCriteria(Object anAttribute, 
> Object aValue1, Object aValue2, String anAlias)
> +    {
> +        return new BetweenCriteria(anAttribute, aValue1, aValue2, 
> NOT_BETWEEN, anAlias);
> +    }
> +    static BetweenCriteria buildNotBeweenCriteria(Object anAttribute, 
> Object aValue1, Object aValue2, UserAlias anAlias)
> +    {
> +        return new BetweenCriteria(anAttribute, aValue1, aValue2, 
> NOT_BETWEEN, anAlias);
> +    }
> 
>      private String m_clause;
> 
> -    /**
> -     * Constructor declaration
> -     *
> -     * @param anAttribute  column- or fieldName
> -     * @param aValue  the value to compare with
> -     * @param aClause the SQL compare clause (ie LIKE, = , IS NULL)
> -     * @param anAlias use alias to link anAttribute to
> -     */
> -    ValueCriteria(Object anAttribute, Object aValue, String aClause, 
> String anAlias)
> -    {
> -        super(anAttribute, aValue, anAlias);
> -        m_clause = aClause;
> -    }
> +    /**
> +     * Constructor declaration
> +     *
> +     * @param anAttribute  column- or fieldName
> +     * @param aValue  the value to compare with
> +     * @param aClause the SQL compare clause (ie LIKE, = , IS NULL)
> +     * @param anAlias use alias to link anAttribute to
> +     */
> +    ValueCriteria(Object anAttribute, Object aValue, String aClause, 
> String anAlias)
> +    {
> +        super(anAttribute, aValue, anAlias);
> +        m_clause = aClause;
> +    }
> +
> +    /**
> +     * Constructor declaration
> +     *
> +     * @param anAttribute  column- or fieldName
> +     * @param aValue  the value to compare with
> +     * @param aClause the SQL compare clause (ie LIKE, = , IS NULL)
> +     * @param aUserAliass userAlias to link anAttribute to
> +     */
> +    // PAW
> +    ValueCriteria(Object anAttribute, Object aValue, String aClause, 
> UserAlias aUserAlias)
> +    {
> +        super(anAttribute, aValue, aUserAlias, false);
> +        m_clause = aClause;
> +    }
> 
> 
>      /* (non-Javadoc)
> Index: SqlQueryStatement.java
> ===================================================================
> RCS file: 
> /home/cvspublic/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java,v 
> 
> retrieving revision 1.73
> diff -u -r1.73 SqlQueryStatement.java
> --- SqlQueryStatement.java    6 May 2004 19:46:40 -0000    1.73
> +++ SqlQueryStatement.java    17 May 2004 05:02:15 -0000
> @@ -43,7 +43,7 @@
>   * Model a Statement based on Query.
>   *
>   * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
> - * @version $Id: SqlQueryStatement.java,v 1.73 2004/05/06 19:46:40 brj 
> Exp $
> + * @version $Id: SqlQueryStatement.java,v 1.72 2004/04/24 08:25:37 brj 
> Exp $
>   */
>  public abstract class SqlQueryStatement implements SqlStatement, 
> JoinSyntaxTypes
>  {
> @@ -152,7 +152,9 @@
>       * @param pathClasses
>       * @return ColumnInfo
>       */
> -    protected AttributeInfo getAttributeInfo(String attr, boolean 
> useOuterJoins, String aUserAlias, Map pathClasses)
> +// PAW
> +//    protected AttributeInfo getAttributeInfo(String attr, boolean 
> useOuterJoins, String aUserAlias, Map pathClasses)
> +    protected AttributeInfo getAttributeInfo(String attr, boolean 
> useOuterJoins, UserAlias aUserAlias, Map pathClasses)
>      {
>          AttributeInfo result = new AttributeInfo();
>          TableAlias tableAlias = null;
> @@ -192,7 +194,10 @@
>                  /**
>                   * pathName might be an alias, so check this first
>                   */
> -                tableAlias = getTableAlias(null, useOuterJoins, 
> pathName, null, pathClasses);
> +                // PAW
> +                // UserAlias class used here to conform to 
> getTableAlias() interface
> +//                tableAlias = getTableAlias(null, useOuterJoins, 
> pathName, null, pathClasses);
> +                tableAlias = getTableAlias(pathName, useOuterJoins, new 
> UserAlias(pathName, pathName, pathName), null, pathClasses);
>              }
> 
>              if (tableAlias != null)
> @@ -421,9 +426,11 @@
>       * @param buf
>       * @return
>       */
> -    protected boolean appendColName(String attr, boolean useOuterJoins, 
> String aUserAlias, StringBuffer buf)
> +//    protected boolean appendColName(String attr, boolean 
> useOuterJoins, String aUserAlias, StringBuffer buf)
> +    protected boolean appendColName(String attr, boolean useOuterJoins, 
> UserAlias aUserAlias, StringBuffer buf)
>      {
>          // PAW: is this correct for pathClasses ?
> +        //AttributeInfo attrInfo = getAttributeInfo(attr, 
> useOuterJoins, aUserAlias, getQuery().getPathClasses());
>          AttributeInfo attrInfo = getAttributeInfo(attr, useOuterJoins, 
> aUserAlias, getQuery().getPathClasses());
>          TableAlias tableAlias = attrInfo.tableAlias;
> 
> @@ -445,10 +452,13 @@
>       * @param buf
>       * @return
>       */
> -    protected boolean appendColName(String attr, String attrAlias, 
> boolean useOuterJoins, String aUserAlias,
> +    // PAW
> +    //protected boolean appendColName(String attr, String attrAlias, 
> boolean useOuterJoins, String aUserAlias,
> +    protected boolean appendColName(String attr, String attrAlias, 
> boolean useOuterJoins, UserAlias aUserAlias,
>              StringBuffer buf)
>      {
>          // PAW: is this correct for pathClasses ?
> +        //AttributeInfo attrInfo = getAttributeInfo(attr, 
> useOuterJoins, aUserAlias, getQuery().getPathClasses());
>          AttributeInfo attrInfo = getAttributeInfo(attr, useOuterJoins, 
> aUserAlias, getQuery().getPathClasses());
>          TableAlias tableAlias = attrInfo.tableAlias;
>          PathInfo pi = attrInfo.pathInfo;
> @@ -664,7 +674,9 @@
> 
>          if (c.isTranslateField())
>          {
> -            appendColName((String) c.getValue(), false, c.getAlias(), 
> buf);
> +            // PAW
> +            //appendColName((String) c.getValue(), false, c.getAlias(), 
> buf);
> +            appendColName((String) c.getValue(), false, 
> c.getUserAlias(), buf);
>          }
>          else
>          {
> @@ -827,7 +839,9 @@
>              return;
>          }
> 
> -        AttributeInfo attrInfo = getAttributeInfo((String) 
> c.getAttribute(), false, c.getAlias(), c.getPathClasses());
> +        // PAW
> +//        AttributeInfo attrInfo = getAttributeInfo((String) 
> c.getAttribute(), false, c.getAlias(), c.getPathClasses());
> +        AttributeInfo attrInfo = getAttributeInfo((String) 
> c.getAttribute(), false, c.getUserAlias(), c.getPathClasses());
>          TableAlias alias = attrInfo.tableAlias;
> 
>          if (alias != null)
> @@ -924,7 +938,9 @@
>       * must not add new join, but use the value of foreign key
>       * @param pathClasses the hints
>       */
> -    private TableAlias getTableAlias(String aPath, boolean 
> useOuterJoins, String aUserAlias, String[] fieldRef, Map pathClasses)
> +    // PAW
> +//    private TableAlias getTableAlias(String aPath, boolean 
> useOuterJoins, String aUserAlias, String[] fieldRef, Map pathClasses)
> +    private TableAlias getTableAlias(String aPath, boolean 
> useOuterJoins, UserAlias aUserAlias, String[] fieldRef, Map pathClasses)
>      {
>          TableAlias curr, prev, indirect;
>          String attr, attrPath = null;
> @@ -937,7 +953,10 @@
>          boolean outer = useOuterJoins;
>          int pathLength;
> 
> -        curr = getTableAliasForPath(aPath, aUserAlias);
> +        // PAW
> +        //curr = getTableAliasForPath(aPath, aUserAlias);
> +        String pathAlias = aUserAlias == null ? null : 
> aUserAlias.getAlias(aPath);
> +        curr = getTableAliasForPath(aPath, pathAlias);
> 
>          if (curr != null)
>          {
> @@ -1023,7 +1042,7 @@
>              {
>                  // must be n:1 or 1:1
>                  cld = getItemClassDescriptor(ord, attrPath, pathClasses);
> -               
> +
>                  // BRJ : if ord is taken from 'super' we have to change 
> prev accordingly
>                  if (!prev.cld.equals(ord.getClassDescriptor()))
>                  {
> @@ -1052,12 +1071,17 @@
>                  }
>              }
> 
> -            curr = getTableAliasForPath(attrPath, aUserAlias, aPath);
> +            // PAW
> +//            curr = getTableAliasForPath(attrPath, aUserAlias, aPath);
> +            pathAlias = aUserAlias == null ? null : 
> aUserAlias.getAlias(attrPath);
> +            curr = getTableAliasForPath(attrPath, pathAlias, aPath);
> 
>              if (curr == null)
>              {
>                  List hintClasses = (List) pathClasses.get(aPath);
> -                curr = createTableAlias(cld, attrPath, aUserAlias, 
> aPath, hintClasses);
> +                // PAW
> +//                curr = createTableAlias(cld, attrPath, aUserAlias, 
> aPath, hintClasses);
> +                curr = createTableAlias(cld, attrPath, pathAlias, 
> aPath, hintClasses);
> 
>                  outer = outer || (curr.cld == prev.cld) || 
> curr.hasExtents() || useOuterJoins;
>                  addJoin(prev, prevKeys, curr, keys, outer, attr);
> @@ -1068,6 +1092,8 @@
>              prev = curr;
>          }
> 
> +        // PAW
> +        m_logger.debug("Result of getTableAlias(): " + curr);
>          return curr;
>      }
> 
> @@ -1252,6 +1278,8 @@
>          String aliasName = String.valueOf(getAliasChar()) + 
> m_aliasCount++; // + m_pathToAlias.size();
>          alias = new TableAlias(table, aliasName);
>          m_pathToAlias.put(path, alias);
> +        // PAW
> +        m_logger.debug("createTableAlias2: path: " + path + " 
> tableAlias: " + alias);
> 
>          return alias;
>      }
> @@ -1580,12 +1608,14 @@
>                  // BRJ: do not build join tree for subQuery attribute
>                  if (c.getAttribute() != null && c.getAttribute() 
> instanceof String)
>                  {
> -                    buildJoinTreeForColumn((String) c.getAttribute(), 
> useOuterJoin, c.getAlias(), c.getPathClasses());
> +                    //buildJoinTreeForColumn((String) c.getAttribute(), 
> useOuterJoin, c.getAlias(), c.getPathClasses());
> +                    buildJoinTreeForColumn((String) c.getAttribute(), 
> useOuterJoin, c.getUserAlias(), c.getPathClasses());
>                  }
>                  if (c instanceof FieldCriteria)
>                  {
>                      FieldCriteria cc = (FieldCriteria) c;
> -                    buildJoinTreeForColumn((String) cc.getValue(), 
> useOuterJoin, c.getAlias(), c.getPathClasses());
> +//                    buildJoinTreeForColumn((String) cc.getValue(), 
> useOuterJoin, c.getAlias(), c.getPathClasses());
> +                    buildJoinTreeForColumn((String) cc.getValue(), 
> useOuterJoin, c.getUserAlias(), c.getPathClasses());
>                  }
>              }
>          }
> @@ -1596,13 +1626,15 @@
>       * functions and the last segment are removed
>       * ie: avg(accounts.amount) -> accounts
>       */
> -    private void buildJoinTreeForColumn(String aColName, boolean 
> useOuterJoin, String aUserAlias, Map pathClasses)
> +//    private void buildJoinTreeForColumn(String aColName, boolean 
> useOuterJoin, String aUserAlias, Map pathClasses)
> +    private void buildJoinTreeForColumn(String aColName, boolean 
> useOuterJoin, UserAlias aUserAlias, Map pathClasses)
>      {
>          String pathName = SqlHelper.cleanPath(aColName);
>          int sepPos = pathName.lastIndexOf(".");
> 
>          if (sepPos >= 0)
>          {
> +//            getTableAlias(pathName.substring(0, sepPos), 
> useOuterJoin, aUserAlias,
>              getTableAlias(pathName.substring(0, sepPos), useOuterJoin, 
> aUserAlias,
>                            new String[]{pathName.substring(sepPos + 1)}, 
> pathClasses);
>          }
> Index: PathTest.java
> ===================================================================
> RCS file: 
> /home/cvspublic/jakarta-ojb/src/test/org/apache/ojb/broker/PathTest.java,v
> retrieving revision 1.1
> diff -u -r1.1 PathTest.java
> --- PathTest.java    24 Apr 2004 08:25:38 -0000    1.1
> +++ PathTest.java    17 May 2004 05:03:02 -0000
> @@ -15,6 +15,7 @@
>  import org.apache.ojb.broker.query.Query;
>  import org.apache.ojb.broker.query.QueryByCriteria;
>  import org.apache.ojb.broker.query.QueryFactory;
> +import org.apache.ojb.broker.query.UserAlias;
> 
>  public class PathTest extends TestCase
>  {
> @@ -107,11 +108,13 @@
>          broker.beginTransaction();
>          A a = new A(A_OFFSET);
>          broker.store(a);
> +        System.out.println("A - " + a.getAAttrib());
>          for (int i = 0; i < NUM_B_PER_A; i++)
>          {
>              B b = new B(A_OFFSET + B_OFFSET * i);
>              b.setA(a);
>              broker.store(b);
> +            System.out.println("\tB - " + b.getBAttrib());
>              for (int j = 0; j < NUM_C_PER_B; j++)
>              {
>                  C c = new C(A_OFFSET + B_OFFSET * i + C_OFFSET * j);
> @@ -120,6 +123,8 @@
>                  c.setD(d);
>                  broker.store(d);
>                  broker.store(c);
> +                System.out.println("\t\tC - " + c.getCAttrib());
> +                System.out.println("\t\t\tD - " + d.getDAttrib());
>              }
>              for (int j = 0; j < NUM_C1_PER_B; j++)
>              {
> @@ -130,6 +135,8 @@
>                  c1.setC1Attrib(c1.getCAttrib() + 1);
>                  broker.store(d);
>                  broker.store(c1);
> +                System.out.println("\t\tC1 - " + c1.getC1Attrib());
> +                System.out.println("\t\t\tD - " + d.getDAttrib());
>              }
>          }
>          broker.commitTransaction();
> @@ -140,40 +147,277 @@
> 
>          Query query = QueryFactory.newQuery(A.class, crit);
>          Collection As = broker.getCollectionByQuery(query);
> -        assertEquals(As.size(), NUM_A);
> +        assertEquals(NUM_A, As.size());
> 
>          query = QueryFactory.newQuery(B.class, crit);
>          Collection Bs = broker.getCollectionByQuery(query);
>          int numB = NUM_A * NUM_B_PER_A;
> -        assertEquals(Bs.size(), numB);
> +        assertEquals(numB, Bs.size());
> 
>          query = QueryFactory.newQuery(C.class, crit);
>          Collection Cs = broker.getCollectionByQuery(query);
>          int numC = numB * (NUM_C_PER_B + NUM_C1_PER_B);
> -        assertEquals(Cs.size(), numC);
> +        assertEquals(numC, Cs.size());
> 
>          query = QueryFactory.newQuery(D.class, crit);
>          Collection Ds = broker.getCollectionByQuery(query);
>          int numD = numC * NUM_D_PER_C;
> -        assertEquals(Ds.size(), numD);
> +        assertEquals(numD, Ds.size());
> 
>      }
> 
> +//    This is the result of the above population
> +//
> +//    A - 10000
> +//        B - 10000
> +//            C - 10000
> +//                D - 10010
> +//            C - 10100
> +//                D - 10110
> +//            C1 - 10001
> +//                D - 10010
> +//            C1 - 10101
> +//                D - 10110
> +//            C1 - 10201
> +//                D - 10210
> +//        B - 11000
> +//            C - 11000
> +//                D - 11010
> +//            C - 11100
> +//                D - 11110
> +//            C1 - 11001
> +//                D - 11010
> +//            C1 - 11101
> +//                D - 11110
> +//            C1 - 11201
> +//                D - 11210
> +//        B - 12000
> +//            C - 12000
> +//                D - 12010
> +//            C - 12100
> +//                D - 12110
> +//            C1 - 12001
> +//                D - 12010
> +//            C1 - 12101
> +//                D - 12110
> +//            C1 - 12201
> +//                D - 12210
> +//        B - 13000
> +//            C - 13000
> +//                D - 13010
> +//            C - 13100
> +//                D - 13110
> +//            C1 - 13001
> +//                D - 13010
> +//            C1 - 13101
> +//                D - 13110
> +//            C1 - 13201
> +//                D - 13210
> +
> +    /*
> +     *  Find all Bs having a particular C1 (c1)
> +     *  Works
> +     */
> +    public void testPathClassOnSegment1() throws Exception
> +    {
> +        try
> +        {
> +            // c1 criteria
> +            Criteria crit1 = new Criteria();
> +            crit1.addEqualTo("cSet.c1Attrib", new Integer("10001"));
> +            crit1.addPathClass("cSet", C1.class);
> +           
> +            Query query = new QueryByCriteria(B.class, crit1);
> +
> +            Collection allBs = broker.getCollectionByQuery(query);
> +
> +            java.util.Iterator itr = allBs.iterator();
> +
> +            assertEquals(1, allBs.size());
> +            System.out.println("testPathClassOnSegment1() iteration 
> size:" + allBs.size());
> +            while (itr.hasNext())
> +            {
> +                B b = (B) itr.next();
> +                System.out.println("Found B:  " + b.getId() + " " + 
> b.getBAttrib());
> +            }
> +        }
> +        catch (Throwable t)
> +        {
> +            t.printStackTrace(System.out);
> +            fail("testPathClassOnSegment1: " + t.getMessage());
> +        }
> +    }
> +   
> +    /*
> +     *  Find all As having a particular C1 (c1)
> +     *  Works
> +     */
> +    public void testPathClassOnSegment2() throws Exception
> +    {
> +        try
> +        {
> +            // c1 criteria
> +            Criteria crit1 = new Criteria();
> +            crit1.addEqualTo("bSet.cSet.c1Attrib", new Integer("10001"));
> +            crit1.addPathClass("bSet.cSet", C1.class);
> +           
> +            Query query = new QueryByCriteria(A.class, crit1);
> +
> +            Collection allAs = broker.getCollectionByQuery(query);
> +
> +            java.util.Iterator itr = allAs.iterator();
> +
> +            assertEquals(allAs.size(), 1);
> +            System.out.println("testPathClassOnSegment2() iteration 
> size:" + allAs.size());
> +            while (itr.hasNext())
> +            {
> +                A a = (A) itr.next();
> +                System.out.println("Found A:  " + a.getId() + " " + 
> a.getAAttrib());
> +            }
> +        }
> +        catch (Throwable t)
> +        {
> +            t.printStackTrace(System.out);
> +            fail("testPathClassOnSegment2: " + t.getMessage());
> +        }
> +    }
> +   
> +    /*
> +     *  Find all Bs having a C with a particular D (d1)
> +     *  Works
> +     */
> +    public void testSingleAlias() throws Exception
> +    {
> +        try
> +        {
> +            // d1 criteria
> +            Criteria crit1 = new Criteria();
> +            crit1.setAlias("cToD1", "cSet");  // unnecessary, but its 
> use should not
> +                                            // cause incorrect results
> +            crit1.addEqualTo("cSet.d.dAttrib", new Integer("10010"));
> +
> +            Query query = new QueryByCriteria(B.class, crit1);
> +
> +            Collection allBs = broker.getCollectionByQuery(query);
> +
> +            java.util.Iterator itr = allBs.iterator();
> +
> +            assertEquals(2, allBs.size());
> +            System.out.println("testSingleAlias() iteration size:" + 
> allBs.size());
> +            while (itr.hasNext())
> +            {
> +                B b = (B) itr.next();
> +                System.out.println("Found B:  " + b.getId() + " " + 
> b.getBAttrib());
> +            }
> +        }
> +        catch (Throwable t)
> +        {
> +            t.printStackTrace(System.out);
> +            fail("testSingleAlias: " + t.getMessage());
> +        }
> +    }
> +   
> +    /*
> +     *  Find all Bs having any C with a particular D (d1) and any C 
> with a particular D (d2)
> +     *  Works
> +     */
> +    public void testTwoAliasesTwoSegments() throws Exception
> +    {
> +        try
> +        {
> +            // d1 criteria
> +            Criteria crit1 = new Criteria();
> +            crit1.setAlias("cToD1", "cSet.d");
> +            crit1.addEqualTo("cSet.d.dAttrib", new Integer("10010"));
> +
> +            // d2 criteria
> +            Criteria crit2 = new Criteria();
> +            crit2.setAlias("cToD2", "cSet.d");
> +            crit2.addEqualTo("cSet.d.dAttrib", new Integer("10110"));
> +
> +            crit1.addAndCriteria(crit2);
> +
> +            Query query = new QueryByCriteria(B.class, crit1);
> +
> +            Collection allBs = broker.getCollectionByQuery(query);
> +
> +            java.util.Iterator itr = allBs.iterator();
> +
> +            assertEquals(4, allBs.size());
> +            System.out.println("testTwoAliasesTwoSegments() iteration 
> size:" + allBs.size());
> +            while (itr.hasNext())
> +            {
> +                B b = (B) itr.next();
> +                System.out.println("Found B:  " + b.getId() + " " + 
> b.getBAttrib());
> +            }
> +        }
> +        catch (Throwable t)
> +        {
> +            t.printStackTrace(System.out);
> +            fail("testTwoAliasesTwoSegments: " + t.getMessage());
> +        }
> +    }
> +   
> +    /*
> +     *  Find all As having any B with any C with a particular D (d1) 
> and any C with a particular D (d2)
> +     *  Works
> +     */
> +    public void testTwoAliasesThreeSegments() throws Exception
> +    {
> +        try
> +        {
> +            // d1 criteria
> +            Criteria crit1 = new Criteria();
> +            crit1.addEqualTo("bSet.cSet.d.dAttrib", new Integer("10010"));
> +            crit1.setAlias("bToCToD1", "cSet.d");
> +
> +            // d2 criteria
> +            Criteria crit2 = new Criteria();
> +            crit2.addEqualTo("bSet.cSet.d.dAttrib", new Integer("10110"));
> +            crit2.setAlias("bToCToD2", "cSet.d");
> +
> +            crit1.addAndCriteria(crit2);
> +
> +            boolean isDistinct = true;
> +            Query query = new QueryByCriteria(A.class, crit1, true);
> +
> +            Collection allAs = broker.getCollectionByQuery(query);
> +
> +            java.util.Iterator itr = allAs.iterator();
> +
> +            assertEquals(1, allAs.size());
> +            System.out.println("testTwoAliasesThreeSegments() iteration 
> size:" + allAs.size());
> +            while (itr.hasNext())
> +            {
> +                A a = (A) itr.next();
> +                System.out.println("Found A:  " + a.getId() + " " + 
> a.getAAttrib());
> +            }
> +        }
> +        catch (Throwable t)
> +        {
> +            t.printStackTrace(System.out);
> +            fail("testTwoAliasesThreeSegments: " + t.getMessage());
> +        }
> +    }   
> +   
> +    /*
> +     *  Find all Bs having a particular C (c) and a particular C1 (c1)
> +     */
>      public void testPathClassPerCriteria() throws Exception
>      {
>          try
>          {
> -            // one EDBranch
> +            // C criteria
>              Criteria crit1 = new Criteria();
> -            crit1.setAlias("alias1");
>              crit1.addEqualTo("cSet.cAttrib", new Integer("10200"));
>              crit1.addPathClass("cSet", C.class);
> +            crit1.setAlias("alias1");
> 
> -            // one EDLeaf
> +            // C1 criteria (subclass of C)
>              Criteria crit2 = new Criteria();
> -            crit2.setAlias("alias2");
>              crit2.addEqualTo("cSet.c1Attrib", new Integer("10001"));
>              crit2.addPathClass("cSet", C1.class);
> +            crit2.setAlias("alias2");
> 
>              crit1.addAndCriteria(crit2);
> 
> @@ -183,7 +427,7 @@
> 
>              java.util.Iterator itr = allBs.iterator();
> 
> -            assertEquals(allBs.size(), 1);
> +            assertEquals(1, allBs.size());
>              System.out.println("testPathClassPerCriteria() iteration 
> size:" + allBs.size());
>              while (itr.hasNext())
>              {
> @@ -197,7 +441,143 @@
>              fail("testPathClassPerCriteria: " + t.getMessage());
>          }
>      }
> -
> +
> +    /*
> +     *  Find all Bs having a particular C1 (c1_a) and a particular C3 
> (c1_b)
> +     *  Works
> +     */
> +    public void testPathClassPerQuery() throws Exception
> +    {
> +        try
> +        {
> +            // c1_a criteria
> +            Criteria crit1 = new Criteria();
> +            crit1.addEqualTo("cSet.c1Attrib", new Integer("12001"));
> +            //crit1.addPathClass("cSet", C1.class); // can use 1 query 
> setting instead
> +            crit1.setAlias("alias1");
> +
> +            // c2_b criteria
> +            Criteria crit2 = new Criteria();
> +            crit2.addEqualTo("cSet.c1Attrib", new Integer("12101"));
> +            //crit2.addPathClass("cSet", C1.class); // can use 1 query 
> setting instead
> +            crit2.setAlias("alias2");
> +
> +            crit1.addAndCriteria(crit2);
> +
> +            QueryByCriteria query = new QueryByCriteria(B.class, crit1);
> +            query.addPathClass("cSet", C1.class);
> +
> +            Collection allBs = broker.getCollectionByQuery(query);
> +
> +            java.util.Iterator itr = allBs.iterator();
> +
> +            assertEquals(1, allBs.size());
> +            System.out.println("testPathClassPerQuery() iteration 
> size:" + allBs.size());
> +            while (itr.hasNext())
> +            {
> +                B b = (B) itr.next();
> +                System.out.println("Found B:  " + b.getId() + " " + 
> b.getBAttrib());
> +            }
> +        }
> +        catch (Throwable t)
> +        {
> +            t.printStackTrace(System.out);
> +            fail("testPathClassPerQuery: " + t.getMessage());
> +        }
> +    }
> +   
> +    /*
> +     *  Find all As having a B with both a particular C-D combination and
> +     *  another particular C-D combination
> +     */
> +    public void testThreeSegmentsAliasOnSegment2And3() throws Exception
> +    {
> +        try
> +        {
> +            // d1 criteria
> +            Criteria crit1 = new Criteria();
> +            crit1.addEqualTo("bSet.cSet.d.dAttrib", new Integer("10010"));
> +            crit1.setAlias("bToCToD1", "cSet.d");
> +
> +            // d2 criteria
> +            Criteria crit2 = new Criteria();
> +            crit2.addEqualTo("bSet.cSet.d.dAttrib", new Integer("10110"));
> +            crit2.setAlias("bToCToD2", "cSet.d");
> +
> +            crit1.addAndCriteria(crit2);
> +
> +            boolean isDistinct = true;
> +            Query query = new QueryByCriteria(A.class, crit1, isDistinct);
> +
> +            Collection allAs = broker.getCollectionByQuery(query);
> +
> +            java.util.Iterator itr = allAs.iterator();
> +
> +            assertEquals(1, allAs.size());
> +            System.out.println("testThreeSegmentsAliasOnSegment2And3() 
> iteration size:" + allAs.size());
> +            while (itr.hasNext())
> +            {
> +                A a = (A) itr.next();
> +                System.out.println("Found A:  " + a.getId() + " " + 
> a.getAAttrib());
> +            }
> +        }
> +        catch (Throwable t)
> +        {
> +            t.printStackTrace(System.out);
> +            fail("testThreeSegmentsAliasOnSegment2And3: " + 
> t.getMessage());
> +        }
> +    }   
> +   
> +    /*
> +     *  Same as above using an explicit UserAlias
> +     */
> +    public void testThreeSegmentsAliasOnSegment2And3UserAlias() throws 
> Exception
> +    {
> +        try
> +        {
> +            UserAlias userAlias1 = new UserAlias("alias1");
> +            userAlias1.add("bSet.cSet");
> +            userAlias1.add("bSet.cSet.d");
> +           
> +            // d1 criteria
> +            Criteria crit1 = new Criteria();
> +            crit1.addEqualTo("bSet.cSet.d.dAttrib", new Integer("10010"));
> +            crit1.setAlias(userAlias1);
> +
> +            // d2 criteria
> +            UserAlias userAlias2 = new UserAlias("alias2");
> +            userAlias1.add("bSet.cSet");
> +            userAlias1.add("bSet.cSet.d");
> +
> +            Criteria crit2 = new Criteria();
> +            crit2.addEqualTo("bSet.cSet.d.dAttrib", new Integer("10110"));
> +            crit2.setAlias(userAlias2);
> +
> +            crit1.addAndCriteria(crit2);
> +
> +            boolean isDistinct = true;
> +            Query query = new QueryByCriteria(A.class, crit1, isDistinct);
> +
> +            Collection allAs = broker.getCollectionByQuery(query);
> +
> +            java.util.Iterator itr = allAs.iterator();
> +
> +            assertEquals(1, allAs.size());
> +            
> System.out.println("testThreeSegmentsAliasOnSegment2And3UserAlias() 
> iteration size:" + allAs.size());
> +            while (itr.hasNext())
> +            {
> +                A a = (A) itr.next();
> +                System.out.println("Found A:  " + a.getId() + " " + 
> a.getAAttrib());
> +            }
> +        }
> +        catch (Throwable t)
> +        {
> +            t.printStackTrace(System.out);
> +            fail("testThreeSegmentsAliasOnSegment2And3UserAlias: " + 
> t.getMessage());
> +        }
> +    }   
> +   
> +   
>      // Inner Classes
> 
>      public static class A
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
> 
> 

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