db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattba...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer RsIterator.java
Date Tue, 01 Jul 2003 04:33:07 GMT
mattbaird    2003/06/30 21:33:06

  Modified:    src/java/org/apache/ojb/odmg/oql oql-ojb.g
               src/java/org/apache/ojb/broker/query QueryByCriteria.java
               src/test/org/apache/ojb/odmg
                        ContractVersionEffectivenessOQLTest.java
               src/java/org/apache/ojb/broker/accesslayer RsIterator.java
  Log:
  Fixed a problem where selecting a projection attribute that is an object didn't return the
proper thing.
  PR:
  Obtained from: Matthew Baird
  Submitted by:	Matthew Baird
  Reviewed by:	Matthew Baird
  
  Revision  Changes    Path
  1.15      +64 -43    db-ojb/src/java/org/apache/ojb/odmg/oql/oql-ojb.g
  
  Index: oql-ojb.g
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/oql/oql-ojb.g,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- oql-ojb.g	24 Jun 2003 21:43:06 -0000	1.14
  +++ oql-ojb.g	1 Jul 2003 04:33:04 -0000	1.15
  @@ -99,6 +99,8 @@
   package org.apache.ojb.odmg.oql;
   
   import org.apache.ojb.broker.query.*;
  +import org.apache.ojb.broker.metadata.*;
  +import org.apache.ojb.broker.*;
   import java.util.*;
   }
   
  @@ -352,54 +354,73 @@
           query = selectQuery ( TOK_SEMIC )?
       ;
   
  -selectQuery returns [QueryByCriteria query = null] :
   
  -        {
  -            Class clazz = null;
  -            Criteria criteria = new Criteria();
  -            String[] projectionAttrs;
  -            boolean distinct = false;
  -        }
  +selectQuery returns [QueryByCriteria query = null] : 
   
  -        "select"
  +        { 
  +            Class clazz = null; 
  +            Criteria criteria = new Criteria(); 
  +            String[] projectionAttrs; 
  +            boolean distinct = false; 
  +        } 
  +
  +        "select" 
  +
  +        ( 
  +            options { 
  +                warnWhenFollowAmbig = false; 
  +            } : 
  +
  +            "distinct" 
  +            { 
  +                 distinct = true; 
  +            } 
  +        )? 
  +
  +        projectionAttrs = projectionAttributes 
  +
  +        "from" clazz = fromClause 
  +        ( "where" whereClause[criteria] )? 
  +        { 
  +            if (clazz != null) 
  +            { 
  +                if (projectionAttrs[0].indexOf('.') < 0) 
  +                { 
  +                    query = QueryFactory.newQuery(clazz, criteria, distinct); 
  +                } 
  +                else 
  +                { 
  +                        ClassDescriptor cld = PersistenceBrokerFactory.defaultPersistenceBroker().getClassDescriptor(clazz);
  +
  +                        ObjectReferenceDescriptor ord = null; 
  +                    for (int i = 0; i < projectionAttrs.length; i++) 
  +                    { 
  +                        projectionAttrs[i] = projectionAttrs[i].substring(projectionAttrs[i].indexOf('.')
+ 1); 
  +                                                ord = cld.getObjectReferenceDescriptorByName(projectionAttrs[i]);

  +                                                if (ord != null) 
  +                                                { 
  +                                                        break; 
  +                                                } 
  +                    } 
  +                    if (ord != null) 
  +                    { 
  +                            query = QueryFactory.newQuery(clazz, criteria, distinct);
  +	       		    query.setProjectionAttributeClass(ord.getItemClass());
  +
  +                    } 
  +                    else 
  +                    { 
  +                        query = QueryFactory.newReportQuery(clazz, projectionAttrs, criteria,
distinct); 
  +                    } 
  +                } 
  +            } 
  +        } 
  +        ( "order" "by" orderClause[query] )? 
   
  -        (
  -            options {
  -                warnWhenFollowAmbig = false;
  -            } :
  -
  -            "distinct"
  -            {
  -                 distinct = true;
  -            }
  -        )?
  -
  -        projectionAttrs = projectionAttributes
  -
  -        "from" clazz = fromClause
  -        ( "where" whereClause[criteria] )?
  -        {
  -            if (clazz != null) {
  -                if (projectionAttrs[0].indexOf('.') < 0)
  -                {
  -                    query = QueryFactory.newQuery(clazz, criteria, distinct);
  -                }
  -                else
  -                {
  -                    for (int i = 0; i < projectionAttrs.length; i++) {
  -                        projectionAttrs[i] = projectionAttrs[i].substring(
  -                                projectionAttrs[i].indexOf('.') + 1);
  -                    }
  -                    query = QueryFactory.newReportQuery(clazz, projectionAttrs,
  -                                                        criteria, distinct);
  -                }
  -            }
  -        }
  -        ( "order" "by" orderClause[query] )?
  +        ( "prefetch" prefetchClause[query] )? 
   
  -        ( "prefetch" prefetchClause[query] )?
  +    ; 
   
  -    ;
   
   existsQuery returns [Query query = null] :
   
  
  
  
  1.17      +11 -1     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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- QueryByCriteria.java	3 Jun 2003 19:33:18 -0000	1.16
  +++ QueryByCriteria.java	1 Jul 2003 04:33:05 -0000	1.17
  @@ -90,6 +90,7 @@
       private boolean m_distinct = false;
       private Map m_pathClasses;
       private Criteria m_havingCriteria;
  +	private Class m_projectionAttributeClass;
   
       // holding FieldHelper for orderBy and groupBy
       private List m_orderby = null;
  @@ -544,4 +545,13 @@
   		return m_pathOuterJoin;
   	}
   
  +	public Class getProjectionAttributeClass()
  +	{
  +		return m_projectionAttributeClass;
  +	}
  +
  +	public void setProjectionAttributeClass(Class projectionAttributeClass)
  +	{
  +		m_projectionAttributeClass = projectionAttributeClass;
  +	}
   }
  
  
  
  1.9       +1 -1      db-ojb/src/test/org/apache/ojb/odmg/ContractVersionEffectivenessOQLTest.java
  
  Index: ContractVersionEffectivenessOQLTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/ContractVersionEffectivenessOQLTest.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ContractVersionEffectivenessOQLTest.java	1 Jul 2003 01:49:42 -0000	1.8
  +++ ContractVersionEffectivenessOQLTest.java	1 Jul 2003 04:33:06 -0000	1.9
  @@ -228,7 +228,7 @@
               createData(db, odmg);
               OQLQuery query = odmg.newOQLQuery();
               int i = 0;
  -            query.create("select effectiveness.version from " + Effectiveness.class.getName());
  +            query.create("select effectiveness.version from " + Effectiveness.class.getName()
+ " where is_defined(effectiveness.version.versionValue1)");
               ManageableCollection all = (ManageableCollection) query.execute();
               java.util.Iterator it = all.ojbIterator();
   			Object temp1 = null;
  
  
  
  1.37      +10 -1     db-ojb/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
  
  Index: RsIterator.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- RsIterator.java	24 May 2003 23:58:20 -0000	1.36
  +++ RsIterator.java	1 Jul 2003 04:33:06 -0000	1.37
  @@ -64,6 +64,7 @@
   import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
   import org.apache.ojb.broker.query.Query;
  +import org.apache.ojb.broker.query.QueryByCriteria;
   import org.apache.ojb.broker.core.LoadedObjectsRegistry;
   import org.apache.ojb.broker.core.PersistenceBrokerImpl;
   import org.apache.ojb.broker.util.logging.Logger;
  @@ -251,6 +252,14 @@
               if (hasNext)
               {
                   Object obj = getObjectFromResultSet();
  +	            if (m_query instanceof QueryByCriteria)
  +	            {
  +		            if (((QueryByCriteria)m_query).getProjectionAttributeClass() != null)
  +		            {
  +			            obj = m_cld.getObjectReferenceDescriptorByName("version").getPersistentField().get(obj);
  +		            }
  +
  +	            }
                   m_current_row++;
   
                   // Invoke events on PersistenceBrokerAware instances and listeners
  
  
  

Mime
View raw message