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 PathTest.java
Date Sat, 22 May 2004 08:37:24 GMT
brj         2004/05/22 01:37:24

  Modified:    src/java/org/apache/ojb/broker/query BetweenCriteria.java
                        SqlCriteria.java ExistsCriteria.java Criteria.java
                        NullCriteria.java SelectionCriteria.java
                        FieldCriteria.java InCriteria.java
                        ValueCriteria.java LikeCriteria.java
               src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlQueryStatement.java
               src/test/org/apache/ojb/broker PathTest.java
  Added:       src/java/org/apache/ojb/broker/query UserAlias.java
  Log:
  query criteria support per path-segment alias (solution by Phil Warrick)
  
  Revision  Changes    Path
  1.10      +13 -6     db-ojb/src/java/org/apache/ojb/broker/query/BetweenCriteria.java
  
  Index: BetweenCriteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/BetweenCriteria.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- BetweenCriteria.java	24 Apr 2004 08:25:37 -0000	1.9
  +++ BetweenCriteria.java	22 May 2004 08:37:23 -0000	1.10
  @@ -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. 
  
  
  
  1.8       +3 -3      db-ojb/src/java/org/apache/ojb/broker/query/SqlCriteria.java
  
  Index: SqlCriteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/SqlCriteria.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SqlCriteria.java	4 Apr 2004 23:53:36 -0000	1.7
  +++ SqlCriteria.java	22 May 2004 08:37:23 -0000	1.8
  @@ -18,7 +18,7 @@
   /**
    * SelectionCriteria for free form sql "REVERSE(name) like 're%'"
    * 
  - * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
  + * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
    * @version $Id$
    */
   public class SqlCriteria extends SelectionCriteria
  @@ -30,7 +30,7 @@
        */
       SqlCriteria(String anSqlStatement)
       {
  -        super(anSqlStatement, null, null);
  +        super(anSqlStatement, null, (String)null);
       }
   
       /*
  
  
  
  1.7       +3 -3      db-ojb/src/java/org/apache/ojb/broker/query/ExistsCriteria.java
  
  Index: ExistsCriteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/ExistsCriteria.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ExistsCriteria.java	4 Apr 2004 23:53:36 -0000	1.6
  +++ ExistsCriteria.java	22 May 2004 08:37:23 -0000	1.7
  @@ -18,7 +18,7 @@
   /**
    * SelectionCriteria for [not] exists(sub query)
    * 
  - * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
  + * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
    * @version $Id$
    */
   public class ExistsCriteria extends SelectionCriteria
  @@ -31,7 +31,7 @@
        */
       ExistsCriteria(Query subQuery, boolean negative)
       {
  -        super("", subQuery, null);
  +        super("", subQuery, (String)null);
           m_negative = negative;
       }
   
  
  
  
  1.45      +211 -63   db-ojb/src/java/org/apache/ojb/broker/query/Criteria.java
  
  Index: Criteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/Criteria.java,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- Criteria.java	24 Apr 2004 08:25:37 -0000	1.44
  +++ Criteria.java	22 May 2004 08:37:23 -0000	1.45
  @@ -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
  
  
  
  1.9       +12 -7     db-ojb/src/java/org/apache/ojb/broker/query/NullCriteria.java
  
  Index: NullCriteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/NullCriteria.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- NullCriteria.java	4 Apr 2004 23:53:36 -0000	1.8
  +++ NullCriteria.java	22 May 2004 08:37:23 -0000	1.9
  @@ -18,22 +18,27 @@
   /**
    * SelectionCriteria for 'is null' and 'is not null'
    * 
  - * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
  + * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
    * @version $Id$
    */
   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);
  +	}
  +
  +	NullCriteria(String anAttribute, String aClause, UserAlias anAlias)
  +	{
  +		super(anAttribute, null, aClause, anAlias);
  +	}
   
       public String toString()
       {
           return getAttribute() + getClause();
       }
   
  -    /*
  +    /**
        * @see SelectionCriteria#isBound()
        */
       public boolean isBound()
  
  
  
  1.17      +63 -11    db-ojb/src/java/org/apache/ojb/broker/query/SelectionCriteria.java
  
  Index: SelectionCriteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/SelectionCriteria.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- SelectionCriteria.java	24 Apr 2004 08:25:37 -0000	1.16
  +++ SelectionCriteria.java	22 May 2004 08:37:23 -0000	1.17
  @@ -28,7 +28,7 @@
   
    * @author DB Harvey-George
    * @author Thomas Mahler
  - * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
  + * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
    * @version $Id$
    */
   public abstract class SelectionCriteria implements java.io.Serializable
  @@ -56,10 +56,11 @@
   	private boolean m_bound = false;
   
   	// BRJ: the criterion must be bound for the main class and for all extents
  -	private int m_numberOfExtentsToBind = 0; // BRJ: 
  +	private int m_numberOfExtentsToBind = 0; 
   
   	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 +76,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)
  +	{
  +		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 +212,42 @@
   	}
   
   	/**
  +	 * 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;
  +		String attributePath = (String)getAttribute();
  +		boolean allPathsAliased = true;
  +		m_userAlias = new UserAlias(alias, attributePath, allPathsAliased);
  +		
  +	}
  +
  +	/**
   	 * 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);
  +	}
  +	
  +	/**
  +	 * 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
   	 */
  @@ -243,7 +297,6 @@
   	 * A Map containing hints about what Class to be used for what path segment
   	 * @return Returns a Map
   	 */
  -	// PAW
   	public Map getPathClasses()
   	{
   		return getCriteria().getPathClasses();
  @@ -262,5 +315,4 @@
   		return getCriteria().getClassesForPath(aPath);
   	}
       
  -
   }
  
  
  
  1.9       +24 -9     db-ojb/src/java/org/apache/ojb/broker/query/FieldCriteria.java
  
  Index: FieldCriteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/FieldCriteria.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- FieldCriteria.java	4 Apr 2004 23:53:36 -0000	1.8
  +++ FieldCriteria.java	22 May 2004 08:37:23 -0000	1.9
  @@ -18,37 +18,49 @@
   /**
    * Abstract superclass for Criteria using a field to compare with
    * 
  - * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
  + * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
    * @version $Id$
    */
   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,7 +77,9 @@
   	 * @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);
           m_clause = aClause;
  @@ -103,3 +117,4 @@
           return m_clause;
       }
   }
  +
  
  
  
  1.11      +11 -6     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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- InCriteria.java	4 Apr 2004 23:53:36 -0000	1.10
  +++ InCriteria.java	22 May 2004 08:37:23 -0000	1.11
  @@ -20,15 +20,20 @@
   /**
    * SelectionCriteria for 'in (a,b,c..)'
    * 
  - * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
  + * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
    * @version $Id$
    */
   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);
  +	}
  + 
  +	InCriteria(Object anAttribute, Object aValue, String aClause, UserAlias anAlias)
  +	{
  +		super(anAttribute, aValue, aClause, anAlias);
  +	}
    
   	/**
   	 * @see org.apache.ojb.broker.query.SelectionCriteria#isBindable()
  
  
  
  1.8       +154 -84   db-ojb/src/java/org/apache/ojb/broker/query/ValueCriteria.java
  
  Index: ValueCriteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/ValueCriteria.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ValueCriteria.java	4 Apr 2004 23:53:36 -0000	1.7
  +++ ValueCriteria.java	22 May 2004 08:37:23 -0000	1.8
  @@ -24,94 +24,164 @@
    */ 
   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);
  +	}
  +	
  +	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;
  +	}
       
  -
  -    /* (non-Javadoc)
  +	/**
  +	 * 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
  +	 */
  +	ValueCriteria(Object anAttribute, Object aValue, String aClause, UserAlias aUserAlias)
  +	{
  +		super(anAttribute, aValue, aUserAlias);
  +		m_clause = aClause;
  +	}
  +    
  +    /**
        * @see org.apache.ojb.broker.query.SelectionCriteria#getClause()
        */
       public String getClause()
  
  
  
  1.9       +22 -11    db-ojb/src/java/org/apache/ojb/broker/query/LikeCriteria.java
  
  Index: LikeCriteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/LikeCriteria.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- LikeCriteria.java	4 Apr 2004 23:53:36 -0000	1.8
  +++ LikeCriteria.java	22 May 2004 08:37:23 -0000	1.9
  @@ -34,16 +34,27 @@
   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
  +	 */
  +	public LikeCriteria(Object anAttribute, Object aValue, String aClause, UserAlias anAlias)
  +	{
  +		super(anAttribute, generateSQLSearchPattern((String) aValue), aClause, anAlias);
  +	}
   
       /**
        * The Character used for Escaping Wildcards
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/query/UserAlias.java
  
  Index: UserAlias.java
  ===================================================================
  package org.apache.ojb.broker.query;
  
  /* Copyright 2002-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  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;
  
  /**
   * 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
   * 
   * @author <a href="mailto:philip.warrick@mcgill.ca">Phil Warrick</a> 
   */
  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);
      }
  }
  
  
  1.74      +28 -57    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.73
  retrieving revision 1.74
  diff -u -r1.73 -r1.74
  --- SqlQueryStatement.java	6 May 2004 19:46:40 -0000	1.73
  +++ SqlQueryStatement.java	22 May 2004 08:37:24 -0000	1.74
  @@ -152,7 +152,7 @@
   	 * @param pathClasses
   	 * @return ColumnInfo
   	 */
  -	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 +192,7 @@
   				/**
   				 * pathName might be an alias, so check this first
   				 */
  -				tableAlias = getTableAlias(null, useOuterJoins, pathName, null, pathClasses);
  +				tableAlias = getTableAlias(pathName, useOuterJoins, new UserAlias(pathName, pathName, pathName), null, pathClasses);
   			}
   
   			if (tableAlias != null)
  @@ -421,7 +421,7 @@
        * @param buf
        * @return
        */
  -    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());
  @@ -445,7 +445,7 @@
        * @param buf
        * @return
        */
  -    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 ?
  @@ -664,7 +664,7 @@
   
           if (c.isTranslateField())
           {
  -            appendColName((String) c.getValue(), false, c.getAlias(), buf);
  +			appendColName((String) c.getValue(), false, c.getUserAlias(), buf);
           }
           else
           {
  @@ -827,7 +827,7 @@
               return;
           }
   
  -		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 +924,7 @@
   	 * 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)
  +	private TableAlias getTableAlias(String aPath, boolean useOuterJoins, UserAlias aUserAlias, String[] fieldRef, Map pathClasses)
   	{
   		TableAlias curr, prev, indirect;
   		String attr, attrPath = null;
  @@ -937,7 +937,8 @@
   		boolean outer = useOuterJoins;
   		int pathLength;
   
  -		curr = getTableAliasForPath(aPath, aUserAlias);
  +		String pathAlias = aUserAlias == null ? null : aUserAlias.getAlias(aPath); 
  +		curr = getTableAliasForPath(aPath, pathAlias);
   
   		if (curr != null)
   		{
  @@ -1000,12 +1001,11 @@
   				else
   				{
   					String mnAttrPath = attrPath + "*";
  -					String mnPath = aPath + "*";
   					String mnUserAlias = (aUserAlias == null ? null : aUserAlias + "*");
  -					indirect = getTableAliasForPath(mnAttrPath, mnUserAlias, mnPath);
  +					indirect = getTableAliasForPath(mnAttrPath, mnUserAlias);
   					if (indirect == null)
   					{
  -						indirect = createTableAlias(cod.getIndirectionTable(), mnAttrPath, mnUserAlias, mnPath);
  +						indirect = createTableAlias(cod.getIndirectionTable(), mnAttrPath, mnUserAlias);
   
   						// we need two Joins for m:n
   						// 1.) prev class to indirectionTable
  @@ -1023,7 +1023,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 +1052,13 @@
   				}
   			}
   
  -			curr = getTableAliasForPath(attrPath, aUserAlias, aPath);
  +			pathAlias = aUserAlias == null ? null : aUserAlias.getAlias(attrPath); 
  +			curr = getTableAliasForPath(attrPath, pathAlias);
   
   			if (curr == null)
   			{
   				List hintClasses = (List) pathClasses.get(aPath);
  -				curr = createTableAlias(cld, attrPath, aUserAlias, aPath, hintClasses);
  +				curr = createTableAlias(cld, attrPath, pathAlias, hintClasses);
   
   				outer = outer || (curr.cld == prev.cld) || curr.hasExtents() || useOuterJoins;
   				addJoin(prev, prevKeys, curr, keys, outer, attr);
  @@ -1068,6 +1069,8 @@
   			prev = curr;
   		}
   
  +		// PAW
  +		m_logger.debug("Result of getTableAlias(): " + curr);
   		return curr;
   	}
   
  @@ -1172,13 +1175,11 @@
        * @param aCld
        * @param aPath
        * @param aUserAlias
  -     * @param anOriginalPath
        * @param hints a List os Class objects to be used as hints for path expressions
        * @return TableAlias
        *
        */
  -    private TableAlias createTableAlias(ClassDescriptor aCld, String aPath, String aUserAlias, String anOriginalPath,
  -            List hints)
  +    private TableAlias createTableAlias(ClassDescriptor aCld, String aPath, String aUserAlias, List hints)
       {
   		if (aUserAlias == null)
   		{
  @@ -1194,7 +1195,7 @@
        * Create new TableAlias for path
        * @param cld the class descriptor for the TableAlias
        * @param path the path from the target table of the query to this TableAlias.
  -     * @@param hints a List of Class objects to be used on path expressions
  +     * @param hints a List of Class objects to be used on path expressions
        */
       private TableAlias createTableAlias(ClassDescriptor cld, List hints, String path)
       {
  @@ -1210,7 +1211,6 @@
           alias = new TableAlias(cld, aliasName, lookForExtents, hints);
   
           m_pathToAlias.put(path, alias);
  -//        m_cldToAlias.put(cld, alias);
           
           return alias;
       }
  @@ -1220,10 +1220,9 @@
        * @param aTable
        * @param aPath
        * @param aUserAlias
  -     * @param anOriginalPath
        * @return TableAlias
        */
  -    private TableAlias createTableAlias(String aTable, String aPath, String aUserAlias, String anOriginalPath)
  +    private TableAlias createTableAlias(String aTable, String aPath, String aUserAlias)
       {
   		if (aUserAlias == null)
   		{
  @@ -1252,6 +1251,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;
       }
  @@ -1294,44 +1295,13 @@
           }
       }
   
  -    /**
  -     * Answer the TableAlias for aPath or aUserAlias
  -     * @param aPath
  -     * @param aUserAlias
  -     * @param anOriginalPath
  -     * @return TableAlias, null if none
  -     */
  -    private TableAlias getTableAliasForPath(String aPath, String aUserAlias, String anOriginalPath)
  -    {
  -        // BRJ: solves problem with multi-segment-path 
  -        // if (aUserAlias == null || !anOriginalPath.equals(aPath))
  -        if (aUserAlias == null)
  -        {
  -            return getTableAliasForPath(aPath);
  -        }
  -        else
  -        {
  -			return getTableAliasForPath(aUserAlias + aPath);
  -        }
  -    }
  -
   	/**
   	 * TODO: add super ClassDescriptor
   	 * answer the ClassDescriptor for itemClass for an ObjectReferenceDescriptor
   	 * check optional hint;
   	 */
   	private ClassDescriptor getItemClassDescriptor(ObjectReferenceDescriptor ord, String attr, Map pathClasses)
  -	{
  -		/* PAW
  -		List itemClasses = null;
  -		Query q = getQuery();
  -
  -		if (q instanceof QueryByCriteria)
  -		{
  -			  itemClasses = ((QueryByCriteria) q).getClassesForPath(attr);
  -		}
  -		*/
  -	    
  +	{   
   		List itemClasses = (List)pathClasses.get(attr);
   
   		if (itemClasses == null)
  @@ -1580,12 +1550,13 @@
                   // 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.getUserAlias(), c.getPathClasses());
                   }
               }
           }
  @@ -1596,7 +1567,7 @@
   	 * 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, UserAlias aUserAlias, Map pathClasses)
   	{
   		String pathName = SqlHelper.cleanPath(aColName);
   		int sepPos = pathName.lastIndexOf(".");
  @@ -1779,7 +1750,7 @@
               boolean useHintsOnExtents = false;
   
               // BRJ: store alias map of in enclosing class
  -			m_cldToAlias.put(aCld, this);
  +			SqlQueryStatement.this.m_cldToAlias.put(aCld, this);
   			
               //LEANDRO: use hints
               if (hints != null && hints.size() > 0)
  
  
  
  1.2       +390 -10   db-ojb/src/test/org/apache/ojb/broker/PathTest.java
  
  Index: PathTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/PathTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PathTest.java	24 Apr 2004 08:25:38 -0000	1.1
  +++ PathTest.java	22 May 2004 08:37:24 -0000	1.2
  @@ -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");
  +			userAlias2.add("bSet.cSet");
  +			userAlias2.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


Mime
View raw message