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/xdoclet/test/xdoclet/modules/ojb/tests TestRowReader.java
Date Thu, 29 Sep 2005 20:36:44 GMT
brj         2005/09/29 13:36:44

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlGeneratorDefaultImpl.java
                        SqlSelectStatement.java SqlGenerator.java
               src/test/org/apache/ojb/compare PerformanceJdbcTest.java
                        PerformanceJdbcFailoverTest.java
               src/java/org/apache/ojb/broker/accesslayer
                        JdbcAccessImpl.java RowReaderDefaultImpl.java
                        ResultSetAndStatement.java
                        StatementManagerAbstractImpl.java RowReader.java
                        RsIterator.java
               src/test/org/apache/ojb/broker QueryTest.java
               src/xdoclet/test/xdoclet/modules/ojb/tests
                        TestRowReader.java
  Added:       src/java/org/apache/ojb/broker/accesslayer/sql
                        SelectStatementWrapper.java
  Log:
  use column index when reading from resultset of multiple joined tables
  
  Revision  Changes    Path
  1.32      +15 -17    db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGeneratorDefaultImpl.java
  
  Index: SqlGeneratorDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGeneratorDefaultImpl.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- SqlGeneratorDefaultImpl.java	6 Sep 2005 22:19:17 -0000	1.31
  +++ SqlGeneratorDefaultImpl.java	29 Sep 2005 20:36:41 -0000	1.32
  @@ -201,11 +201,10 @@
        *
        * @param cld the ClassDescriptor
        */
  -    public String getPreparedSelectByPkStatement(ClassDescriptor cld)
  +    public SqlStatement getPreparedSelectByPkStatement(ClassDescriptor cld)
       {
  -        String result;
           SqlForClass sfc = getSqlForClass(cld);
  -        result = sfc.getSelectByPKSql();
  +        SqlStatement result = sfc.getSelectByPKSql();
           if(result == null)
           {
               ProcedureDescriptor pd = cld.getSelectByPKProcedure();
  @@ -213,15 +212,14 @@
   
               if(pd == null)
               {
  -                sql = new SqlSelectByPkStatement(m_platform, m_logger, cld);
  +                result = new SqlSelectByPkStatement(m_platform, m_logger, cld);
               }
               else
               {
  -                sql = new SqlProcedureStatement(pd, m_logger);
  +                result = new SqlProcedureStatement(pd, m_logger);
               }
   
  -            result = sql.getStatement();
  -            // set the sql string
  +             // set the sql string
               sfc.setSelectByPKSql(result);
   
               if(m_logger.isDebugEnabled())
  @@ -229,7 +227,7 @@
                   m_logger.debug("SQL:" + result);
               }
           }
  -        return result;
  +        return new SelectStatementWrapper(result);
       }
   
       /**
  @@ -238,7 +236,7 @@
        * @param query the Query
        * @param cld the ClassDescriptor
        */
  -    public String getPreparedSelectStatement(Query query, ClassDescriptor cld)
  +    public SqlStatement getPreparedSelectStatement(Query query, ClassDescriptor cld)
       {
           ProcedureDescriptor pd = cld.getSelectByFKProcedure();
           SqlStatement sql;
  @@ -254,7 +252,7 @@
               sql = new SqlSelectStatement(m_platform, m_logger, cld, query);
           }
   
  -        return sql.getStatement();
  +        return new SelectStatementWrapper(sql);
       }
   
       /**
  @@ -263,12 +261,12 @@
        * @param query the Query
        * @param cld the ClassDescriptor
        */
  -    public String getPreparedSelectPkStatement(Query query, ClassDescriptor cld)
  +    public SqlStatement getPreparedSelectPkStatement(Query query, ClassDescriptor cld)
       {
           SqlStatement sql;
           sql = new SqlSelectPkStatement(m_platform, m_logger, cld, query);
   
  -        return sql.getStatement();
  +        return new SelectStatementWrapper(sql);
       }
   
       /**
  @@ -462,7 +460,7 @@
           if(attributeOrQuery instanceof Query)
           {
               Query q = (Query) attributeOrQuery;
  -            result = getPreparedSelectStatement(q, cld.getRepository().getDescriptorFor(q.getSearchClass()));
  +            result = getPreparedSelectStatement(q, cld.getRepository().getDescriptorFor(q.getSearchClass())).getStatement();
           }
           else
           {
  @@ -590,7 +588,7 @@
           private String deleteSql;
           private String insertSql;
           private String updateSql;
  -        private String selectByPKSql;
  +        private SqlStatement selectByPKSql;
   
           public String getDeleteSql()
           {
  @@ -622,12 +620,12 @@
               this.updateSql = updateSql;
           }
   
  -        public String getSelectByPKSql()
  +        public SqlStatement getSelectByPKSql()
           {
               return selectByPKSql;
           }
   
  -        public void setSelectByPKSql(String selectByPKSql)
  +        public void setSelectByPKSql(SqlStatement selectByPKSql)
           {
               this.selectByPKSql = selectByPKSql;
           }
  
  
  
  1.42      +60 -6     db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectStatement.java
  
  Index: SqlSelectStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectStatement.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- SqlSelectStatement.java	18 Sep 2005 13:26:14 -0000	1.41
  +++ SqlSelectStatement.java	29 Sep 2005 20:36:41 -0000	1.42
  @@ -42,6 +42,8 @@
    */
   public class SqlSelectStatement extends SqlQueryStatement
   {
  +    private FieldDescriptor[] fieldsForSelect;
  +    
       /**
        * Constructor for SqlSelectStatement.
        * @param aPlatform
  @@ -105,6 +107,33 @@
       }
   
       /**
  +     * Get MultiJoined ClassDescriptors
  +      */
  +    ClassDescriptor[] getMultiJoinedClassDescriptors()
  +    {
  +        return getMultiJoinedClassDescriptors(getSearchClassDescriptor());
  +    }
  +        
  +    /**
  +     * Get MultiJoined ClassDescriptors
  +     * @param cld
  +     */
  +    private ClassDescriptor[] getMultiJoinedClassDescriptors(ClassDescriptor cld)
  +    {
  +        DescriptorRepository repository = cld.getRepository();
  +        Class[] multiJoinedClasses = repository.getSubClassesMultipleJoinedTables(cld,
true);
  +        ClassDescriptor[] result = new ClassDescriptor[multiJoinedClasses.length];
  +                                
  +        for (int i = 0 ; i < multiJoinedClasses.length; i++)
  +        {
  +            ClassDescriptor subCld = repository.getDescriptorFor(multiJoinedClasses[i]);
  +            result[i] = subCld;
  +         }
  +        
  +        return result;
  +    }
  +
  +    /**
        * Create the OJB_CLAZZ pseudo column based on CASE WHEN. 
        * This column defines the Class to be instantiated.
        * @param cld
  @@ -112,21 +141,20 @@
        */
       private void appendClazzColumnForSelect(ClassDescriptor cld, StringBuffer buf)
       {
  -        DescriptorRepository repository = cld.getRepository();
  -        Class[] multiJoinedClasses = repository.getSubClassesMultipleJoinedTables(cld,
true);
  +        ClassDescriptor[] clds = getMultiJoinedClassDescriptors(cld);
   
  -        if (multiJoinedClasses.length == 0)
  +        if (clds.length == 0)
           {
               return;
           }
           
           buf.append(",CASE");
   
  -        for (int i = multiJoinedClasses.length; i > 0; i--)
  +        for (int i = clds.length; i > 0; i--)
           {
               buf.append(" WHEN ");
   
  -            ClassDescriptor subCld = repository.getDescriptorFor(multiJoinedClasses[i-1]);
  +            ClassDescriptor subCld = clds[i - 1];
               FieldDescriptor[] fieldDescriptors = subCld.getPkFields();
   
               TableAlias alias = getTableAliasForClassDescriptor(subCld);
  @@ -149,11 +177,37 @@
       /**
        * Return the Fields to be selected.
        *
  +     * @return the Fields to be selected
  +     */
  +    FieldDescriptor[] getFieldsForSelect()
  +    {
  +        return getFieldsForSelect(getSearchClassDescriptor());
  +    }
  +
  +    /**
  +     * Return the Fields to be selected.
  +     *
        * @param cld the ClassDescriptor
        * @return the Fields to be selected
        */
       protected FieldDescriptor[] getFieldsForSelect(ClassDescriptor cld)
       {
  +        if (fieldsForSelect == null)
  +        {
  +            fieldsForSelect = buildFieldsForSelect(cld);
  +        }
  +        
  +        return fieldsForSelect;
  +    }
  +        
  +    /**
  +     * Return the Fields to be selected.
  +     *
  +     * @param cld the ClassDescriptor
  +     * @return the Fields to be selected
  +     */
  +    protected FieldDescriptor[] buildFieldsForSelect(ClassDescriptor cld)
  +    {
           DescriptorRepository repository = cld.getRepository();
           Set fields = new ListOrderedSet();   // keep the order of the fields
           
  
  
  
  1.13      +4 -4      db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGenerator.java
  
  Index: SqlGenerator.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGenerator.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- SqlGenerator.java	27 Apr 2005 19:21:52 -0000	1.12
  +++ SqlGenerator.java	29 Sep 2005 20:36:41 -0000	1.13
  @@ -55,14 +55,14 @@
        * @param query the Query
        * @param cld the ClassDescriptor
        */
  -    public String getPreparedSelectStatement(Query query, ClassDescriptor cld);
  +    public SqlStatement getPreparedSelectStatement(Query query, ClassDescriptor cld);
   
       /**
        * generate a select pk-columns only statement according to query
        * @param query the Query
        * @param cld the ClassDescriptor
        */
  -    public String getPreparedSelectPkStatement(Query query, ClassDescriptor cld);
  +    public SqlStatement getPreparedSelectPkStatement(Query query, ClassDescriptor cld);
   
       /**
        * generate a select-Statement according to query
  @@ -97,7 +97,7 @@
        * described by cld
        * @param cld the ClassDescriptor
        */
  -    public String getPreparedSelectByPkStatement(ClassDescriptor cld);
  +    public SqlStatement getPreparedSelectByPkStatement(ClassDescriptor cld);
   
       /**
        * generate a prepared UPDATE-Statement for the Class
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SelectStatementWrapper.java
  
  Index: SelectStatementWrapper.java
  ===================================================================
  package org.apache.ojb.broker.accesslayer.sql;
  
  /* 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.metadata.ClassDescriptor;
  import org.apache.ojb.broker.metadata.FieldDescriptor;
  import org.apache.ojb.broker.metadata.JdbcType;
  
  
  /**
   * Wrapper for SqlStatement.
   * Contains information about the SQL-String ie. the FieldDescriptors of the selected columns.
   *
   * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
   * @version $Id: SelectStatementWrapper.java,v 1.1 2005/09/29 20:36:41 brj Exp $
   */
  public class SelectStatementWrapper implements SqlStatement
  {
      private String sql;
      private FieldDescriptor[] selectedFields;
      private ClassDescriptor[] classDescriptors; 
  
      public SelectStatementWrapper(SqlStatement aStatement)
      {
          sql = aStatement.getStatement();
          
          if (aStatement instanceof SqlSelectStatement)
          {
              SqlSelectStatement selectStmt = (SqlSelectStatement) aStatement;
              selectedFields = selectStmt.getFieldsForSelect();
              classDescriptors = selectStmt.getMultiJoinedClassDescriptors();            
          }
      }
  
      public SelectStatementWrapper(SqlSelectStatement aStatement)
      {
          sql = aStatement.getStatement();
          selectedFields = aStatement.getFieldsForSelect();
          classDescriptors = aStatement.getMultiJoinedClassDescriptors();
      }
  
      /**
       * Answer the SQL-String.
       */
      public String getStatement()
      {
          return sql;
      }
  
      public ClassDescriptor[] getClassDescriptors()
      {
          return classDescriptors;
      }
  
      /**
       * Return the Column Index for the given FieldDescriptor.
       * @param fld the FieldDescriptor
       * @return the columnIndex or JdbcType.MIN_INT if not found
       */
      public int getColumnIndex(FieldDescriptor fld)
      {
          int index = JdbcType.MIN_INT;
          
          if (selectedFields != null)
          {
              for (int i = 0; i < selectedFields.length; i++)
              {
                  if (selectedFields[i].equals(fld))
                  {
                      index = i + 1;  // starts at 1
                      break;
                  }
              }
          }
          
          return index;
      }
  }
  
  
  
  1.3       +2 -2      db-ojb/src/test/org/apache/ojb/compare/PerformanceJdbcTest.java
  
  Index: PerformanceJdbcTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/compare/PerformanceJdbcTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PerformanceJdbcTest.java	27 Aug 2005 12:41:20 -0000	1.2
  +++ PerformanceJdbcTest.java	29 Sep 2005 20:36:41 -0000	1.3
  @@ -172,7 +172,7 @@
           // Use the OJB SqlGenerator to generate SQL Statements. All details about
           // Table and column names are read from the repository.xml file.
           ClassDescriptor cld = broker.getClassDescriptor(PerformanceArticle.class);
  -        String sql = broker.serviceSqlGenerator().getPreparedSelectByPkStatement(cld);
  +        String sql = broker.serviceSqlGenerator().getPreparedSelectByPkStatement(cld).getStatement();
           logger.debug("select stmt: " + sql);
   
           String colId = cld.getFieldDescriptorByName("articleId").getColumnName();
  @@ -242,7 +242,7 @@
           // Use the OJB SqlGenerator to generate SQL Statements. All details about
           // Table and column names are read from the repository.xml file.
           ClassDescriptor cld = broker.getClassDescriptor(PerformanceArticle.class);
  -        String sql = broker.serviceSqlGenerator().getPreparedSelectStatement(query, cld);
  +        String sql = broker.serviceSqlGenerator().getPreparedSelectStatement(query, cld).getStatement();
   
           logger.debug("select stmt: " + sql);
   
  
  
  
  1.3       +2 -2      db-ojb/src/test/org/apache/ojb/compare/PerformanceJdbcFailoverTest.java
  
  Index: PerformanceJdbcFailoverTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/compare/PerformanceJdbcFailoverTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PerformanceJdbcFailoverTest.java	27 Aug 2005 12:41:20 -0000	1.2
  +++ PerformanceJdbcFailoverTest.java	29 Sep 2005 20:36:41 -0000	1.3
  @@ -373,7 +373,7 @@
           // Use the OJB SqlGenerator to generate SQL Statements. All details about
           // Table and column names are read from the repository.xml file.
           ClassDescriptor cld = broker.getClassDescriptor(PerformanceArticle.class);
  -        String sql = broker.serviceSqlGenerator().getPreparedSelectByPkStatement(cld);
  +        String sql = broker.serviceSqlGenerator().getPreparedSelectByPkStatement(cld).getStatement();
           logger.debug("select stmt: " + sql);
           long start = System.currentTimeMillis();
   
  @@ -465,7 +465,7 @@
           // Use the OJB SqlGenerator to generate SQL Statements. All details about
           // Table and column names are read from the repository.xml file.
           ClassDescriptor cld = broker.getClassDescriptor(PerformanceArticle.class);
  -        String sql = broker.serviceSqlGenerator().getPreparedSelectStatement(query, cld);
  +        String sql = broker.serviceSqlGenerator().getPreparedSelectStatement(query, cld).getStatement()
;
   
           logger.debug("select stmt: " + sql);
           long start = System.currentTimeMillis();
  
  
  
  1.35      +10 -9     db-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
  
  Index: JdbcAccessImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- JdbcAccessImpl.java	6 Sep 2005 22:19:17 -0000	1.34
  +++ JdbcAccessImpl.java	29 Sep 2005 20:36:41 -0000	1.35
  @@ -31,6 +31,7 @@
   import org.apache.ojb.broker.PersistenceBrokerInternal;
   import org.apache.ojb.broker.PersistenceBrokerSQLException;
   import org.apache.ojb.broker.accesslayer.sql.SqlExistStatement;
  +import org.apache.ojb.broker.accesslayer.sql.SqlStatement;
   import org.apache.ojb.broker.core.ValueContainer;
   import org.apache.ojb.broker.metadata.ArgumentDescriptor;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
  @@ -40,10 +41,10 @@
   import org.apache.ojb.broker.platforms.Platform;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryByCriteria;
  +import org.apache.ojb.broker.util.SqlHelper;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   import org.apache.ojb.broker.util.sequence.SequenceManagerException;
  -import org.apache.ojb.broker.util.SqlHelper;
   
   /**
    * JdbcAccess is responsible for establishing performing
  @@ -299,7 +300,7 @@
           try
           {
               final int queryFetchSize = query.getFetchSize();
  -            final String sql;
  +            final SqlStatement sql;
               if (selectPkOnly)
               {
                   sql = broker.serviceSqlGenerator().getPreparedSelectPkStatement(query,
cld);
  @@ -308,8 +309,8 @@
               {
                   sql = broker.serviceSqlGenerator().getPreparedSelectStatement(query, cld);
               }
  -            final boolean callableStmt = SqlHelper.isStoredProcedure(sql);
  -            PreparedStatement stmt = stmtManager.getPreparedStatement(sql,
  +            final boolean callableStmt = SqlHelper.isStoredProcedure(sql.getStatement());
  +            PreparedStatement stmt = stmtManager.getPreparedStatement(sql.getStatement(),
                       scrollable, queryFetchSize, callableStmt);
   
               ResultSet rs;
  @@ -336,7 +337,7 @@
                   rs = stmt.executeQuery();
               }
   
  -            retval = new ResultSetAndStatement(stmtManager, stmt, rs);
  +            retval = new ResultSetAndStatement(stmtManager, stmt, rs, sql);
               return retval;
           }
           catch (PersistenceBrokerException e)
  @@ -418,7 +419,7 @@
   
               // as we return the resultset for further operations, we cannot release the
statement yet.
               // that has to be done by the JdbcAccess-clients (i.e. RsIterator, ProxyRsIterator
and PkEnumeration.)
  -            retval = new ResultSetAndStatement(broker.serviceStatementManager(), stmt,
rs);
  +            retval = new ResultSetAndStatement(broker.serviceStatementManager(), stmt,
rs, null);
               return retval;
           }
           catch (PersistenceBrokerException e)
  @@ -667,8 +668,8 @@
           PreparedStatement stmt = null;
           try
           {
  -            final String sql = broker.serviceSqlGenerator().getPreparedSelectByPkStatement(cld);
  -            final boolean callableStmt = SqlHelper.isStoredProcedure(sql);
  +            final SqlStatement sql = broker.serviceSqlGenerator().getPreparedSelectByPkStatement(cld);
  +            final boolean callableStmt = SqlHelper.isStoredProcedure(sql.getStatement());
               stmt = broker.serviceStatementManager().getSelectByPKStatement(cld);
               if (stmt == null)
               {
  
  
  
  1.39      +59 -22    db-ojb/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java
  
  Index: RowReaderDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- RowReaderDefaultImpl.java	18 Sep 2005 13:26:14 -0000	1.38
  +++ RowReaderDefaultImpl.java	29 Sep 2005 20:36:41 -0000	1.39
  @@ -25,11 +25,13 @@
   import org.apache.commons.beanutils.ConvertUtils;
   import org.apache.commons.collections.map.ListOrderedMap;
   import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.broker.accesslayer.sql.SelectStatementWrapper;
   import org.apache.ojb.broker.core.factory.ObjectFactory;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CreationDescriptor;
   import org.apache.ojb.broker.metadata.CreationParameter;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
  +import org.apache.ojb.broker.metadata.JdbcType;
   import org.apache.ojb.broker.metadata.MetadataException;
   import org.apache.ojb.broker.util.SqlHelper;
   
  @@ -56,6 +58,7 @@
   
       /** The object factory to be used by this row reader for classes that require it */
       private transient ObjectFactory factory;
  +    private SelectStatementWrapper statementWrapper;
   
       public RowReaderDefaultImpl(ObjectFactory factory, ClassDescriptor classDescriptor)
       {
  @@ -232,6 +235,12 @@
           return (FieldDescriptor[])result.values().toArray(new FieldDescriptor[result.size()]);
       }
   
  +    public void readObjectArrayFrom(ResultSetAndStatement rs, Map row)
  +    {
  +        statementWrapper = (SelectStatementWrapper) rs.m_sql;
  +        readObjectArrayFrom(rs.m_rs, row);
  +    }
  +
       /**
        * materialize a single object, described by cld,
        * from the first row of the ResultSet rs.
  @@ -302,11 +311,41 @@
        * @throws PersistenceBrokerException if there is an error accessing the access layer
        */
       public void readPkValuesFrom(ResultSet rs, Map row)
  -    {
  -        FieldDescriptor[] pkFields = classDescriptor.getPkFields();
  +    {       
  +        String ojbClass = SqlHelper.getOjbClassName(rs);
  +        ClassDescriptor cld;
  +        
  +        if (ojbClass != null)
  +        {
  +            cld = classDescriptor.getRepository().getDescriptorFor(ojbClass);
  +        }
  +        else
  +        {
  +            cld = classDescriptor;
  +        }
  +
  +        FieldDescriptor[] pkFields = cld.getPkFields();
           readValuesFrom(rs, row, pkFields);
       }
   
  +    public void readPkValuesFrom(ResultSetAndStatement rs, Map row)
  +    {
  +        statementWrapper = (SelectStatementWrapper) rs.m_sql;
  +        readPkValuesFrom(rs.m_rs, row);
  +    }
  +    
  +    private int getColumnIndex(FieldDescriptor fld)
  +    {
  +        int index = JdbcType.MIN_INT;
  +        
  +        if (statementWrapper != null)
  +        {
  +            index = statementWrapper.getColumnIndex(fld);
  +        }
  +        
  +        return index;
  +    }
  +
       protected void readValuesFrom(ResultSet rs, Map row, FieldDescriptor[] fields)
       {
           int size = fields.length;
  @@ -319,7 +358,8 @@
                   fld = fields[j];
                   if(!row.containsKey(fld.getColumnName()))
                   {
  -                    val = fld.getJdbcType().getObjectFromColumn(rs, fld.getColumnName());
  +                    int idx = getColumnIndex(fld);
  +                    val = fld.getJdbcType().getObjectFromColumn(rs, null, fld.getColumnName(),
idx);
                       row.put(fld.getColumnName(), fld.getFieldConversion().sqlToJava(val));
                   }
               }
  @@ -342,28 +382,25 @@
           }
           try
           {
  -            String result = (String) discriminatorFD.getJdbcType().getObjectFromColumn(rs,
discriminatorFD.getColumnName());
  +            String result = (String) discriminatorFD.getJdbcType().getObjectFromColumn(rs,
  +                    discriminatorFD.getColumnName());
               result = result != null ? result.trim() : null;
               if (result == null || result.length() == 0)
               {
  -                throw new PersistenceBrokerException(
  -                        "The discriminator field column for class " + cld.getClassNameOfObject()
  -                        + " returned null or 0-length string, discriminator field was:
" + discriminatorFD);
  +                throw new PersistenceBrokerException("The discriminator field column for
class "
  +                        + cld.getClassNameOfObject() + " returned null or 0-length string,
discriminator field was: "
  +                        + discriminatorFD);
               }
  -            else
  -            {
  -                /*
  -                arminw: Make sure that we don't read discriminator field twice from the
ResultSet.
  -                */
  -                row.put(discriminatorFD.getColumnName(), result);
  -                return result;
  -            }
  -        }
  -        catch(SQLException e)
  -        {
  -            throw new PersistenceBrokerException("Unexpected error while try to read 'ojbConcretClass'"
+
  -                    " field from result set using column name " + discriminatorFD.getColumnName()
+ " main class" +
  -                    " was " + classDescriptor.getClassNameOfObject(), e);
  +
  +            // arminw: Make sure that we don't read discriminator field twice from the
ResultSet.
  +            row.put(discriminatorFD.getColumnName(), result);
  +            return result;
  +        }
  +        catch (SQLException e)
  +        {
  +            throw new PersistenceBrokerException("Unexpected error while try to read 'ojbConcretClass'"
  +                    + " field from result set using column name " + discriminatorFD.getColumnName()
+ " main class"
  +                    + " was " + classDescriptor.getClassNameOfObject(), e);
           }
       }
   
  
  
  
  1.15      +5 -2      db-ojb/src/java/org/apache/ojb/broker/accesslayer/ResultSetAndStatement.java
  
  Index: ResultSetAndStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ResultSetAndStatement.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ResultSetAndStatement.java	6 Sep 2005 22:19:17 -0000	1.14
  +++ ResultSetAndStatement.java	29 Sep 2005 20:36:41 -0000	1.15
  @@ -18,6 +18,7 @@
   import java.sql.ResultSet;
   import java.sql.Statement;
   
  +import org.apache.ojb.broker.accesslayer.sql.SqlStatement;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   
  @@ -38,12 +39,14 @@
       */
   	public final ResultSet m_rs;
   	public final Statement m_stmt;
  +    public final SqlStatement m_sql;
   
  -	public ResultSetAndStatement(StatementManager manager, Statement stmt, ResultSet rs)
  +	public ResultSetAndStatement(StatementManager manager, Statement stmt, ResultSet rs, SqlStatement
sql)
   	{
   		this.manager = manager;
           m_stmt = stmt;
           m_rs = rs;
  +        m_sql = sql;
           isClosed = false;
   	}
   
  
  
  
  1.2       +2 -2      db-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementManagerAbstractImpl.java
  
  Index: StatementManagerAbstractImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementManagerAbstractImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StatementManagerAbstractImpl.java	6 Sep 2005 22:19:17 -0000	1.1
  +++ StatementManagerAbstractImpl.java	29 Sep 2005 20:36:41 -0000	1.2
  @@ -154,7 +154,7 @@
       /** return a prepared Select Statement for the given ClassDescriptor */
       public PreparedStatement getSelectByPKStatement(ClassDescriptor cld) throws PersistenceBrokerSQLException,
PersistenceBrokerException
       {
  -        String selectByPKSql = broker.serviceSqlGenerator().getPreparedSelectByPkStatement(cld);
  +        String selectByPKSql = broker.serviceSqlGenerator().getPreparedSelectByPkStatement(cld).getStatement();
           return getPreparedStatement(
                   selectByPKSql,
                   Query.NOT_SCROLLABLE,
  
  
  
  1.11      +80 -68    db-ojb/src/java/org/apache/ojb/broker/accesslayer/RowReader.java
  
  Index: RowReader.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/RowReader.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- RowReader.java	14 Nov 2004 09:33:38 -0000	1.10
  +++ RowReader.java	29 Sep 2005 20:36:41 -0000	1.11
  @@ -1,68 +1,80 @@
  -package org.apache.ojb.broker.accesslayer;
  -
  -/* 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.metadata.ClassDescriptor;
  -
  -import java.io.Serializable;
  -import java.sql.ResultSet;
import java.util.Map;
  -
  -/**
  - * @version $Id$
  - */
  -public interface RowReader extends Serializable
  -{
  -	static final long serialVersionUID = -1283322922537162249L;
  -
  -    /**
  -     * Materialize a single object from the values of the Map row.
  -     * the implementor of this class must not care for materializing
  -     * references or collection attributes, this is done later!
  -     * @param row the Map containing the new values
  -     * @return a properly created instance.
  -     */
  -    public Object readObjectFrom(Map row);
  -
  -    /**
  -     * refresh an existing instance from the values of the Map row.
  -     * @param instance the instance to refresh
  -     * @param row the Map containing the new values
  -     */
  -    public void refreshObject(Object instance, Map row);
  -
  -
  -	/**
  -	 * Read all fields from the current ResultRow into the Object[] row.#
  -	 * ConversionStrategies are applied here!
  -	 */
  -	public void readObjectArrayFrom(ResultSet rs, Map row);
  -
  -	/**
  -	 * Read primary key fields from the current ResultRow into the Object[] row.#
  -	 * ConversionStrategies are applied here!
  -	 */
  -	public void readPkValuesFrom(ResultSet rs, Map row);
  -
  -    /**
  -     * Set the descriptor this <i>RowReader</i> worked with.
  -     */
  -    public void setClassDescriptor(ClassDescriptor cld);
  -
  -    /**
  -     * Returns the associated {@link org.apache.ojb.broker.metadata.ClassDescriptor}
  -     */
  -    public ClassDescriptor getClassDescriptor();
  -}
  +package org.apache.ojb.broker.accesslayer;
  +
  +/* 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.metadata.ClassDescriptor;
  +
  +import java.io.Serializable;
  +import java.sql.ResultSet;
import java.util.Map;
  +
  +/**
  + * @version $Id$
  + */
  +public interface RowReader extends Serializable
  +{
  +	static final long serialVersionUID = -1283322922537162249L;
  +
  +    /**
  +     * Materialize a single object from the values of the Map row.
  +     * the implementor of this class must not care for materializing
  +     * references or collection attributes, this is done later!
  +     * @param row the Map containing the new values
  +     * @return a properly created instance.
  +     */
  +    public Object readObjectFrom(Map row);
  +
  +    /**
  +     * refresh an existing instance from the values of the Map row.
  +     * @param instance the instance to refresh
  +     * @param row the Map containing the new values
  +     */
  +    public void refreshObject(Object instance, Map row);
  +
  +
  +	/**
  +	 * Read all fields from the current ResultRow into the Object[] row.#
  +	 * ConversionStrategies are applied here!
  +	 */
  +	public void readObjectArrayFrom(ResultSet rs, Map row);
  +
  +    /**
  +     * Read all fields from the current ResultRow into the Object[] row.#
  +     * ConversionStrategies are applied here!
  +     */
  +    public void readObjectArrayFrom(ResultSetAndStatement rs, Map row);
  +
  +	/**
  +	 * Read primary key fields from the current ResultRow into the Object[] row.#
  +	 * ConversionStrategies are applied here!
  +	 */
  +	public void readPkValuesFrom(ResultSet rs, Map row);
  +
  +    /**
  +     * Read primary key fields from the current ResultRow into the Object[] row.#
  +     * ConversionStrategies are applied here!
  +     */
  +    public void readPkValuesFrom(ResultSetAndStatement rs, Map row);
  +
  +    /**
  +     * Set the descriptor this <i>RowReader</i> worked with.
  +     */
  +    public void setClassDescriptor(ClassDescriptor cld);
  +
  +    /**
  +     * Returns the associated {@link org.apache.ojb.broker.metadata.ClassDescriptor}
  +     */
  +    public ClassDescriptor getClassDescriptor();
  +}
  
  
  
  1.78      +3 -3      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.77
  retrieving revision 1.78
  diff -u -r1.77 -r1.78
  --- RsIterator.java	27 Aug 2005 12:05:04 -0000	1.77
  +++ RsIterator.java	29 Sep 2005 20:36:41 -0000	1.78
  @@ -409,7 +409,7 @@
           // we need the PK values of result set row
           // provide m_row with primary key data of current row
           RowReader reader = getBroker().getRowReaderFor(getQueryObject().getClassDescriptor());
  -        reader.readPkValuesFrom(getRsAndStmt().m_rs, getRow());
  +        reader.readPkValuesFrom(getRsAndStmt(), getRow());
   
           // 1.read Identity
           Identity oid = getIdentityFromResultSet();
  @@ -421,7 +421,7 @@
           {
   
               // map all field values from the current result set
  -            reader.readObjectArrayFrom(getRsAndStmt().m_rs, getRow());
  +            reader.readObjectArrayFrom(getRsAndStmt(), getRow());
               // 3. If Object is not in cache
               // materialize Object with primitive attributes filled from current row
               result = reader.readObjectFrom(getRow());
  
  
  
  1.87      +2 -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.86
  retrieving revision 1.87
  diff -u -r1.86 -r1.87
  --- QueryTest.java	27 Aug 2005 12:39:54 -0000	1.86
  +++ QueryTest.java	29 Sep 2005 20:36:44 -0000	1.87
  @@ -1957,7 +1957,7 @@
           q.setAttributes(new String[]{"articleId", "price + 10"});
           ClassDescriptor cd = broker.getClassDescriptor(q.getBaseClass());
           SqlGenerator sqlg = broker.serviceSqlGenerator();
  -        String sql = sqlg.getPreparedSelectStatement(q, cd);
  +        String sql = sqlg.getPreparedSelectStatement(q, cd).getStatement();
           
           assertTrue("Bad query generated. SQL Output: " + sql, sql
                   .equalsIgnoreCase("SELECT A0.Artikel_Nr,A0.Einzelpreis + 10 FROM Artikel
A0"));
  @@ -1973,7 +1973,7 @@
           q.setAttributes(new String[]{"articleId", "0.9 * (price * stock)"});
           ClassDescriptor cd = broker.getClassDescriptor(q.getBaseClass());
           SqlGenerator sqlg = broker.serviceSqlGenerator();
  -        String sql = sqlg.getPreparedSelectStatement(q, cd);
  +        String sql = sqlg.getPreparedSelectStatement(q, cd).getStatement();
           
           assertTrue("Bad query generated. SQL Output: " + sql, sql
                   .equalsIgnoreCase("SELECT A0.Artikel_Nr,0.9 * (A0.Einzelpreis * A0.Lagerbestand)
FROM Artikel A0"));
  
  
  
  1.5       +68 -59    db-ojb/src/xdoclet/test/xdoclet/modules/ojb/tests/TestRowReader.java
  
  Index: TestRowReader.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/xdoclet/test/xdoclet/modules/ojb/tests/TestRowReader.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestRowReader.java	14 Nov 2004 09:43:34 -0000	1.4
  +++ TestRowReader.java	29 Sep 2005 20:36:44 -0000	1.5
  @@ -1,59 +1,68 @@
  -package xdoclet.modules.ojb.tests;
  -
  -/* Copyright 2003-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.sql.ResultSet;
  -import java.util.Map;
  -
  -import org.apache.ojb.broker.accesslayer.RowReader;
  -import org.apache.ojb.broker.core.factory.ObjectCreator;
  -import org.apache.ojb.broker.metadata.ClassDescriptor;
  -
  -/**
  - * Row reader class used in some of the unit tests.
  - */
  -public class TestRowReader implements RowReader
  -{
  -    public ClassDescriptor getClassDescriptor()
  -    {
  -        return null;
  -    }
  -
  -    public void readObjectArrayFrom(ResultSet rs, Map row)
  -    {
  -    }
  -
  -    public Object readObjectFrom(Map row)
  -    {
  -        return null;
  -    }
  -
  -    public void readPkValuesFrom(ResultSet rs, Map row)
  -    {
  -    }
  -
  -    public void refreshObject(Object instance, Map row)
  -    {
  -    }
  -
  -    public void setClassDescriptor(ClassDescriptor cld)
  -    {
  -    }
  -
  -    public void setObjectFactory(ObjectCreator factory)
  -    {
  -    }
  -}
  +package xdoclet.modules.ojb.tests;
  +
  +/* Copyright 2003-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.sql.ResultSet;
  +import java.util.Map;
  +
  +import org.apache.ojb.broker.accesslayer.ResultSetAndStatement;
  +import org.apache.ojb.broker.accesslayer.RowReader;
  +import org.apache.ojb.broker.core.factory.ObjectCreator;
  +import org.apache.ojb.broker.metadata.ClassDescriptor;
  +
  +/**
  + * Row reader class used in some of the unit tests.
  + */
  +public class TestRowReader implements RowReader
  +{
  +    public ClassDescriptor getClassDescriptor()
  +    {
  +        return null;
  +    }
  +
  +    public void readObjectArrayFrom(ResultSet rs, Map row)
  +    {
  +    }
  +
  +    public Object readObjectFrom(Map row)
  +    {
  +        return null;
  +    }
  +
  +    public void readPkValuesFrom(ResultSet rs, Map row)
  +    {
  +    }
  +
  +    public void refreshObject(Object instance, Map row)
  +    {
  +    }
  +
  +    public void setClassDescriptor(ClassDescriptor cld)
  +    {
  +    }
  +
  +    public void setObjectFactory(ObjectCreator factory)
  +    {
  +    }
  +
  +    public void readObjectArrayFrom(ResultSetAndStatement rs, Map row)
  +    {
  +    }
  +
  +    public void readPkValuesFrom(ResultSetAndStatement rs, Map row)
  +    {
  +    }
  +}
  
  
  

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