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 ReportQueryByCriteria.java ReportQueryByCriteriaImpl.java
Date Wed, 08 Jun 2005 20:35:09 GMT
brj         2005/06/08 13:35:09

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql
                        AttributeInfo.java SqlQueryStatement.java
                        SqlSelectStatement.java SqlDeleteByQuery.java
               src/java/org/apache/ojb/broker/accesslayer
                        ReportQueryRsIterator.java
               src/java/org/apache/ojb/broker/query
                        ReportQueryByCriteria.java
                        ReportQueryByCriteriaImpl.java
  Log:
  apply field-conversions when using ReportQueries
  
  Revision  Changes    Path
  1.2       +12 -1     db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/AttributeInfo.java
  
  Index: AttributeInfo.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/AttributeInfo.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AttributeInfo.java	26 Feb 2005 20:02:19 -0000	1.1
  +++ AttributeInfo.java	8 Jun 2005 20:35:09 -0000	1.2
  @@ -90,6 +90,12 @@
       {
           return m_elements.iterator();
       }
  +    
  +    String getAttribute()
  +    {
  +        return m_attribute;
  +    }
  +
   
       /**
        * Increment the extentIndex.
  @@ -148,5 +154,10 @@
           {
               return m_attribute;
           }
  +        
  +        AttributeInfo getParent()
  +        {
  +            return m_parent;
  +        }
       }
   }
  
  
  
  1.99      +16 -12    db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java
  
  Index: SqlQueryStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java,v
  retrieving revision 1.98
  retrieving revision 1.99
  diff -u -r1.98 -r1.99
  --- SqlQueryStatement.java	26 Feb 2005 20:02:19 -0000	1.98
  +++ SqlQueryStatement.java	8 Jun 2005 20:35:09 -0000	1.99
  @@ -65,6 +65,8 @@
       private TableAliasHandler m_tableAliasHandler;
       
       private Map m_attributeCache = new HashMap();
  +    protected HashMap m_attrToFld = new HashMap();   //attribute -> FieldDescriptor
  +
       
       /**
        * Constructor for SqlCriteriaStatement.
  @@ -271,23 +273,25 @@
        * there prefixed with the alias (firstname -> A0.F_NAME).
        *
        * @param aTableAlias the TableAlias
  -     * @param anAttrName the name of the attribute
  +     * @param anAttrInfo the name of the attribute
        * @param translate
        * @return
        */
  -    protected String getColName(TableAlias aTableAlias, String anAttrName, boolean translate)
  +    protected String getColName(TableAlias aTableAlias, SingleAttributeInfo anAttrInfo,
boolean translate)
       {
           FieldDescriptor fld = null;
           String result = null;
  -   
  -
  +        String attrName = anAttrInfo.getAttribute();
  +        
           if (translate)
           {
               // translate attribute name into column name
  -            fld = getFieldDescriptor(aTableAlias, anAttrName);
  +            fld = getFieldDescriptor(aTableAlias, attrName);
   
               if (fld != null)
               {
  +                m_attrToFld.put(anAttrInfo.getParent().getAttribute(), fld);
  +
                   // added to suport the super reference descriptor
                   if (!fld.getClassDescriptor().getFullTableName().equals(aTableAlias.table)
&& aTableAlias.hasJoins())
                   {
  @@ -304,7 +308,7 @@
   
                       if (result == null)
                       {
  -                        result = anAttrName;
  +                        result = attrName;
                       }
                   }
                   else
  @@ -312,20 +316,20 @@
                       result = aTableAlias.alias + "." + fld.getColumnName();
                   }
               }
  -            else if ("*".equals(anAttrName))
  +            else if ("*".equals(attrName))
               {
  -                result = anAttrName;
  +                result = attrName;
               }
               else
               {
                   // throw new IllegalArgumentException("No Field found for : " + aPathInfo.column);
  -                result = anAttrName;
  +                result = attrName;
               }
           }
           else
           {
               // use attribute name
  -            result = anAttrName;
  +            result = attrName;
           }
   
           return result;
  @@ -351,7 +355,7 @@
               {
                   SingleAttributeInfo sai = (SingleAttributeInfo) element;
                   TableAlias alias = sai.getTableAlias();
  -                appendColumn(getColName(alias, sai.getAttribute(), translate), buf);
  +                appendColumn(getColName(alias, sai, translate), buf);
               }
               else
               {
  
  
  
  1.39      +10 -5     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.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- SqlSelectStatement.java	27 Apr 2005 19:21:52 -0000	1.38
  +++ SqlSelectStatement.java	8 Jun 2005 20:35:09 -0000	1.39
  @@ -27,7 +27,7 @@
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryByCriteria;
  -import org.apache.ojb.broker.query.ReportQuery;
  +import org.apache.ojb.broker.query.ReportQueryByCriteria;
   import org.apache.ojb.broker.util.logging.Logger;
   
   /**
  @@ -148,10 +148,10 @@
           Iterator it = getJoinTreeToCriteria().entrySet().iterator();
           List columnList = new ArrayList();
   
  -        if (query instanceof ReportQuery)
  +        if (query instanceof ReportQueryByCriteria)
           {
  -            attributes = ((ReportQuery) query).getAttributes();
  -            joinAttributes = ((ReportQuery) query).getJoinAttributes();
  +            attributes = ((ReportQueryByCriteria) query).getAttributes();
  +            joinAttributes = ((ReportQueryByCriteria) query).getJoinAttributes();
           }
   
           while (it.hasNext())
  @@ -253,6 +253,11 @@
   
           appendOrderByClause(orderByFields, columnList, stmt);
   
  +        if (query instanceof ReportQueryByCriteria)
  +        {
  +           ((ReportQueryByCriteria) query).setAttributeFieldDescriptors(m_attrToFld);
  +        }
  +
           return stmt.toString();
       }
   
  
  
  
  1.20      +7 -6      db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlDeleteByQuery.java
  
  Index: SqlDeleteByQuery.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlDeleteByQuery.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- SqlDeleteByQuery.java	13 Feb 2005 10:18:46 -0000	1.19
  +++ SqlDeleteByQuery.java	8 Jun 2005 20:35:09 -0000	1.20
  @@ -15,6 +15,7 @@
    * limitations under the License.
    */
   
  +import org.apache.ojb.broker.accesslayer.sql.AttributeInfo.SingleAttributeInfo;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.platforms.Platform;
  @@ -57,17 +58,17 @@
   		return stmt.toString();
   	}
   
  -	/* (non-Javadoc)
  -     * @see org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement#getColName(org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.TableAlias,
org.apache.ojb.broker.util.SqlHelper.PathInfo, boolean)
  +	/**
  +     * @see org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement#getColName()
        */
  -    protected String getColName(TableAliasHandler.TableAlias aTableAlias, String attr,
boolean translate)
  +    protected String getColName(TableAliasHandler.TableAlias aTableAlias, SingleAttributeInfo
anAttrInfo, boolean translate)
       {
           FieldDescriptor fld = null;
           String result = null;
   
           if (translate)
           {
  -            fld = getFieldDescriptor(aTableAlias, attr);
  +            fld = getFieldDescriptor(aTableAlias, anAttrInfo.getAttribute());
           }
   
           // BRJ : No alias for delete
  @@ -77,7 +78,7 @@
           }
           else
           {
  -            result = attr;
  +            result = anAttrInfo.getAttribute();
           }
   
          return result;
  
  
  
  1.16      +10 -25    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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- ReportQueryRsIterator.java	13 Apr 2005 19:48:28 -0000	1.15
  +++ ReportQueryRsIterator.java	8 Jun 2005 20:35:09 -0000	1.16
  @@ -24,6 +24,7 @@
   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.query.ReportQueryByCriteria;
   import org.apache.ojb.broker.util.JdbcTypesHelper;
   
   /**
  @@ -37,8 +38,6 @@
       private String[] m_attributes;
       private int m_attributeCount;
       private int[] m_jdbcTypes;
  -    private FieldDescriptor[] m_fieldDescriptors;
  -    
       /**
        * Constructor for ReportQueryRsIterator.
        */
  @@ -54,7 +53,6 @@
               m_attributeCount = q.getAttributes().length;
               
               init_jdbcTypes();
  -            init_fieldDescriptors();
           }
           catch (SQLException e)
           {
  @@ -62,24 +60,7 @@
               throw new PersistenceBrokerException(e);
           }
       }
  -
  -    /**
  -     * 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
  @@ -116,18 +97,22 @@
       {
           Object[] result = new Object[m_attributeCount];
           ResultSet rs = getRsAndStmt().m_rs;
  +        ReportQueryByCriteria q =(ReportQueryByCriteria) getQueryObject().getQuery();
           
           for (int i = 0; i < m_attributeCount; i++)
           {
               try
               {
                   int jdbcType = m_jdbcTypes[i];
  +                String attr = m_attributes[i];
  +                FieldDescriptor fld = (FieldDescriptor) q.getAttributeFieldDescriptors().get(attr);
                   Object value = JdbcTypesHelper.getObjectFromColumn(rs, new Integer(jdbcType),
i + 1);
  -                FieldDescriptor fd = m_fieldDescriptors[i];
  -                if (fd != null)
  +                
  +                if (fld != null && fld.getFieldConversion() != null)
                   {
  -                    value = fd.getFieldConversion().sqlToJava(value);
  +                    value = fld.getFieldConversion().sqlToJava(value);
                   }
  +
                   result[i] = value;
               }
               catch (SQLException e)
  
  
  
  1.14      +16 -2     db-ojb/src/java/org/apache/ojb/broker/query/ReportQueryByCriteria.java
  
  Index: ReportQueryByCriteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/ReportQueryByCriteria.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ReportQueryByCriteria.java	1 Apr 2005 20:28:08 -0000	1.13
  +++ ReportQueryByCriteria.java	8 Jun 2005 20:35:09 -0000	1.14
  @@ -1,5 +1,7 @@
   package org.apache.ojb.broker.query;
   
  +import java.util.Map;
  +
   
   /* Copyright 2002-2004 The Apache Software Foundation
    *
  @@ -24,6 +26,18 @@
    */
   public interface ReportQueryByCriteria extends ReportQuery, QueryByCriteria
   {
  -
  +    /**
  +     * Returns a Map with FieldDescriptors. 
  +     * Key is the Attribute, value the FieldDescriptor.
  +     * @return Map
  +     */
  +    Map getAttributeFieldDescriptors();
  +    
  +    /**
  +     * Sets a Map with FieldDescriptors.
  +     * Key is the Attribute, value the FieldDescriptor.
  +     * @param anFldMap the Map with FieldDescriptors 
  +     */
  +   void  setAttributeFieldDescriptors(Map anFldMap);
   }
   
  
  
  
  1.2       +21 -1     db-ojb/src/java/org/apache/ojb/broker/query/ReportQueryByCriteriaImpl.java
  
  Index: ReportQueryByCriteriaImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/ReportQueryByCriteriaImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ReportQueryByCriteriaImpl.java	1 Apr 2005 20:28:08 -0000	1.1
  +++ ReportQueryByCriteriaImpl.java	8 Jun 2005 20:35:09 -0000	1.2
  @@ -1,5 +1,7 @@
   package org.apache.ojb.broker.query;
   
  +import java.util.Map;
  +
   /* Copyright 2002-2004 The Apache Software Foundation
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
  @@ -34,6 +36,8 @@
   
       // define the additional attributes (columns) to be used for the join
       private String[] m_joinAttributes = null;
  +    
  +    private Map m_attrToFld = null;
   
   	/**
   	 * Constructor for ReportQueryByCriteria.
  @@ -187,5 +191,21 @@
   
           return buf.toString();
       }
  +
  +    /**
  +     * @see ReportQueryByCriteria#getAttributeFieldDescriptors()
  +     */
  +    public Map getAttributeFieldDescriptors()
  +    {
  +        return m_attrToFld;
  +    }
  +
  +    /**
  +     * @see ReportQueryByCriteria#setAttributeFieldDescriptors()
  +     */
  +    public void setAttributeFieldDescriptors(Map anFldMap)
  +    {
  +        m_attrToFld = anFldMap;
  +    }
       
   }
  
  
  

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