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/sql SqlQueryStatement.java SqlDeleteByQuery.java
Date Wed, 23 Nov 2005 20:47:35 GMT
brj         2005/11/23 12:47:35

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlQueryStatement.java SqlDeleteByQuery.java
  Log:
  fixed support for quoted columns
  
  Revision  Changes    Path
  1.107     +24 -31    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.106
  retrieving revision 1.107
  diff -u -r1.106 -r1.107
  --- SqlQueryStatement.java	19 Nov 2005 08:45:45 -0000	1.106
  +++ SqlQueryStatement.java	23 Nov 2005 20:47:35 -0000	1.107
  @@ -254,76 +254,68 @@
       }
   
       /**
  -     * Answer the column name for alias and path info.<br>
  +     * Append the column name for alias and path info.<br>
        * if translate try to convert attribute name into column name otherwise use attribute
name<br>
        * if a FieldDescriptor is found for the attribute name the column name is taken from
        * there prefixed with the alias (firstname -> A0.F_NAME).
        *
  -     * @param aTableAlias the TableAlias
        * @param anAttrInfo the name of the attribute
        * @param translate
  +     * @param buf the Buffer
        * @return The column name.
        */
  -    protected String getColName(TableAlias aTableAlias, SingleAttributeInfo anAttrInfo,
boolean translate)
  +    protected void appendColumn(SingleAttributeInfo anAttrInfo, boolean translate, StringBuffer
buf)
       {
  -        FieldDescriptor fld;
  -        String result = null;
  -        String attrName = anAttrInfo.getAttribute();
  +        TableAlias tableAlias = anAttrInfo.getTableAlias();
  +        String colName = anAttrInfo.getAttribute();
   
           // no translation required, use attribute name
           if (!translate)
           {
  -            return attrName;
  +            appendColumn(colName, buf);
  +            return;
           }
   
           // BRJ: special alias for the indirection table has no ClassDescriptor 
  -        if (TableAliasHandler.isMNAlias(aTableAlias))
  +        if (TableAliasHandler.isMNAlias(tableAlias))
           {
  -            return aTableAlias.alias + "." + attrName;
  +            appendColumn(tableAlias, colName, buf);
  +            return;
           }
   
           // translate attribute name into column name
  -        fld = getFieldDescriptor(aTableAlias, attrName);
  +        FieldDescriptor fld = getFieldDescriptor(tableAlias, colName);
   
           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())
  +            if (!fld.getClassDescriptor().getFullTableName().equals(tableAlias.table) &&
tableAlias.hasJoins())
               {
  -                Iterator itr = aTableAlias.joins.iterator();
  +                Iterator itr = tableAlias.joins.iterator();
                   while (itr.hasNext())
                   {
                       Join join = (Join) itr.next();
                       if (join.right.table.equals(fld.getClassDescriptor().getFullTableName()))
                       {
  -                        result = join.right.alias + "." + fld.getColumnName();
  +                        tableAlias = join.right;
  +                        colName = fld.getColumnName();
                           break;
                       }
                   }
  -
  -                if (result == null)
  -                {
  -                    result = attrName;
  -                }
               }
               else
               {
  -                result = aTableAlias.alias + "." + fld.getColumnName();
  +                 colName = fld.getColumnName();
               }
  -        }
  -        else if ("*".equals(attrName))
  -        {
  -            result = attrName;
  +            
  +            appendColumn(tableAlias, colName, buf);            
           }
           else
           {
  -            // throw new IllegalArgumentException("No Field found for : " + aPathInfo.column);
  -            result = attrName;
  +            appendColumn(colName, buf);            
           }
  -
  -        return result;
       }
   
       /**
  @@ -345,8 +337,7 @@
               if (element instanceof SingleAttributeInfo)
               {
                   SingleAttributeInfo sai = (SingleAttributeInfo) element;
  -                TableAlias alias = sai.getTableAlias();
  -                appendColumn(getColName(alias, sai, translate), buf);
  +                appendColumn( sai, translate, buf);
               }
               else
               {
  @@ -470,7 +461,9 @@
   	protected boolean appendAttribute(String anAttribute, boolean useOuterJoins, UserAlias
aUserAlias, StringBuffer buf)
       {
           AttributeInfo attrInfo = getAttributeInfo(anAttribute, useOuterJoins, aUserAlias,
getQuery().getPathClasses());
  -        return appendAttribute(attrInfo, (attrInfo.getTableAlias() != null), buf);
  +        
  +        //BRJ: translate must be true to handle expressions ie. "0.9 * (price * stock)"
  +        return appendAttribute(attrInfo, true, buf);        
       }
   
       /**
  
  
  
  1.22      +12 -26    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.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- SqlDeleteByQuery.java	10 Oct 2005 18:21:14 -0000	1.21
  +++ SqlDeleteByQuery.java	23 Nov 2005 20:47:35 -0000	1.22
  @@ -15,9 +15,8 @@
    * limitations under the License.
    */
   
  -import org.apache.ojb.broker.accesslayer.sql.AttributeInfo.SingleAttributeInfo;
  +import org.apache.ojb.broker.accesslayer.sql.TableAliasHandler.TableAlias;
   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;
  @@ -56,30 +55,17 @@
   
           return stmt.toString();
       }
  -
  -	/**
  -     * @see org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement#getColName()
  +    
  +    /**
  +     * Append a Column with alias: A0 name -> A0.name
  +     * Do NOT use an alias here.
  +     * @param anAlias the TableAlias
  +     * @param aColumn name
  +     * @param buf
        */
  -    protected String getColName(TableAliasHandler.TableAlias aTableAlias, SingleAttributeInfo
anAttrInfo, boolean translate)
  +    protected void appendColumn(TableAlias anAlias, String aColumn, StringBuffer buf)
       {
  -        FieldDescriptor fld = null;
  -        String result = null;
  -
  -        if (translate)
  -        {
  -            fld = getFieldDescriptor(aTableAlias, anAttrInfo.getAttribute());
  -        }
  -
           // BRJ : No alias for delete
  -        if (fld != null)
  -        {
  -            result = fld.getColumnName();
  -        }
  -        else
  -        {
  -            result = anAttrInfo.getAttribute();
  -        }
  -
  -       return result;
  -   }
  +        appendColumn(aColumn, buf);
  +    }    
   }
  
  
  

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