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 QueryByExample.java QueryByCriteria.java QueryFactory.java AbstractQueryImpl.java
Date Fri, 27 Aug 2004 19:55:43 GMT
brj         2004/08/27 12:55:43

  Modified:    src/java/org/apache/ojb/broker/core
                        PersistenceBrokerImpl.java
               src/java/org/apache/ojb/broker/query QueryByCriteria.java
                        QueryFactory.java AbstractQueryImpl.java
  Added:       src/java/org/apache/ojb/broker/query QueryByExample.java
  Log:
  better handling for QueryByExample. criteria is built during runtime.
  constructor QueryByCriteria(Object anExampleObject) removed !
  
  Revision  Changes    Path
  1.90      +7 -1      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.89
  retrieving revision 1.90
  diff -u -r1.89 -r1.90
  --- PersistenceBrokerImpl.java	15 Aug 2004 12:42:27 -0000	1.89
  +++ PersistenceBrokerImpl.java	27 Aug 2004 19:55:42 -0000	1.90
  @@ -58,6 +58,7 @@
   import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryByCriteria;
  +import org.apache.ojb.broker.query.QueryByExample;
   import org.apache.ojb.broker.query.QueryByIdentity;
   import org.apache.ojb.broker.query.QueryBySQL;
   import org.apache.ojb.broker.util.BrokerHelper;
  @@ -1810,6 +1811,11 @@
           {
               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.29      +10 -64    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.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- QueryByCriteria.java	13 Jul 2004 11:37:57 -0000	1.28
  +++ QueryByCriteria.java	27 Aug 2004 19:55:43 -0000	1.29
  @@ -22,12 +22,9 @@
   import java.util.Map;
   
   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.ObjectReferenceDescriptor;
  -import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
  -import org.apache.ojb.broker.util.logging.LoggerFactory;
   
   /**
    * represents a search by criteria.
  @@ -51,18 +48,18 @@
   {
       private Criteria m_criteria;
       private boolean m_distinct = false;
  -    private Map m_pathClasses;
  +    private Map m_pathClasses = new HashMap();
       private Criteria m_havingCriteria;
       private String m_objectProjectionAttribute;
   
       // holding FieldHelper for orderBy and groupBy
  -    private List m_orderby = null;
  -    private List m_groupby = null;
  +    private List m_orderby = new ArrayList();
  +    private List m_groupby = new ArrayList();
   
       // list of names of prefetchable relationships
  -    private List m_prefetchedRelationships = null;
  +    private List m_prefetchedRelationships = new ArrayList();
   
  -    private Map m_pathOuterJoin;
  +    private Map m_pathOuterJoin = new HashMap();
   
       /**
        * handy criteria that can be used to select all instances of
  @@ -70,6 +67,10 @@
        */
       public static final Criteria CRITERIA_SELECT_ALL = null;
   
  +    protected QueryByCriteria()
  +    {
  +    }
  +    
       /**
        * Build a Query for class targetClass with criteria.
        * Criteriy may be null (will result in a query returning ALL objects from a table)
  @@ -82,11 +83,6 @@
           setHavingCriteria(havingCriteria);
   
           m_distinct = distinct;
  -        m_pathClasses = new HashMap();
  -        m_groupby = new ArrayList();
  -        m_orderby = new ArrayList();
  -        m_prefetchedRelationships = new ArrayList();
  -        m_pathOuterJoin = new HashMap();
       }
   
       /**
  @@ -118,24 +114,6 @@
       }
   
       /**
  -     * Build a Query based on anObject <br>
  -     * all non null values are used as EqualToCriteria
  -     */
  -    public QueryByCriteria(Object anObject, boolean distinct)
  -    {
  -        this(anObject.getClass(), buildCriteria(anObject), distinct);
  -    }
  -
  -    /**
  -     * Build a Query based on anObject <br>
  -     * all non null values are used as EqualToCriteria
  -     */
  -    public QueryByCriteria(Object anObject)
  -    {
  -        this(anObject.getClass(), buildCriteria(anObject));
  -    }
  -
  -    /**
        * Build a Query based on a Class Object. This
        * Query will return all instances of the given class.
        * @param aClassToSearchFrom the class to search from
  @@ -182,38 +160,6 @@
           m_pathClasses = aQuery.m_pathClasses;
           m_pathOuterJoin = aQuery.m_pathOuterJoin;
           m_prefetchedRelationships = aQuery.m_prefetchedRelationships;
  -    }
  -
  -    /**
  -     * Build Criteria based on example object<br>
  -     * all non null values are used as EqualToCriteria
  -     */
  -    private static Criteria buildCriteria(Object anExample)
  -    {
  -        Criteria criteria = new Criteria();
  -        ClassDescriptor cld = MetadataManager.getInstance().getRepository().getDescriptorFor(anExample.getClass());
  -        FieldDescriptor[] fds = cld.getFieldDescriptions();
  -        PersistentField f;
  -        Object value;
  -
  -        for (int i = 0; i < fds.length; i++)
  -        {
  -            try
  -            {
  -                f = fds[i].getPersistentField();
  -                value = f.get(anExample);
  -                if (value != null)
  -                {
  -                    criteria.addEqualTo(f.getName(), value);
  -                }
  -            }
  -            catch (Throwable ex)
  -            {
  -                LoggerFactory.getDefaultLogger().error(ex);
  -            }
  -        }
  -
  -        return criteria;
       }
   
       /**
  
  
  
  1.19      +11 -4     db-ojb/src/java/org/apache/ojb/broker/query/QueryFactory.java
  
  Index: QueryFactory.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/QueryFactory.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- QueryFactory.java	13 Jul 2004 11:37:57 -0000	1.18
  +++ QueryFactory.java	27 Aug 2004 19:55:43 -0000	1.19
  @@ -86,6 +86,8 @@
        * Return a QueryByIdentity for example_or_identity
        * @param example_or_identity
        * @return QueryByIdentity
  +     * 
  +     * @deprecated use newQueryByIdentity()
        */
       public static QueryByIdentity newQuery(Object example_or_identity)
       {
  @@ -106,11 +108,11 @@
        * Return a QueryByCriteria for example
        * <br>Use with care because building of Query is not foolproof !!!
        * @param example
  -     * @return QueryByCriteria
  +     * @return QueryByExample
        */
  -    public static QueryByCriteria newQueryByExample(Object example)
  +    public static QueryByExample newQueryByExample(Object example)
       {
  -        return new QueryByCriteria(example);
  +        return new QueryByExample(example);
       }
   
       /**
  @@ -164,6 +166,11 @@
           if (aQuery instanceof ReportQueryByCriteria)
           {
               return new ReportQueryByCriteria((ReportQueryByCriteria)aQuery);
  +        }
  +
  +        if (aQuery instanceof QueryByExample)
  +        {
  +            return new QueryByExample((QueryByExample)aQuery);
           }
   
           if (aQuery instanceof QueryByMtoNCriteria)
  
  
  
  1.15      +16 -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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- AbstractQueryImpl.java	4 Apr 2004 23:53:36 -0000	1.14
  +++ AbstractQueryImpl.java	27 Aug 2004 19:55:43 -0000	1.15
  @@ -163,4 +163,19 @@
               || getStartAtIndex() > NO_START_AT_INDEX;
       }
       
  +    /**
  +     * @param baseClass The baseClass to set.
  +     */
  +    protected void setBaseClass(Class baseClass)
  +    {
  +        m_baseClass = baseClass;
  +    }
  +    
  +    /**
  +     * @param searchClass The searchClass to set.
  +     */
  +    protected void setSearchClass(Class searchClass)
  +    {
  +        m_searchClass = searchClass;
  +    }
   }
  
  
  
  1.4       +139 -135  db-ojb/src/java/org/apache/ojb/broker/query/QueryByExample.java
  
  
  
  

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