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/accesslayer ReportQueryRsIterator.java
Date Wed, 16 Mar 2005 20:31:01 GMT
brj         2005/03/16 12:31:01

  Modified:    src/java/org/apache/ojb/broker/accesslayer
                        ReportQueryRsIterator.java
  Log:
  fix for OJB 309: works only for simple attributes of the searchClass
  
  Revision  Changes    Path
  1.14      +37 -8     db-ojb/src/java/org/apache/ojb/broker/accesslayer/ReportQueryRsIterator.java
  
  Index: ReportQueryRsIterator.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ReportQueryRsIterator.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ReportQueryRsIterator.java	4 Apr 2004 23:53:31 -0000	1.13
  +++ ReportQueryRsIterator.java	16 Mar 2005 20:31:01 -0000	1.14
  @@ -15,11 +15,14 @@
    * limitations under the License.
    */
   
  +import java.sql.ResultSet;
   import java.sql.ResultSetMetaData;
   import java.sql.SQLException;
   
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.core.PersistenceBrokerImpl;
  +import org.apache.ojb.broker.metadata.ClassDescriptor;
  +import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.query.ReportQuery;
   import org.apache.ojb.broker.util.JdbcTypesHelper;
   
  @@ -31,9 +34,10 @@
    */
   public class ReportQueryRsIterator extends RsIterator
   {
  -
  +    private String[] m_attributes;
       private int m_attributeCount;
       private int[] m_jdbcTypes;
  +    private FieldDescriptor[] m_fieldDescriptors;
       
       /**
        * Constructor for ReportQueryRsIterator.
  @@ -46,9 +50,11 @@
               // BRJ: use only explicit attributes (columns) ! 
               // ignore those automatically added for ordering or grouping 
               ReportQuery q = (ReportQuery)queryObject.getQuery();
  +            m_attributes = q.getAttributes();
               m_attributeCount = q.getAttributes().length;
               
               init_jdbcTypes();
  +            init_fieldDescriptors();
           }
           catch (SQLException e)
           {
  @@ -58,6 +64,23 @@
       }
   
       /**
  +     * Initialize the FieldDescriptors for the attributes.
  +     * TODO: currently works for simple attributes only. No FieldDescriptor 
  +     * will be found for attributes like 'address.city' when the search class is 'Person'
  +     */
  +    private void init_fieldDescriptors()
  +    {
  +        ClassDescriptor cld = getQueryObject().getClassDescriptor();
  +
  +        m_fieldDescriptors = new FieldDescriptor[m_attributeCount];
  +        
  +        for (int i = 0; i < m_attributeCount; i++)
  +        {
  +            m_fieldDescriptors[i] = cld.getFieldDescriptorByName(m_attributes[i]);
  +        }
  +    }
  +    
  +    /**
        * get the jdbcTypes from the Query or the ResultSet if not available from the Query
        * @throws SQLException
        */
  @@ -82,22 +105,30 @@
           }
       }
       
  -    
       /**
        * returns an Object[] representing the columns of the current ResultSet
        * row. There is no OJB object materialization, Proxy generation etc.
  -     * involved to maximize performance.
  +     * involved to maximize performance. 
  +     * If a FieldDescriptor is available for the attribute, the retrieved value
  +     * is passed to it's FieldConversion. 
        */
       protected Object getObjectFromResultSet() throws PersistenceBrokerException
       {
           Object[] result = new Object[m_attributeCount];
  -
  +        ResultSet rs = getRsAndStmt().m_rs;
  +        
           for (int i = 0; i < m_attributeCount; i++)
           {
               try
               {
                   int jdbcType = m_jdbcTypes[i];
  -                result[i] = JdbcTypesHelper.getObjectFromColumn(getRsAndStmt().m_rs, new
Integer(jdbcType), i + 1);
  +                Object value = JdbcTypesHelper.getObjectFromColumn(rs, new Integer(jdbcType),
i + 1);
  +                FieldDescriptor fd = m_fieldDescriptors[i];
  +                if (fd != null)
  +                {
  +                    value = fd.getFieldConversion().sqlToJava(value);
  +                }
  +                result[i] = value;
               }
               catch (SQLException e)
               {
  @@ -106,6 +137,4 @@
           }
           return result;
       }
  - 
  -
   }
  
  
  

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