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/java/org/apache/ojb/broker/query QueryByCriteria.java Criteria.java
Date Sat, 15 Mar 2003 16:22:11 GMT
brj         2003/03/15 08:22:11

  Modified:    src/java/org/apache/ojb/broker/query QueryByCriteria.java
                        Criteria.java
  Log:
  Query refactoring
  
  Revision  Changes    Path
  1.10      +145 -24   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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- QueryByCriteria.java	15 Mar 2003 15:42:26 -0000	1.9
  +++ QueryByCriteria.java	15 Mar 2003 16:22:11 -0000	1.10
  @@ -54,15 +54,17 @@
    * <http://www.apache.org/>.
    */
   
  +import java.util.ArrayList;
  +import java.util.HashMap;
  +import java.util.List;
  +
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
  +import org.apache.ojb.broker.metadata.FieldHelper;
   import org.apache.ojb.broker.metadata.MetadataManager;
   import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   
  -import java.util.HashMap;
  -import java.util.List;
  -
   /**
    * represents a search by criteria.
    * "find all articles where article.price > 100"
  @@ -88,6 +90,13 @@
       private HashMap m_pathClasses;
       private Criteria m_havingCriteria;
   
  +    // holding FieldHelper for orderBy and groupBy
  +    private List m_orderby = null;
  +    private List m_groupby = null;
  +    
  +    // list of names of prefetchable relationships
  +    private List m_prefetchedRelationships = null;
  +
       /**
        * Build a Query for class targetClass with criteria.
        * Criteriy may be null (will result in a query returning ALL objects from a table)
  @@ -96,10 +105,13 @@
       {
           super (targetClass);
           
  -        this.m_criteria = whereCriteria;
  -        this.m_havingCriteria = havingCriteria;
  -        this.m_distinct = distinct;
  -        this.m_pathClasses = new HashMap();
  +        m_criteria = whereCriteria;
  +        m_havingCriteria = havingCriteria;
  +        m_distinct = distinct;
  +        m_pathClasses = new HashMap();
  +        m_groupby = new ArrayList();
  +        m_orderby = new ArrayList();
  +        m_prefetchedRelationships = new ArrayList();
       }
   
       /**
  @@ -285,49 +297,158 @@
   		m_havingCriteria = havingCriteria;
   	}
   
  +    /**
  +     * Adds a groupby fieldName for ReportQueries.
  +     * @param fieldName The groupby to set
  +     */
  +    public void addGroupBy(String fieldName)
  +    {
  +        if (fieldName != null)
  +        {
  +            m_groupby.add(new FieldHelper(fieldName, false));
  +        }
  +    }
  +
  +    /**
  +     * Adds a field for groupby
  +     * @param aField
  +     */
  +    public void addGroupBy(FieldHelper aField)
  +    {
  +        if (aField != null)
  +        {
  +            m_groupby.add(aField);
  +        }
  +    }
  +
  +    /**
  +     * Adds an array of groupby fieldNames for ReportQueries.
  +     * @param fieldNames The groupby to set
  +     */
  +    public void addGroupBy(String[] fieldNames)
  +    {
  +        for (int i = 0; i < fieldNames.length; i++)
  +        {
  +            addGroupBy(fieldNames[i]);
  +        }
  +    }
  +
   	/* (non-Javadoc)
   	 * @see org.apache.ojb.broker.query.Query#getGroupBy()
   	 */
   	public List getGroupBy()
   	{
  +        // BRJ: 
  +        // combine data from query and criteria
  +        // TODO: to be removed when Criteria#addGroupBy is removed 
  +        ArrayList temp = new ArrayList();     
  +        temp.addAll(m_groupby);
  +        
           if (getCriteria() != null)
           {
  -            return getCriteria().getGroupby();
  +            temp.addAll(getCriteria().getGroupby());
  +        }    
  +
  +        return temp;
  +	}
  +
  +    /**
  +     * Adds a field for orderBy
  +     * @param  fieldName    The field name to be used
  +     * @param  sortAscending    true for ASCENDING, false for DESCENDING
  +     */
  +    public void addOrderBy(String fieldName, boolean sortAscending)
  +    {
  +        if (fieldName != null)
  +        {
  +            m_orderby.add(new FieldHelper(fieldName, sortAscending));
           }
  -        else
  +    }
  +
  +    /**
  +     * Adds a field for orderBy, order is ASCENDING
  +     * @param  fieldName    The field name to be used
  +     * @deprecated use #addOrderByAscending(String fieldName)
  +     */
  +    public void addOrderBy(String fieldName)
  +    {
  +        addOrderBy(fieldName, true);
  +    }
  +
  +    /**
  +     * Adds a field for orderBy
  +     * @param aField
  +     */
  +    public void addOrderBy(FieldHelper aField)
  +    {
  +        if (aField != null)
           {
  -            return null;
  +            m_orderby.add(aField);
           }
  -	}
  +    }
  +
  +    /**
  +     * Adds a field for orderBy ASCENDING
  +     * @param  fieldName    The field name to be used
  +     */
  +    public void addOrderByAscending(String fieldName)
  +    {
  +        addOrderBy(fieldName, true);
  +    }
  +
  +    /**
  +     * Adds a field for orderBy DESCENDING
  +     * @param  fieldName    The field name to be used
  +     */
  +    public void addOrderByDescending(String fieldName)
  +    {
  +        addOrderBy(fieldName, false);
  +    }
   
   	/* (non-Javadoc)
   	 * @see org.apache.ojb.broker.query.Query#getOrderBy()
   	 */
   	public List getOrderBy()
   	{
  +        // BRJ: 
  +        // combine data from query and criteria
  +        // TODO: to be removed when Criteria#addOrderBy is removed 
  +        ArrayList temp = new ArrayList();     
  +        temp.addAll(m_orderby);
  +        
           if (getCriteria() != null)
           {
  -            return getCriteria().getOrderby();
  -        }
  -        else
  -        {
  -            return null;
  -        }
  +            temp.addAll(getCriteria().getOrderby());
  +        }    
  +        
  +        return temp;
   	}
   
  +    /**
  +     * add the name of aRelationship for prefetched read
  +     */
  +    public void addPrefetchedRelationship(String aName)
  +    {
  +        m_prefetchedRelationships.add(aName);
  +    }
  +
   	/* (non-Javadoc)
   	 * @see org.apache.ojb.broker.query.Query#getPrefetchedRelationships()
   	 */
   	public List getPrefetchedRelationships()
   	{
  +        // BRJ: 
  +        // combine data from query and criteria
  +        // TODO: to be removed when Criteria#addPrefetchedRelationship is removed 
  +        ArrayList temp = new ArrayList();     
  +        temp.addAll(m_prefetchedRelationships);
  +        
           if (getCriteria() != null)
           {
  -            return getCriteria().getPrefetchedRelationships();
  -        }
  -        else
  -        {
  -            return null;
  -        }
  +            temp.addAll(getCriteria().getPrefetchedRelationships());
  +        }    
  +        
  +        return temp;
   	}
   
   }
  
  
  
  1.25      +8 -1      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.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- Criteria.java	15 Mar 2003 15:42:26 -0000	1.24
  +++ Criteria.java	15 Mar 2003 16:22:11 -0000	1.25
  @@ -545,6 +545,7 @@
   	/**
   	 * Adds a field for orderBy
   	 * @param aField
  +     * @deprecated use Query#addOrderBy
   	 */
   	public void addOrderBy(FieldHelper aField)
   	{
  @@ -557,6 +558,7 @@
   	/**
   	 * Adds a field for orderBy ASCENDING
   	 * @param  fieldName	The field name to be used
  +     * @deprecated use Query#addOrderByAscending
   	 */
   	public void addOrderByAscending(String fieldName)
   	{
  @@ -566,6 +568,7 @@
   	/**
   	 * Adds a field for orderBy DESCENDING
   	 * @param  fieldName	The field name to be used
  +     * @deprecated use Query#addOrderByDescending
   	 */
   	public void addOrderByDescending(String fieldName)
   	{
  @@ -852,6 +855,7 @@
   	/**
   	 * Adds a groupby fieldName for ReportQueries.
   	 * @param fieldName The groupby to set
  +     * @deprecated use Query#addGroupBy
   	 */
   	public void addGroupBy(String fieldName)
   	{
  @@ -864,6 +868,7 @@
   	/**
   	 * Adds a field for groupby
   	 * @param aField
  +     * @deprecated use Query#addGroupBy
   	 */
   	public void addGroupBy(FieldHelper aField)
   	{
  @@ -876,6 +881,7 @@
   	/**
   	 * Adds an array of groupby fieldNames for ReportQueries.
   	 * @param fieldNames The groupby to set
  +     * @deprecated use Query#addGroupBy
   	 */
   	public void addGroupBy(String[] fieldNames)
   	{
  @@ -896,6 +902,7 @@
   
   	/**
   	 * add the name of aRelationship for prefetch read
  +     * @deprecated use Query#addPrefetchedRelationship
   	 */
   	public void addPrefetchedRelationship(String aName)
   	{
  
  
  

Mime
View raw message