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/util SqlHelper.java
Date Wed, 08 Jun 2005 19:45:30 GMT
brj         2005/06/08 12:45:30

  Modified:    src/java/org/apache/ojb/broker/query Tag: OJB_1_0_RELEASE
                        ReportQuery.java ReportQueryByCriteria.java
               src/java/org/apache/ojb/broker/accesslayer/sql Tag:
                        OJB_1_0_RELEASE SqlSelectStatement.java
                        SqlQueryStatement.java
               src/java/org/apache/ojb/broker/accesslayer Tag:
                        OJB_1_0_RELEASE ReportQueryRsIterator.java
               src/java/org/apache/ojb/broker/util Tag: OJB_1_0_RELEASE
                        SqlHelper.java
  Log:
  apply field-conversions when using ReportQueries
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.6.2.1   +8 -1      db-ojb/src/java/org/apache/ojb/broker/query/ReportQuery.java
  
  Index: ReportQuery.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/ReportQuery.java,v
  retrieving revision 1.6
  retrieving revision 1.6.2.1
  diff -u -r1.6 -r1.6.2.1
  --- ReportQuery.java	4 Apr 2004 23:53:36 -0000	1.6
  +++ ReportQuery.java	8 Jun 2005 19:45:29 -0000	1.6.2.1
  @@ -1,5 +1,7 @@
   package org.apache.ojb.broker.query;
   
  +import java.util.Map;
  +
   
   /* Copyright 2002-2004 The Apache Software Foundation
    *
  @@ -53,4 +55,9 @@
        */
       String[] getJoinAttributes();
       
  +    /**
  +     * Returns a Map with FieldDescriptors identified by Attribute
  +     * @return Map
  +     */
  +    Map getAttributeFieldDescriptors();
   }
  
  
  
  1.10.2.1  +18 -1     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.10
  retrieving revision 1.10.2.1
  diff -u -r1.10 -r1.10.2.1
  --- ReportQueryByCriteria.java	9 Jun 2004 20:00:44 -0000	1.10
  +++ ReportQueryByCriteria.java	8 Jun 2005 19:45:29 -0000	1.10.2.1
  @@ -1,5 +1,7 @@
   package org.apache.ojb.broker.query;
   
  +import java.util.Map;
  +
   
   /* Copyright 2002-2004 The Apache Software Foundation
    *
  @@ -33,6 +35,9 @@
   
       // define the additional attributes (columns) to be used for the join
       private String[] m_joinAttributes = null;
  +    
  +    // attribute -> FieldDescriptor
  +    private Map m_attrToFld = null;
   
   	/**
   	 * Constructor for ReportQueryByCriteria.
  @@ -173,5 +178,17 @@
   
           return buf.toString();
       }
  +
  +    public Map getAttributeFieldDescriptors()
  +    {
  +        return m_attrToFld;
  +    }
  +
  +    public void setAttributeFieldDescriptors(Map attrToFld)
  +    {
  +        m_attrToFld = attrToFld;
  +    }
  +
  +
       
   }
  
  
  
  No                   revision
  No                   revision
  1.22.2.4  +8 -2      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.22.2.3
  retrieving revision 1.22.2.4
  diff -u -r1.22.2.3 -r1.22.2.4
  --- SqlSelectStatement.java	7 May 2005 16:43:05 -0000	1.22.2.3
  +++ SqlSelectStatement.java	8 Jun 2005 19:45:30 -0000	1.22.2.4
  @@ -22,11 +22,12 @@
   
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
  +import org.apache.ojb.broker.platforms.Platform;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.ReportQuery;
  +import org.apache.ojb.broker.query.ReportQueryByCriteria;
   import org.apache.ojb.broker.util.logging.Logger;
  -import org.apache.ojb.broker.platforms.Platform;
   
   /**
    * Model a SELECT Statement
  @@ -250,6 +251,11 @@
   
           appendOrderByClause(orderByFields, columnList, stmt);
   
  +        if (query instanceof ReportQueryByCriteria)
  +        {
  +             ((ReportQueryByCriteria) query).setAttributeFieldDescriptors(m_attrToFld);
  +        }
  +
           return stmt.toString();
       }
   
  
  
  
  1.75.2.7  +4 -1      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.75.2.6
  retrieving revision 1.75.2.7
  diff -u -r1.75.2.6 -r1.75.2.7
  --- SqlQueryStatement.java	28 May 2005 10:37:15 -0000	1.75.2.6
  +++ SqlQueryStatement.java	8 Jun 2005 19:45:30 -0000	1.75.2.7
  @@ -82,6 +82,7 @@
       private ClassDescriptor m_searchCld;
   
       private int m_aliasCount = 0;
  +    protected HashMap m_attrToFld = new HashMap();   //attribute -> FieldDescriptor
   
       /**
        * Constructor for SqlCriteriaStatement.
  @@ -245,6 +246,8 @@
   
               if (fld != null)
               {
  +                m_attrToFld.put(aPathInfo.path, fld);
  +                
                   // added to suport the super reference descriptor
                   if (!fld.getClassDescriptor().getFullTableName().equals(aTableAlias.table)
&& aTableAlias.hasJoins())
                   {
  
  
  
  No                   revision
  No                   revision
  1.13.2.2  +13 -3     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.2.1
  retrieving revision 1.13.2.2
  diff -u -r1.13.2.1 -r1.13.2.2
  --- ReportQueryRsIterator.java	10 Mar 2005 17:55:30 -0000	1.13.2.1
  +++ ReportQueryRsIterator.java	8 Jun 2005 19:45:30 -0000	1.13.2.2
  @@ -20,8 +20,9 @@
   
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.core.PersistenceBrokerImpl;
  -import org.apache.ojb.broker.query.ReportQuery;
  +import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.metadata.JdbcTypesHelper;
  +import org.apache.ojb.broker.query.ReportQuery;
   
   /**
    * RsIterator for ReportQueries
  @@ -91,13 +92,22 @@
       protected Object getObjectFromResultSet() throws PersistenceBrokerException
       {
           Object[] result = new Object[m_attributeCount];
  +        ReportQuery q =(ReportQuery) getQueryObject().getQuery();
   
           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);
  +                String attr = q.getAttributes()[i];
  +                FieldDescriptor fld = (FieldDescriptor) q.getAttributeFieldDescriptors().get(attr);
  +                Object val =JdbcTypesHelper.getObjectFromColumn(getRsAndStmt().m_rs, new
Integer(jdbcType), i + 1);
  +                
  +                if (fld != null && fld.getFieldConversion() != null)
  +                {
  +                    val = fld.getFieldConversion().sqlToJava(val);
  +                }
  +                result[i] = val;
               }
               catch (SQLException e)
               {
  
  
  
  No                   revision
  No                   revision
  1.24.2.2  +7 -5      db-ojb/src/java/org/apache/ojb/broker/util/SqlHelper.java
  
  Index: SqlHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/SqlHelper.java,v
  retrieving revision 1.24.2.1
  retrieving revision 1.24.2.2
  diff -u -r1.24.2.1 -r1.24.2.2
  --- SqlHelper.java	14 Jan 2005 21:11:31 -0000	1.24.2.1
  +++ SqlHelper.java	8 Jun 2005 19:45:30 -0000	1.24.2.2
  @@ -40,9 +40,11 @@
   		public String column;
   		public String prefix;
   		public String suffix;
  +        public final String path;  //original Path
   
  -		PathInfo(String aPrefix, String aColumn, String aSuffix)
  +		PathInfo(String aPath, String aPrefix, String aColumn, String aSuffix)
           {
  +            path = aPath;
   			column = aColumn;
   			prefix = aPrefix;
   			suffix = aSuffix;
  @@ -83,10 +85,10 @@
           String prefix = null;
           String suffix = null;
           String colName = aPath;
  -
  + 
           if (aPath == null)
           {
  -            return new PathInfo(null, null, null);
  +            return new PathInfo(null, null, null, null);
           }
   
           // ignore leading ( and trailing ) ie: sum(avg(col1))
  @@ -116,6 +118,6 @@
               suffix = aPath.substring(opPos);
           }
           
  -        return new PathInfo(prefix, colName.trim(), suffix);
  +        return new PathInfo(aPath, prefix, colName.trim(), suffix);
       }
   }
  
  
  

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