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 release-notes.txt
Date Wed, 15 Sep 2004 17:18:45 GMT
brj         2004/09/15 10:18:45

  Modified:    src/java/org/apache/ojb/broker/core
                        PersistenceBrokerImpl.java
               src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlQueryStatement.java
               src/java/org/apache/ojb/broker/query Criteria.java
                        Query.java QueryByExample.java
                        SelectionCriteria.java QueryByCriteria.java
                        AbstractQueryImpl.java ValueCriteria.java
               src/test/org/apache/ojb/broker QueryTest.java
               src/java/org/apache/ojb/broker/accesslayer
                        StatementManager.java
               src/java/org/apache/ojb/broker/util BrokerHelper.java
               .        release-notes.txt
  Added:       src/java/org/apache/ojb/broker/query AbstractCriterion.java
                        IdentityCriterion.java Criterion.java
  Log:
  add support for new IdentityCriterion
  see QueryTest#testIdentity...
  
  Revision  Changes    Path
  1.92      +3 -6      db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java,v
  retrieving revision 1.91
  retrieving revision 1.92
  diff -u -r1.91 -r1.92
  --- PersistenceBrokerImpl.java	14 Sep 2004 16:16:35 -0000	1.91
  +++ PersistenceBrokerImpl.java	15 Sep 2004 17:18:44 -0000	1.92
  @@ -1942,15 +1942,12 @@
       private OJBIterator getRsIteratorFromQuery(Query query, ClassDescriptor cld, RsIteratorFactory factory)
           throws PersistenceBrokerException
       {
  +        query.preprocess(this);
  +        
           if (query instanceof QueryBySQL)
           {
               if(logger.isDebugEnabled()) logger.debug("Creating SQL-RsIterator for class ["+cld.getClassNameOfObject()+"]");
               return factory.createRsIterator((QueryBySQL) query, cld, this);
  -        }
  -
  -        if (query instanceof QueryByExample)
  -        {
  -            ((QueryByExample) query).buildCriteria(this);
           }
   
           if (!cld.isExtent() || !query.getWithExtents())
  
  
  
  1.82      +150 -83   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.81
  retrieving revision 1.82
  diff -u -r1.81 -r1.82
  --- SqlQueryStatement.java	4 Sep 2004 17:02:09 -0000	1.81
  +++ SqlQueryStatement.java	15 Sep 2004 17:18:44 -0000	1.82
  @@ -23,6 +23,7 @@
   import java.util.List;
   import java.util.Map;
   
  +import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.PersistenceBrokerSQLException;
   import org.apache.ojb.broker.accesslayer.JoinSyntaxTypes;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
  @@ -602,75 +603,98 @@
       }
   
       /**
  -     * create SQL-String based on Criteria
  +     * create SQL-String based on SelectionCriteria
        * @param crit
        * @return
        */
  -    private String asSQLStatement(Criteria crit)
  +    private void asSQLStatement(SelectionCriteria crit, StringBuffer buf)
       {
  -        Enumeration e = crit.getElements();
  -        StringBuffer statement = new StringBuffer();
  +        if (buf.length() > 0)
  +        {
  +            buf.insert(0, "(");
  +            buf.append(") AND ");
  +        }
  +        
  +        appendSQLClause(crit, buf);
  +        
  +    }
   
  -        while (e.hasMoreElements())
  +    /**
  +     * create SQL-String based on Selection
  +     * @param crit
  +     * @return
  +     */
  +    private void asSQLStatement(Criteria crit, StringBuffer buf)
  +    {
  +        if (crit.isEmpty())
           {
  -            Object o = e.nextElement();
  -            if (o instanceof Criteria)
  -            {
  -                Criteria pc = (Criteria) o;
  -                
  -                if (pc.isEmpty())
  -                {
  -                    continue;	//skip empty criteria
  -                }
  -                
  -                String addAtStart = "";
  -                String addAtEnd = "";
  +            return;		//skip empty criteria
  +        }
  +        
  +        String addAtStart = "";
  +        String addAtEnd = "";
   
  -                // need to add parenthesises?
  -                if (pc.isEmbraced())
  -                {
  -                    addAtStart = " (";
  -                    addAtEnd = ")";
  -                }    
  +        // need to add parenthesises?
  +        if (crit.isEmbraced())
  +        {
  +            addAtStart = " (";
  +            addAtEnd = ")";
  +        }    
   
  -                switch (pc.getType())
  +        switch (crit.getType())
  +        {
  +            case (Criteria.OR) :
                   {
  -                    case (Criteria.OR) :
  -                        {
  -                            if (statement.length() > 0)
  -                            {
  -                                statement.append(" OR ");
  -                            }
  -                            statement.append(addAtStart);
  -                            statement.append(asSQLStatement(pc));
  -                            statement.append(addAtEnd);
  -                            break;
  -                        }
  -                    case (Criteria.AND) :
  -                        {
  -                            if (statement.length() > 0)
  -                            {
  -                                statement.insert(0, "( ");
  -                                statement.append(") AND ");
  -                            }
  -                            statement.append(addAtStart);
  -                            statement.append(asSQLStatement(pc));
  -                            statement.append(addAtEnd);
  -                            break;
  -                        }
  +                    if (buf.length() > 0)
  +                    {
  +                        buf.append(" OR ");
  +                    }
  +                    buf.append(addAtStart);
  +                    buf.append(asSQLStatement(crit));
  +                    buf.append(addAtEnd);
  +                    break;
                   }
  +            case (Criteria.AND) :
  +                {
  +                    if (buf.length() > 0)
  +                    {
  +                        buf.insert(0, "( ");
  +                        buf.append(") AND ");
  +                    }
  +                    buf.append(addAtStart);
  +                    buf.append(asSQLStatement(crit));
  +                    buf.append(addAtEnd);
  +                    break;
  +                }
  +        }
  +    }
  +
  +    /**
  +     * create SQL-String based on Criteria
  +     * @param crit
  +     * @return
  +     */
  +    private String asSQLStatement(Criteria crit)
  +    {
  +        StringBuffer statement = new StringBuffer();
  +        Iterator iter = crit.getIterator();
  +
  +        while (iter.hasNext())
  +        {
  +            Object c = iter.next();
  +            if (c instanceof Criteria)
  +            {
  +                asSQLStatement((Criteria) c, statement);
  +            }
  +            else if (c instanceof SelectionCriteria)
  +            {
  +                asSQLStatement((SelectionCriteria) c, statement);
               }
               else
               {
  -                SelectionCriteria c = (SelectionCriteria) o;
  -                if (statement.length() > 0)
  -                {
  -                    statement.insert(0, "(");
  -                    statement.append(") AND ");
  -                }
  -                appendSQLClause(c, statement);
  +                throw new PersistenceBrokerException("Don't know how to handle Criteria: " + c);
               }
  -        } // while
  +        } 
   
           // BRJ : negative Criteria surrounded by NOT (...)
           if (crit.isNegative())
  @@ -678,6 +702,7 @@
               statement.insert(0, " NOT (");
               statement.append(")");
           }
  +        
           return (statement.length() == 0 ? null : statement.toString());
       }
   
  @@ -892,6 +917,19 @@
               return;
           }
   
  +        // BRJ : handle IdentityCriteria
  +        if (c instanceof IdentityCriterion)
  +        {
  +            IdentityCriterion idc = (IdentityCriterion) c;
  +            Iterator iter = idc.getCriteriaList().iterator();
  +            
  +            while (iter.hasNext())
  +            {
  +                asSQLStatement((SelectionCriteria)iter.next(), buf);              
  +            }
  +            return;
  +        }
  +        
   		AttributeInfo attrInfo = getAttributeInfo((String) c.getAttribute(), false, c.getUserAlias(), c.getPathClasses());
           TableAlias alias = attrInfo.tableAlias;
   
  @@ -1576,44 +1614,73 @@
       }
   
       /**
  +     * Build Join Tree for SelectionCriteria
  +     * @param crit
  +     * @param useOuterJoin
  +     */
  +    private void buildJoinTree(SelectionCriteria crit, boolean useOuterJoin)
  +    {
  +        // ignore SqlCriteria
  +        if (crit instanceof SqlCriteria)
  +        {
  +            return;
  +        }
  +
  +        // handle IdentityCriteria as a collection of SelectionCriteria
  +        if (crit instanceof IdentityCriterion)
  +        {
  +            IdentityCriterion idc = (IdentityCriterion) crit;
  +            Iterator idIter = idc.getCriteriaList().iterator();
  +            
  +            while (idIter.hasNext())
  +            {
  +                buildJoinTree((SelectionCriteria) idIter.next(), useOuterJoin);
  +            }
  +            
  +            return;
  +        }
  +        
  +        // do not build join tree for subQuery attribute                  
  +        if (crit.getAttribute() != null && crit.getAttribute() instanceof String)
  +        {
  +			buildJoinTreeForColumn((String) crit.getAttribute(), 
  +			        useOuterJoin, crit.getUserAlias(), crit.getPathClasses());
  +        }
  +        
  +        // handle the referenced Field
  +        if (crit instanceof FieldCriteria)
  +        {
  +            FieldCriteria cc = (FieldCriteria) crit;
  +			buildJoinTreeForColumn((String) cc.getValue(), useOuterJoin, crit.getUserAlias(), crit.getPathClasses());
  +        }
  +            
  +    }    
  +        
  +    /**
        * Build the tree of joins for the given criteria
        */
       private void buildJoinTree(Criteria crit)
       {
  -        Enumeration e = crit.getElements();
  +        Iterator iter = crit.getIterator();
   
  -        while (e.hasMoreElements())
  +        while (iter.hasNext())
           {
  -            Object o = e.nextElement();
  -            if (o instanceof Criteria)
  +            Object c = iter.next();
  +            if (c instanceof Criteria)
               {
  -                buildJoinTree((Criteria) o);
  +                buildJoinTree((Criteria) c);
               }
  -            else
  +            else if (c instanceof SelectionCriteria)
               {
  -                SelectionCriteria c = (SelectionCriteria) o;
  -                
  -                // BRJ skip SqlCriteria
  -                if (c instanceof SqlCriteria)
  -                {
  -                    continue;
  -                }
  -                
  -                // BRJ: Outer join for OR
                   boolean useOuterJoin = (crit.getType() == Criteria.OR);
  -
  -                // 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.getUserAlias(), c.getPathClasses());
  -                }
  -                if (c instanceof FieldCriteria)
  -                {
  -                    FieldCriteria cc = (FieldCriteria) c;
  -					buildJoinTreeForColumn((String) cc.getValue(), useOuterJoin, c.getUserAlias(), c.getPathClasses());
  -                }
  +                
  +                buildJoinTree((SelectionCriteria) c, useOuterJoin);
  +            }
  +            else
  +            {
  +                throw new PersistenceBrokerException("Don't know how to handle Criteria: " + c);
               }
  +            
           }
       }
   
  
  
  
  1.49      +116 -117  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.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- Criteria.java	7 Aug 2004 13:13:05 -0000	1.48
  +++ Criteria.java	15 Sep 2004 17:18:44 -0000	1.49
  @@ -17,6 +17,7 @@
   
   import java.util.ArrayList;
   import java.util.Collection;
  +import java.util.Collections;
   import java.util.Enumeration;
   import java.util.HashMap;
   import java.util.Iterator;
  @@ -24,9 +25,10 @@
   import java.util.Map;
   import java.util.Vector;
   
  +import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
  -import org.apache.ojb.broker.metadata.FieldHelper;
   import org.apache.ojb.broker.core.PersistenceBrokerConfiguration;
  +import org.apache.ojb.broker.metadata.FieldHelper;
   import org.apache.ojb.broker.util.configuration.ConfigurationException;
   
   /**
  @@ -45,7 +47,7 @@
    * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
    * @version $Id$
    */
  -public class Criteria implements java.io.Serializable
  +public class Criteria extends AbstractCriterion
   {
       static final long serialVersionUID = 7384550404778187808L;
   
  @@ -59,33 +61,24 @@
       /** prefix to identify attributes referencing enclosing query */
       public static final String PARENT_QUERY_PREFIX = "parentQuery.";
   
  -    private Vector m_criteria;
  +    private List m_criteria;
       private int m_type;
       private boolean m_embraced;
       private boolean m_negative = false;
   
       // holding CriteriaFields for orderBy and groupBy
  -    private List orderby = null;
  -    private List groupby = null;
  -    private List prefetchedRelationships = null;
  -
  -	// an optional alias to be used for this criteria
  -	private String m_alias = null;
  +    private List m_orderby = null;
  +    private List m_groupby = null;
  +    private List m_prefetchedRelationships = null;
   
  -	// 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;
  -    private Criteria m_parentCriteria;
   
  -    // PAW
   	// hint classes for paths of this criteria
   	private Map m_pathClasses;
   
  @@ -94,10 +87,10 @@
        */
       public Criteria()
       {
  -        m_criteria = new Vector();
  -        groupby = new ArrayList();
  -        orderby = new ArrayList();
  -        prefetchedRelationships = new ArrayList();
  +        m_criteria = new ArrayList();
  +        m_groupby = new ArrayList();
  +        m_orderby = new ArrayList();
  +        m_prefetchedRelationships = new ArrayList();
           m_type = NONE;
           m_embraced = false;
           // PAW
  @@ -105,7 +98,8 @@
       }
   
       /**
  -     * Constructor with a SelectionCriteria
  +     * Constructor with a SelectionCriteria.
  +     * 
        * @param aSelectionCriteria SelectionCriteria
        */
       public Criteria(SelectionCriteria aSelectionCriteria)
  @@ -115,45 +109,45 @@
       }
   
       /**
  -     * make a copy of the criteria
  +     * Copy Constructor.
  +     * 
  +     * @param aCriteria Criteria
        * @param includeGroupBy if true (groupBy is deprecated)
        * @param includeOrderBy if ture (orderBy is deprecated)
        * @param includePrefetchedRelationships if true (prefectchedRel. is deprecated)
        * @return a copy of the criteria
        */
  -    public Criteria copy(boolean includeGroupBy, boolean includeOrderBy, boolean includePrefetchedRelationships)
  +    public Criteria(Criteria aCriteria, boolean includeGroupBy, boolean includeOrderBy, boolean includePrefetchedRelationships)
       {
  -        Criteria copy = new Criteria();
  -
  -        copy.m_criteria = new Vector(this.m_criteria);
  -        copy.m_negative = this.m_negative;
  +        this();
  +        
  +        m_criteria = new Vector(aCriteria.m_criteria);
  +        m_negative = aCriteria.m_negative;
   
           if (includeGroupBy)
           {
  -            copy.groupby = this.groupby;
  +            m_groupby = aCriteria.m_groupby;
           }
           if (includeOrderBy)
           {
  -            copy.orderby = this.orderby;
  +            m_orderby = aCriteria.m_orderby;
           }
           if (includePrefetchedRelationships)
           {
  -            copy.prefetchedRelationships = this.prefetchedRelationships;
  +            m_prefetchedRelationships = aCriteria.m_prefetchedRelationships;
           }
  -
  -        return copy;
       }
   
       protected void addSelectionCriteria(SelectionCriteria selectionCrit)
       {
  -        selectionCrit.setCriteria(this);
  -        m_criteria.addElement(selectionCrit);
  +        selectionCrit.setParentCriterion(this);
  +        m_criteria.add(selectionCrit);
       }
   
       protected void addCriteria(Criteria crit)
       {
  -        crit.setParentCriteria(this);
  -        m_criteria.addElement(crit);
  +        crit.setParentCriterion(this);
  +        m_criteria.add(crit);
       }
   
       protected void addCriteria(Vector criteria)
  @@ -214,14 +208,10 @@
       {
           if (negative)
           {
  -        	// PAW
  -			// return ValueCriteria.buildNotInCriteria(attribute, values, getAlias());
   			return ValueCriteria.buildNotInCriteria(attribute, values, getUserAlias(attribute));
           }
           else
           {
  -			// PAW
  -			// return ValueCriteria.buildInCriteria(attribute, values, getAlias());
   			return ValueCriteria.buildInCriteria(attribute, values, getUserAlias(attribute));
           }
       }
  @@ -232,14 +222,23 @@
        */
       public Enumeration getElements()
       {
  -        return getCriteria().elements();
  +        return Collections.enumeration(getCriteria());
       }
   
       /**
  -     * Get a Vector with all sub criteria
  -     * @return Vector
  +     * Get an Iterator with all sub criteria
  +     * @return Iterator
  +     */
  +    public Iterator getIterator()
  +    {
  +        return getCriteria().iterator();
  +    }
  +    
  +    /**
  +     * Get a List with all sub criteria
  +     * @return List
        */
  -    protected Vector getCriteria()
  +    protected List getCriteria()
       {
           return m_criteria;
       }
  @@ -295,6 +294,7 @@
           return this;
       }
   
  +    
       /**
        * Adds and equals (=) criteria,
        * CUST_ID = 10034
  @@ -625,7 +625,7 @@
        */
       protected List _getOrderby()
       {
  -        return orderby;
  +        return m_orderby;
       }
   
       /**
  @@ -900,6 +900,32 @@
       }
   
       /**
  +     * Adds and equals (=) criteria for an identity
  +     * customer = Identity()
  +     *
  +     * @param  attribute   The field name to be used
  +     * @param  value       An object representing the value of the field
  +     */
  +    public Criteria addIdentityEqualTo(String attribute, Object value)
  +    {
  +		addSelectionCriteria(IdentityCriterion.buildEqualToCriteria(attribute, value, getUserAlias(attribute)));
  +        return this;
  +    }
  +
  +    /**
  +     * Adds and equals (!=) criteria for an identity
  +     * customer != Identity()
  +     *
  +     * @param  attribute   The field name to be used
  +     * @param  value       An object representing the value of the field
  +     */
  +    public Criteria addIdentityNotEqualTo(String attribute, Object value)
  +    {
  +		addSelectionCriteria(IdentityCriterion.buildNotEqualToCriteria(attribute, value, getUserAlias(attribute)));
  +        return this;
  +    }
  +    
  +    /**
        * Answer true if no sub criteria available
        * @return boolean
        */
  @@ -938,7 +964,7 @@
        */
       protected List _getGroupby()
       {
  -        return groupby;
  +        return m_groupby;
       }
   
       /**
  @@ -986,7 +1012,7 @@
        */
       List getPrefetchedRelationships()
       {
  -        return prefetchedRelationships;
  +        return m_prefetchedRelationships;
       }
   
       /**
  @@ -1017,46 +1043,31 @@
       }
   
   	/**
  -	 * @return String
  -	 */
  -	public String getAlias()
  -	{
  -		return m_alias;
  -	}
  -
  -	/**
  -	 * @return String
  -	 */
  -	public UserAlias getUserAlias()
  -	{
  -		return m_userAlias;
  -	}
  -
  -	/**
   	 * Retrieves or if necessary, creates a user alias to be used
  -	 * by a child criteria 
  +	 * by a child criteria .
   	 * @param attribute The alias to set
   	 */
   	private UserAlias getUserAlias(Object attribute)
   	{
  -		if (m_userAlias != null)
  +		if (getUserAlias() != null)
   		{
  -			return m_userAlias;
  +			return getUserAlias();
   		}
  -		if (!(attribute instanceof String))
  +		else if (!(attribute instanceof String))
   		{	
   			return null;
   		}
  -		if (m_alias == null)
  +		else if (getAlias() == null)
   		{
   			return null;
   		}
   		if (m_aliasPath == null)
   		{
   			boolean allPathsAliased = true;
  -			return new UserAlias(m_alias, (String)attribute, allPathsAliased);
  +			return new UserAlias(getAlias(), (String)attribute, allPathsAliased);
   		}
  -		return new UserAlias(m_alias, (String)attribute, m_aliasPath);
  +		
  +		return new UserAlias(getAlias(), (String)attribute, m_aliasPath);
   	}
   
   
  @@ -1064,25 +1075,19 @@
   	 * Sets the alias. Empty String is regarded as null.
   	 * @param alias The alias to set
   	 */
  -	public Criteria setAlias(String alias)
  +	public Criterion setAlias(String alias)
   	{
  -		if (alias == null || alias.trim().equals(""))
  -		{
  -			m_alias = null;
  -		}
  -		else
  -		{
  -			m_alias = alias;
  -		}
  +	    super.setAlias(alias);
   
   		// propagate to SelectionCriteria,not to Criteria
   		for (int i = 0; i < m_criteria.size(); i++)
   		{
  -			if (!(m_criteria.elementAt(i) instanceof Criteria))
  +			if (!(m_criteria.get(i) instanceof Criteria))
   			{
  -				((SelectionCriteria) m_criteria.elementAt(i)).setAlias(m_alias);
  +				((SelectionCriteria) m_criteria.get(i)).setAlias(getAlias());
   			}
   		}
  +		
           return this;
   	}
   
  @@ -1091,24 +1096,18 @@
   	 * @param alias The alias to set
   	 * @param aliasPath The path segment(s) to which the alias applies
   	 */
  -	public Criteria setAlias(String alias, String aliasPath)
  +	public Criterion setAlias(String alias, String aliasPath)
   	{
  -		if (alias == null || alias.trim().equals(""))
  -		{
  -			m_alias = null;
  -		}
  -		else
  -		{
  -			m_alias = alias;
  -			m_aliasPath = aliasPath;
  -		}
  +	    super.setAlias(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))
  +			if (!(m_criteria.get(i) instanceof Criteria))
   			{
  -				((SelectionCriteria) m_criteria.elementAt(i)).setAlias(m_alias, aliasPath);
  +				((SelectionCriteria) m_criteria.get(i)).setAlias(getAlias(), aliasPath);
   			}
   		}
           return this;
  @@ -1118,16 +1117,16 @@
   	 * Sets the alias using a userAlias object. 
   	 * @param userAlias The alias to set
   	 */
  -	public Criteria setAlias(UserAlias userAlias)
  +	public Criterion setAlias(UserAlias userAlias)
   	{
  -		m_alias = userAlias.getName();
  +	    super.setAlias(userAlias);
   
   		// propagate to SelectionCriteria,not to Criteria
   		for (int i = 0; i < m_criteria.size(); i++)
   		{
  -			if (!(m_criteria.elementAt(i) instanceof Criteria))
  +			if (!(m_criteria.get(i) instanceof Criteria))
   			{
  -				((SelectionCriteria) m_criteria.elementAt(i)).setAlias(userAlias);
  +				((SelectionCriteria) m_criteria.get(i)).setAlias(userAlias);
   			}
   		}
           return this;
  @@ -1139,9 +1138,9 @@
        */
       public QueryByCriteria getQuery()
       {
  -        if (getParentCriteria() != null)
  +        if (getParentCriterion() != null)
           {
  -            return getParentCriteria().getQuery();
  +            return getParentCriterion().getQuery();
           }
           else
           {
  @@ -1158,21 +1157,6 @@
           m_query = query;
       }
   
  -    /**
  -     * @return the parent criteria
  -     */
  -    public Criteria getParentCriteria()
  -    {
  -        return m_parentCriteria;
  -    }
  -
  -    /**
  -     * @param criteria
  -     */
  -    void setParentCriteria(Criteria criteria)
  -    {
  -        m_parentCriteria = criteria;
  -    }
   
       /**
        * @see Object#toString()
  @@ -1277,7 +1261,7 @@
   	{
   		if (m_pathClasses.isEmpty())
   		{
  -			if (m_parentCriteria == null)
  +			if (getParentCriterion() == null)
   			{
   				if (m_query == null)
   				{
  @@ -1290,7 +1274,7 @@
   			}
   			else
   			{
  -				return m_parentCriteria.getPathClasses();
  +				return getParentCriterion().getPathClasses();
   			}
   		}
   		else
  @@ -1299,5 +1283,20 @@
   		}
   	}
   
  -
  +    /**
  +     * Preprocess the Criteria using a PersistenceBroker.
  +     * 
  +     * @param aPb the PersistenceBroker
  +     */
  +    public void preprocess(PersistenceBroker aPb)
  +    {
  +        Iterator iter = getIterator();
  +        
  +        while (iter.hasNext())
  +        {
  +            Criterion crit = (Criterion) iter.next();            
  +            crit.preprocess(aPb);
  +        }
  +    }
  +    
   }
  
  
  
  1.18      +10 -1     db-ojb/src/java/org/apache/ojb/broker/query/Query.java
  
  Index: Query.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/Query.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Query.java	4 Apr 2004 23:53:36 -0000	1.17
  +++ Query.java	15 Sep 2004 17:18:44 -0000	1.18
  @@ -2,6 +2,8 @@
   
   import java.util.List;
   
  +import org.apache.ojb.broker.PersistenceBroker;
  +
   /* Copyright 2002-2004 The Apache Software Foundation
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
  @@ -127,6 +129,13 @@
        */
       public List getPrefetchedRelationships();
   
  +    /**
  +     * Preprocess the Query using a PersistenceBroker.
  +     * 
  +     * @param aPb the PersistenceBroker
  +     */
  +    public void preprocess(PersistenceBroker aPb);
  +    
       /**
        * @deprecated 
        * @param size
  
  
  
  1.5       +10 -2     db-ojb/src/java/org/apache/ojb/broker/query/QueryByExample.java
  
  Index: QueryByExample.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/QueryByExample.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- QueryByExample.java	27 Aug 2004 19:55:43 -0000	1.4
  +++ QueryByExample.java	15 Sep 2004 17:18:44 -0000	1.5
  @@ -82,7 +82,7 @@
        * 
        * @param aPb the Broker used to access the repository
        */
  -    public void buildCriteria(PersistenceBroker aPb)
  +    protected void buildCriteria(PersistenceBroker aPb)
       {
           Object example = getExampleObject();
           DescriptorRepository repository = aPb.getConfiguration().getModel();
  @@ -138,5 +138,13 @@
       public void setIgnoreZero(boolean ignoreZero)
       {
           m_ignoreZero = ignoreZero;
  +    }
  +    
  +    /**
  +     * @see org.apache.ojb.broker.query.Query#preprocess(org.apache.ojb.broker.PersistenceBroker)
  +     */
  +    public void preprocess(PersistenceBroker aPb)
  +    {
  +        buildCriteria(aPb);
       }
   }
  
  
  
  1.19      +62 -87    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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- SelectionCriteria.java	16 Jul 2004 00:47:19 -0000	1.18
  +++ SelectionCriteria.java	15 Sep 2004 17:18:44 -0000	1.19
  @@ -31,9 +31,11 @@
    * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
    * @version $Id$
    */
  -public abstract class SelectionCriteria implements java.io.Serializable
  +public abstract class SelectionCriteria extends AbstractCriterion
   {
  -	static final long serialVersionUID = -5194901539702756536L;    protected static final String EQUAL = " = ";
  +	static final long serialVersionUID = -5194901539702756536L;
  +	
  +	protected static final String EQUAL = " = ";
       protected static final String NOT_EQUAL = " <> ";
       protected static final String GREATER = " > ";
       protected static final String NOT_GREATER = " <= ";
  @@ -58,14 +60,10 @@
   	// BRJ: the criterion must be bound for the main class and for all extents
   	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;
  -
  -    private Criteria m_criteria;
  -    
  +   
   	/**
   	 * Constructor declaration
   	 *
  @@ -75,16 +73,7 @@
   	 */
   	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 !");
  -		}    
  -            
  -		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);
  +	    this (anAttribute, aValue, new UserAlias(alias, (String)anAttribute, true));
   	}
   
   	/**
  @@ -104,9 +93,9 @@
               
   		m_attribute = anAttribute;
   		m_value = aValue;
  -		this.m_bound = !isBindable();
  -		this.m_userAlias = aUserAlias;
  -		this.m_alias = m_userAlias == null ? null : m_userAlias.getName();
  +		m_bound = !isBindable();
  +		
  +		setAlias(aUserAlias);
   	}
   
   	/**
  @@ -199,53 +188,8 @@
   	{
   		this.m_numberOfExtentsToBind = numberOfExtentsToBind;
   	}
  -
  -	/**
  -	 * @return String
  -	 */
  -	public String getAlias()
  -	{
  -		return m_alias;
  -	}
  -
  -	/**
  -	 * 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, 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
   	 */
   	public boolean isTranslateAttribute()
  @@ -261,27 +205,16 @@
   		m_translateAttribute = b;
   	}
   
  -	/**
  -	 * @return
  -	 */
  -	public Criteria getCriteria()
  -	{
  -		return m_criteria;
  -	}
  -
  -	/**
  -	 * @param criteria
  +    /**
  +	 * Get the Query of the parent
  +	 * 
  +	 * @see org.apache.ojb.broker.query.Criterion#getQuery()
   	 */
  -	void setCriteria(Criteria criteria)
  -	{
  -		m_criteria = criteria;
  -	}
  -
       public QueryByCriteria getQuery()
       {
  -        if (getCriteria() != null)
  +        if (getParentCriterion() != null)
           {
  -            return getCriteria().getQuery();
  +            return getParentCriterion().getQuery();
           }
           else
           {
  @@ -296,7 +229,14 @@
   	 */
   	public Map getPathClasses()
   	{
  -		return getCriteria().getPathClasses();
  +        if (getParentCriterion() != null)
  +        {    
  +            return getParentCriterion().getPathClasses();
  +        }
  +        else
  +        {
  +            return null;
  +        }
   	}
   
   	/**
  @@ -308,7 +248,42 @@
   	 */
   	public List getClassesForPath(String aPath)
   	{
  -		return getCriteria().getClassesForPath(aPath);
  +        if (getParentCriterion() != null)
  +        {    
  +            return getParentCriterion().getClassesForPath(aPath);
  +        }
  +        else
  +        {
  +            return null;
  +        }
   	}
  -    
  + 
  +    /**
  +     * Sets the alias. By default the entire attribute path participates in the alias
  +     * @param alias   The name of the alias to set
  +     */
  +    public Criterion setAlias(String alias)
  +    {
  +    	String attributePath = (String)getAttribute();
  +    	boolean allPathsAliased = true;
  +
  +    	setAlias(new UserAlias(alias, attributePath, allPathsAliased));
  +    	
  +    	return this;
  +    }
  +
  +    /**
  +     * Sets the alias. 
  +     * @param alias   The alias to set
  +     */
  +    public Criterion setAlias(String alias, String aliasPath)
  +    {
  +    	String attributePath = (String)getAttribute();
  +
  +    	setAlias(new UserAlias(alias, attributePath, aliasPath));
  +    	
  +    	return this;
  +    }
  +   
  +
   }
  
  
  
  1.30      +15 -3     db-ojb/src/java/org/apache/ojb/broker/query/QueryByCriteria.java
  
  Index: QueryByCriteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/QueryByCriteria.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- QueryByCriteria.java	27 Aug 2004 19:55:43 -0000	1.29
  +++ QueryByCriteria.java	15 Sep 2004 17:18:44 -0000	1.30
  @@ -21,6 +21,7 @@
   import java.util.List;
   import java.util.Map;
   
  +import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.FieldHelper;
   import org.apache.ojb.broker.metadata.MetadataManager;
  @@ -133,7 +134,7 @@
           
           if (aQuery.getCriteria() != null)
           {
  -            setCriteria(aQuery.getCriteria().copy(true,true,true));
  +            setCriteria(new Criteria(aQuery.getCriteria(),true,true,true));
           }
           else
           {
  @@ -142,7 +143,7 @@
   
           if (aQuery.getHavingCriteria() != null)
           {
  -            setHavingCriteria(aQuery.getHavingCriteria().copy(true,true,true));
  +            setHavingCriteria(new Criteria(aQuery.getHavingCriteria(),true,true,true));
           }
           else
           {
  @@ -562,4 +563,15 @@
           m_objectProjectionAttribute = objectProjectionAttribute;
           m_searchClass = objectProjectionClass;
   	}
  +    
  +    /**
  +     * @see org.apache.ojb.broker.query.Query#preprocess(org.apache.ojb.broker.PersistenceBroker)
  +     */
  +    public void preprocess(PersistenceBroker aPb)
  +    {
  +        if (getCriteria() != null)
  +        {
  +            getCriteria().preprocess(aPb);
  +        }    
  +    }
   }
  
  
  
  1.16      +11 -1     db-ojb/src/java/org/apache/ojb/broker/query/AbstractQueryImpl.java
  
  Index: AbstractQueryImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/AbstractQueryImpl.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- AbstractQueryImpl.java	27 Aug 2004 19:55:43 -0000	1.15
  +++ AbstractQueryImpl.java	15 Sep 2004 17:18:44 -0000	1.16
  @@ -3,6 +3,8 @@
   import java.io.Serializable;
   import java.util.List;
   
  +import org.apache.ojb.broker.PersistenceBroker;
  +
   /* Copyright 2002-2004 The Apache Software Foundation
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
  @@ -177,5 +179,13 @@
       protected void setSearchClass(Class searchClass)
       {
           m_searchClass = searchClass;
  +    }
  +    
  +    /**
  +     * @see org.apache.ojb.broker.query.Query#preprocess(org.apache.ojb.broker.PersistenceBroker)
  +     */
  +    public void preprocess(PersistenceBroker aPb)
  +    {
  +        // do nothing
       }
   }
  
  
  
  1.10      +3 -3      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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ValueCriteria.java	16 Jul 2004 00:47:19 -0000	1.9
  +++ ValueCriteria.java	15 Sep 2004 17:18:44 -0000	1.10
  @@ -28,7 +28,7 @@
   	{
   		return new ValueCriteria(anAttribute, aValue, EQUAL, anAlias);
   	}
  -	
  +
   	static ValueCriteria buildEqualToCriteria(Object anAttribute, Object aValue, UserAlias anAlias)
   	{
   		return new ValueCriteria(anAttribute, aValue, EQUAL, anAlias);
  @@ -150,7 +150,7 @@
   	{
   		return new BetweenCriteria(anAttribute, aValue1, aValue2, NOT_BETWEEN, anAlias);
   	}
  -    
  +	
       private String m_clause;
   
   	/**
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/query/AbstractCriterion.java
  
  Index: AbstractCriterion.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 org.apache.ojb.broker.PersistenceBroker;
  
  /**
   * Abstract Implementation of Criterion.
   *
   * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
   * @version $Id: AbstractCriterion.java,v 1.1 2004/09/15 17:18:44 brj Exp $
   */
  public abstract class AbstractCriterion implements Criterion
  {
  	// holds the path segment(s) to which the alias applies
  	private UserAlias m_userAlias = null;
  
  	// optional alias
  	private String m_alias = null;
  
  	private Criterion m_parentCriterion = null;
  
      /**
       * @see org.apache.ojb.broker.query.Criterion#preprocess(org.apache.ojb.broker.PersistenceBroker)
       */
      public void preprocess(PersistenceBroker aPb)
      {
          // do nothing
      }
  
      /**
       * @see org.apache.ojb.broker.query.Criterion#getParentCriterion()
       */
      public Criterion getParentCriterion()
      {
          return m_parentCriterion;
      }
  
  	/**
  	 * @param criteria
  	 */
  	protected void setParentCriterion(Criterion parent)
  	{
  		m_parentCriterion = parent;
  	}
      
      /**
       * @see org.apache.ojb.broker.query.Criterion#getUserAlias()
       */
      public UserAlias getUserAlias()
      {
          return m_userAlias;
      }
  
      /**
       * @see org.apache.ojb.broker.query.Criterion#getAlias()
       */
      public String getAlias()
      {
          return m_alias;
      }
  
      /**
       * Sets the alias. an empty String is regarded as null.
       * @param alias
       */
      public Criterion setAlias(String alias)
      {
  		if (alias == null || alias.trim().equals(""))
  		{
  			m_alias = null;
  		}
  		else
  		{    
  		    m_alias = alias;
  		}    
  		
  		return this;
      }
  
      /**
       * Sets the alias using a userAlias object. 
       * @param userAlias   The alias to set
       */
      public Criterion setAlias(UserAlias userAlias)
      {
      	m_userAlias = userAlias;
      	
      	if (userAlias != null)
      	{
      	    m_alias = userAlias.getName();
      	}
      	else
      	{
      	    m_alias = null;
      	}
      	
      	return this;
      }	
  
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/query/IdentityCriterion.java
  
  Index: IdentityCriterion.java
  ===================================================================
  
  package org.apache.ojb.broker.query;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import org.apache.ojb.broker.Identity;
  import org.apache.ojb.broker.PersistenceBroker;
  import org.apache.ojb.broker.metadata.ClassDescriptor;
  import org.apache.ojb.broker.metadata.DescriptorRepository;
  import org.apache.ojb.broker.metadata.FieldDescriptor;
  
  /* 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.
  */
  
  /**
   * Criteria for Identity. 
   * The Identity is translated into a list of ordinary SelectionCriteria reflecting the primary key.
   *
   * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
   * @version $Id: IdentityCriterion.java,v 1.1 2004/09/15 17:18:44 brj Exp $
   */
  public class IdentityCriterion extends SelectionCriteria
  {
  	static IdentityCriterion buildEqualToCriteria(Object anAttribute, Object aValue, String anAlias)
  	{
  		return new IdentityCriterion(anAttribute, aValue, EQUAL, anAlias);
  	}
  
  	static IdentityCriterion buildNotEqualToCriteria(Object anAttribute, Object aValue, String anAlias)
  	{
  		return new IdentityCriterion(anAttribute, aValue, NOT_EQUAL, anAlias);
  	}
  
  	static IdentityCriterion buildEqualToCriteria(Object anAttribute, Object aValue, UserAlias anAlias)
  	{
  		return new IdentityCriterion(anAttribute, aValue, EQUAL, anAlias);
  	}
  
  	static IdentityCriterion buildNotEqualToCriteria(Object anAttribute, Object aValue, UserAlias anAlias)
  	{
  		return new IdentityCriterion(anAttribute, aValue, NOT_EQUAL, anAlias);
  	}
  	
      // the list of SelectionCriteria based on the identity
      private List m_criteriaList;
      private String m_clause;
      
      /**
       * @param anAttribute
       * @param aValue
       * @param alias
       */
      IdentityCriterion(Object anAttribute, Object aValue, String aClause, String alias)
      {
          super(anAttribute, aValue, alias);
          setCriteriaList(new ArrayList());
          setClause(aClause);
      }
      
      /**
       * @param anAttribute
       * @param aValue
       * @param aUserAlias
       */
      IdentityCriterion(Object anAttribute, Object aValue, String aClause, UserAlias aUserAlias)
      {
          super(anAttribute, aValue, aUserAlias);
          setCriteriaList(new ArrayList());
          setClause(aClause);
      }
      
      /**
       * @see org.apache.ojb.broker.query.SelectionCriteria#getClause()
       */
      public String getClause()
      {
          return m_clause;
      }
  
      /**
       * @param clause The clause to set.
       */
      protected void setClause(String clause)
      {
          m_clause = clause;
      }
      
      /**
       * @return Returns the criteriaList.
       */
      public List getCriteriaList()
      {
          return m_criteriaList;
      }
      
      /**
       * @param criteriaList The criteriaList to set.
       */
      protected void setCriteriaList(List criteriaList)
      {
          m_criteriaList = criteriaList;
      }
  
      /**
       * Build SelectionCriteria based on Identity.
       * 
       * @param aPb the Broker used to access the repository
       */
      protected void buildCriteria(PersistenceBroker aPb)
      {
          Identity id = (Identity)getValue();
          DescriptorRepository repository = aPb.getConfiguration().getModel();
          ClassDescriptor cld = repository.getDescriptorFor(id.getObjectsRealClass());
          FieldDescriptor[] pkFields = cld.getPkFields();
          Object[] pkValues = id.getPrimaryKeyValues();
          String attribute = ((String) getAttribute()).trim();
  
          List crits = new ArrayList();
          
          if (attribute != null && attribute.length() > 0)
          {
              attribute = attribute + ".";
          }
          
          for (int i = 0;i < pkFields.length; i++)
          {
              String pkAttribute = attribute + pkFields[i].getAttributeName();
      		ValueCriteria c = new ValueCriteria(pkAttribute, pkValues[i], getClause(), getAlias());
      		
      		c.setParentCriterion(getParentCriterion()); // set the parent
      		crits.add(c);
          }
          
          setCriteriaList(crits);       
      }
      
      /**
       * Preprocess the Criteria using a PersistenceBroker.
       * 
       * @param aPb the PersistenceBroker
       */
      public void preprocess(PersistenceBroker aPb)
      {
          buildCriteria(aPb);
      }
  
  
      /**
       * Always return 0, because the extents are handeld in the enclosed ValueCriteria.
       * @see org.apache.ojb.broker.query.SelectionCriteria#getNumberOfExtentsToBind()
       */
      public int getNumberOfExtentsToBind()
      {
          return 0;
      }
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/query/Criterion.java
  
  Index: Criterion.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.List;
  import java.util.Map;
  
  import org.apache.ojb.broker.PersistenceBroker;
  
  /**
   * Interface for Criterion
   * 
   * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
   * @version $Id: Criterion.java,v 1.1 2004/09/15 17:18:44 brj Exp $
   */
  public interface Criterion extends java.io.Serializable
  {
      /**
       * Preprocess the Criterion using a PersistenceBroker.
       * 
       * @param aPb the PersistenceBroker
       */
      public void preprocess(PersistenceBroker aPb);
      
      /**
       * Return the parent Criterion.
       * 
       * @return the parent Criterion or null
       */
      public Criterion getParentCriterion();
  
      /**
       * Return the Query.
       * 
       * @return the Query
       */
      public QueryByCriteria getQuery();
  
  	/**
  	 * Gets the pathClasses from the parent Criteria.
  	 * A Map containing hints about what Class to be used for what path segment
  	 * 
  	 * @return Returns a Map
  	 */
  	public Map getPathClasses();
      
  	/**
  	 * Get the a List of Class objects used as hints for a path.
  	 *
  	 * @param aPath the path segment ie: allArticlesInGroup
  	 * @return a List o Class objects to be used in SqlStatment
  	 * @see org.apache.ojb.broker.QueryTest#testInversePathExpression()
  	 */
  	public List getClassesForPath(String aPath);
  
  	/**
  	 * Get the Alias for this Criterion.
  	 * 
  	 * @return UserAlias
  	 */
  	public UserAlias getUserAlias();
  
  	/**
  	 * Get the Alias for this Criterion.
  	 * 
  	 * @return String
  	 */
  	public String getAlias();
  
  	/**
  	 * Sets the alias. Empty String is regarded as null.
  	 * @param alias The alias to set
  	 */
  	public Criterion setAlias(String alias);
  
  	/**
  	 * 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 Criterion setAlias(String alias, String aliasPath);
  
  	/**
  	 * Sets the alias using a userAlias object. 
  	 * @param userAlias The alias to set
  	 */
  	public Criterion setAlias(UserAlias userAlias);
  	
  }
  
  
  
  1.74      +105 -2    db-ojb/src/test/org/apache/ojb/broker/QueryTest.java
  
  Index: QueryTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/QueryTest.java,v
  retrieving revision 1.73
  retrieving revision 1.74
  diff -u -r1.73 -r1.74
  --- QueryTest.java	14 Sep 2004 16:46:08 -0000	1.73
  +++ QueryTest.java	15 Sep 2004 17:18:45 -0000	1.74
  @@ -10,6 +10,8 @@
   import java.util.Vector;
   import java.util.List;
   
  +import org.apache.ojb.broker.ReferenceTest.Region;
  +
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.LikeCriteria;
  @@ -50,7 +52,7 @@
   
           // prepare test
           broker.beginTransaction();
  -        Query q = QueryFactory.newQuery(group);
  +        Query q = QueryFactory.newQueryByIdentity(group);
           broker.deleteByQuery(q);
           broker.commitTransaction();
           broker.clearCache();
  @@ -65,7 +67,7 @@
   
           ObjectRepository.Group groupTemp = new ObjectRepository.Group();
    	    groupTemp.setId(new Integer(0));
  -        Query queryNew = QueryFactory.newQuery(groupTemp);
  +        Query queryNew = QueryFactory.newQueryByIdentity(groupTemp);
    	    newGroup = ( ObjectRepository.Group ) broker.getObjectByQuery(queryNew);
           assertNotNull(newGroup);
           assertEquals(new Integer(0), newGroup.getId());
  @@ -105,6 +107,107 @@
           assertEquals(results.size(), 9);
       }
   
  +    /**
  +     * Criteria by identity
  +     */
  +    public void testByIdentity1()
  +    {
  +        Person p = new Person();
  +        p.setId(1);
  +        p.setFirstname("tom");
  +        Identity id = broker.serviceIdentity().buildIdentity(p);
  +
  +        Criteria crit = new Criteria();
  +        crit.addIdentityEqualTo("", id);
  +
  +        Query q = QueryFactory.newQuery(Person.class, crit);
  +        Collection results = broker.getCollectionByQuery(q);
  +
  +        // 1 person
  +        assertEquals(results.size(), 1);
  +    }
  +
  +    /**
  +     * Criteria by identity using extents
  +     */
  +    public void testByIdentityExtents()
  +    {
  +        Article a = new Article();
  +        a.setArticleId(1);
  +        Identity id = broker.serviceIdentity().buildIdentity(a);
  +
  +        Criteria crit = new Criteria();
  +        crit.addIdentityEqualTo("", id);
  +
  +        Query q = QueryFactory.newQuery(Article.class, crit);
  +        Collection results = broker.getCollectionByQuery(q);
  +
  +        // 1 article
  +        assertEquals(results.size(), 1);
  +    }
  +
  +    /**
  +     * Criteria by identity using relationship
  +     */
  +    public void testByIdentityRelationship()
  +    {
  +        Person p = new Person();
  +        p.setId(1);
  +        p.setFirstname("tom");
  +        Identity id = broker.serviceIdentity().buildIdentity(p);
  +
  +        Criteria crit = new Criteria();
  +        crit.addIdentityEqualTo("persons", id);
  +
  +        Query q = QueryFactory.newQuery(Project.class, crit);
  +        Collection results = broker.getCollectionByQuery(q);
  +
  +        // 2 Projects
  +        assertEquals(results.size(), 2);
  +    }
  +
  +    /**
  +     * Criteria by identity using relationship and extents
  +     */
  +    public void testByIdentityRelationshipAndExtents()
  +    {
  +        Article a = new Article();
  +        a.setArticleId(1);
  +        Identity id = broker.serviceIdentity().buildIdentity(a);
  +
  +        Criteria crit = new Criteria();
  +        crit.addIdentityEqualTo("allArticlesInGroup", id);
  +
  +        Query q = QueryFactory.newQuery(ProductGroup.class, crit);
  +        Collection results = broker.getCollectionByQuery(q);
  +
  +        // 1 article
  +        assertEquals(results.size(), 1);
  +    }
  +
  +    /**
  +     * Criteria by identity using object with multiple pk
  +     */
  +    public void testByIdentityMultiPk()
  +    {
  +        Region region = new Region("Region_for_Identity", "Country_for_Identity", "BRJ");
  +        Identity id = broker.serviceIdentity().buildIdentity(region);
  +
  +        broker.beginTransaction();
  +        broker.store(region);
  +        broker.commitTransaction();
  +        broker.clearCache();
  +        
  +        Criteria crit = new Criteria();
  +        crit.addIdentityEqualTo("", id);
  +
  +        Query q = QueryFactory.newQuery(Region.class, crit);
  +        Collection results = broker.getCollectionByQuery(q);
  +
  +        // 1 Region
  +        assertEquals(results.size(), 1);
  +    }
  +        
       /**
        * Criteria by example
        */
  
  
  
  1.51      +83 -26    db-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementManager.java
  
  Index: StatementManager.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementManager.java,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- StatementManager.java	14 Sep 2004 16:03:33 -0000	1.50
  +++ StatementManager.java	15 Sep 2004 17:18:45 -0000	1.51
  @@ -22,7 +22,6 @@
   import java.sql.Statement;
   import java.sql.Types;
   import java.util.Collection;
  -import java.util.Enumeration;
   import java.util.Iterator;
   
   import org.apache.ojb.broker.Identity;
  @@ -40,6 +39,7 @@
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.ExistsCriteria;
   import org.apache.ojb.broker.query.FieldCriteria;
  +import org.apache.ojb.broker.query.IdentityCriterion;
   import org.apache.ojb.broker.query.InCriteria;
   import org.apache.ojb.broker.query.NullCriteria;
   import org.apache.ojb.broker.query.Query;
  @@ -174,6 +174,7 @@
               throws SQLException
       {
           FieldDescriptor fld = null;
  +        
           // if value is a subQuery bind it
           if (value instanceof Query)
           {
  @@ -307,10 +308,31 @@
           {
               index = bindStatementValue(stmt, index, crit.getAttribute(), crit.getValue(), cld);
           }
  +        
           return index;
       }
   
       /**
  +     * bind IdentityCriteria by binding the enclosed Criteria
  +     * @param stmt the PreparedStatement
  +     * @param index the position of the parameter to bind
  +     * @param crit the Criteria containing the parameter
  +     * @param cld the ClassDescriptor
  +     * @return next index for PreparedStatement
  +     */
  +    private int bindStatement(PreparedStatement stmt, int index, IdentityCriterion crit, ClassDescriptor cld) throws SQLException
  +    {
  +        Iterator iter = crit.getCriteriaList().iterator();
  +        
  +        while (iter.hasNext())
  +        {
  +            SelectionCriteria selCrit = (SelectionCriteria) iter.next();
  +            index = bindSelectionCriteriaWithExtents(stmt, index, selCrit, cld);
  +        }
  +        return index;
  +    }
  +    
  +    /**
        * bind ExistsCriteria
        * @param stmt the PreparedStatement
        * @param index the position of the parameter to bind
  @@ -322,15 +344,14 @@
       {
           Query subQuery = (Query) crit.getValue();
   
  -        // if query has criteria, bind them
           if (subQuery.getCriteria() != null && !subQuery.getCriteria().isEmpty())
           {
  +            // if query has criteria, bind them
               return bindStatement(stmt, subQuery.getCriteria(), cld.getRepository().getDescriptorFor(subQuery.getSearchClass()), index);
  -
  -            // otherwise, just ignore it
           }
           else
           {
  +            // otherwise, just ignore it
               return index;
           }
       }
  @@ -340,49 +361,67 @@
        */
       public int bindStatement(PreparedStatement stmt, Query query, ClassDescriptor cld, int param) throws SQLException
       {
  -        int result;
  +        int index;
   
  -        result = bindStatement(stmt, query.getCriteria(), cld, param);
  -        result = bindStatement(stmt, query.getHavingCriteria(), cld, result);
  +        index = bindStatement(stmt, query.getCriteria(), cld, param);
  +        index = bindStatement(stmt, query.getHavingCriteria(), cld, index);
   
  -        return result;
  +        return index;
       }
   
       /**
        * bind a Query based Select Statement
        */
  -    protected int bindStatement(PreparedStatement stmt, Criteria crit, ClassDescriptor cld, int param) throws SQLException
  +    protected int bindStatement(PreparedStatement stmt, Criteria crit, ClassDescriptor cld, int index) throws SQLException
       {
           if (crit != null)
           {
  -            Enumeration e = crit.getElements();
  +            Iterator iter = crit.getIterator();
   
  -            while (e.hasMoreElements())
  +            while (iter.hasNext())
               {
  -                Object o = e.nextElement();
  -                if (o instanceof Criteria)
  +                Object c = iter.next();
  +                if (c instanceof Criteria)
  +                {
  +                    index = bindStatement(stmt, (Criteria)c, cld, index);
  +                }
  +                else if (c instanceof SelectionCriteria)
                   {
  -                    Criteria pc = (Criteria) o;
  -                    param = bindStatement(stmt, pc, cld, param);
  +                    index = bindSelectionCriteriaWithExtents(stmt, index, (SelectionCriteria)c, cld);
                   }
                   else
                   {
  -                    SelectionCriteria c = (SelectionCriteria) o;
  -                    // BRJ : bind once for the criterion's main class
  -                    param = bindSelectionCriteria(stmt, param, c, cld);
  -
  -                    // BRJ : and once for each extent
  -                    for (int i = 0; i < c.getNumberOfExtentsToBind(); i++)
  -                    {
  -                        param = bindSelectionCriteria(stmt, param, c, cld);
  -                    }
  +                    throw new PersistenceBrokerException("Don't know how to bind: " + c);                   
                   }
               }
           }
  -        return param;
  +        
  +        return index;
       }
   
       /**
  +     * bind SelectionCriteria handling the extents
  +     * @param stmt the PreparedStatement
  +     * @param index the position of the parameter to bind
  +     * @param crit the Criteria containing the parameter
  +     * @param cld the ClassDescriptor
  +     * @return next index for PreparedStatement
  +     */
  +    private int bindSelectionCriteriaWithExtents(PreparedStatement stmt, int index, SelectionCriteria crit, ClassDescriptor cld) throws SQLException
  +    {
  +        // BRJ : bind once for the criterion's main class
  +        index = bindSelectionCriteria(stmt, index, crit, cld);
  +
  +        // BRJ : and once for each extent
  +        for (int i = 0; i < crit.getNumberOfExtentsToBind(); i++)
  +        {
  +            index = bindSelectionCriteria(stmt, index, crit, cld);
  +        }
  +        
  +        return index;
  +    }    
  +        
  +    /**
        * bind SelectionCriteria
        * @param stmt the PreparedStatement
        * @param index the position of the parameter to bind
  @@ -393,19 +432,37 @@
       private int bindSelectionCriteria(PreparedStatement stmt, int index, SelectionCriteria crit, ClassDescriptor cld) throws SQLException
       {
           if (crit instanceof NullCriteria)
  +        {
               index = bindStatement(stmt, index, (NullCriteria) crit);
  +        }
           else if (crit instanceof BetweenCriteria)
  +        {
               index = bindStatement(stmt, index, (BetweenCriteria) crit, cld);
  +        }
           else if (crit instanceof InCriteria)
  +        {
               index = bindStatement(stmt, index, (InCriteria) crit, cld);
  +        }
           else if (crit instanceof SqlCriteria)
  +        {
               index = bindStatement(stmt, index, (SqlCriteria) crit);
  +        }
           else if (crit instanceof FieldCriteria)
  +        {
               index = bindStatement(stmt, index, (FieldCriteria) crit);
  +        }
           else if (crit instanceof ExistsCriteria)
  +        {
               index = bindStatement(stmt, index, (ExistsCriteria) crit, cld);
  +        }
  +        else if (crit instanceof IdentityCriterion)
  +        {
  +            index = bindStatement(stmt, index, (IdentityCriterion) crit, cld);
  +        }
           else
  +        {
               index = bindStatement(stmt, index, crit, cld);
  +        }
   
           return index;
       }
  
  
  
  1.66      +2 -2      db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java
  
  Index: BrokerHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java,v
  retrieving revision 1.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- BrokerHelper.java	14 Sep 2004 16:36:14 -0000	1.65
  +++ BrokerHelper.java	15 Sep 2004 17:18:45 -0000	1.66
  @@ -531,7 +531,7 @@
           // BRJ: copied Criteria without groupby, orderby, and prefetched relationships
           if (aQuery.getCriteria() != null)
           {
  -            countCrit = aQuery.getCriteria().copy(false,false,false);
  +            countCrit = new Criteria(aQuery.getCriteria(),false,false,false);
           }
   
           if(aQuery.isDistinct())
  
  
  
  1.64      +14 -1     db-ojb/release-notes.txt
  
  Index: release-notes.txt
  ===================================================================
  RCS file: /home/cvs/db-ojb/release-notes.txt,v
  retrieving revision 1.63
  retrieving revision 1.64
  diff -u -r1.63 -r1.64
  --- release-notes.txt	14 Sep 2004 16:55:22 -0000	1.63
  +++ release-notes.txt	15 Sep 2004 17:18:45 -0000	1.64
  @@ -46,6 +46,19 @@
   - QueryByExample: New class QueryByExample; the constructor QueryByCriteria(Object anExample) has been removed !  
     The handling of primitives has been improved a little. It's possible to ignore primitive 0 by using 
     QueryByExample#setIgnoreZero(true).
  +- Added support for new IdentityCriterion : 
  +
  +        Person p = new Person();
  +        p.setId(1);
  +        p.setFirstname("tom");
  +        Identity id = broker.serviceIdentity().buildIdentity(p);
  +
  +        Criteria crit = new Criteria();
  +        crit.addIdentityEqualTo("persons", id);
  +
  +        Query q = QueryFactory.newQuery(Project.class, crit);
  +        Collection results = broker.getCollectionByQuery(q);
  +
   
   BUG FIXES:
   
  
  
  

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