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 Fri, 21 Mar 2003 19:50:59 GMT
brj         2003/03/21 11:50:59

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlQueryStatement.java SqlDeleteByQuery.java
  Log:
  Query refactoring
  
  Revision  Changes    Path
  1.29      +43 -41    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.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- SqlQueryStatement.java	20 Mar 2003 20:48:47 -0000	1.28
  +++ SqlQueryStatement.java	21 Mar 2003 19:50:59 -0000	1.29
  @@ -193,37 +193,59 @@
           result.pathInfo = pathInfo;
           return result;
       }
  -    
  +   
       /**
  -     * Add the Column to the StringBuffer <br>
  +     * Answer the column name for alias and path info<br>
        * if a FieldDescriptor is found for the Criteria the colName is taken from
        * there otherwise its taken from Criteria. <br>
  +     * if translate try to convert attribute name into column name
  +     * 
  +     * @param aTableAlias
  +     * @param aPathInfo
  +     * @param translate
  +     * @return
  +     */  
  +    protected String getColName(TableAlias aTableAlias, PathInfo aPathInfo, boolean translate)
  +    {
  +        FieldDescriptor fld = null;
  +        String result;
  +
  +        if (translate)
  +        {     
  +            fld = getFieldDescriptor(aTableAlias, aPathInfo);
  +        }
  + 
  +        if (fld != null)
  +        {
  +            result = aTableAlias.alias + "." + fld.getColumnName();
  +        }
  +        else
  +        {
  +            result = aPathInfo.column;
  +        }
  +       
  +       return result;
  +    }
  +    
  +    /**
  +     * Add the Column to the StringBuffer <br>
  +     *
        * @param aTableAlias
        * @param aPathInfo
  +     * @param translate
        * @param buf
        */
  -	protected void appendColName(TableAlias aTableAlias, PathInfo aPathInfo, StringBuffer
buf)
  +	protected void appendColName(TableAlias aTableAlias, PathInfo aPathInfo, boolean translate,
StringBuffer buf)
   	{
  -		FieldDescriptor fld = getField(aTableAlias, aPathInfo);
   		String functionName = aPathInfo.function;
  -		String colName = aPathInfo.column;
  +		String colName = getColName(aTableAlias, aPathInfo ,translate);
   
  -        
           if (functionName != null) // rebuild function contains (
           {
               buf.append(functionName);
           }
   
  -        if (fld != null)
  -        {
  -            buf.append(aTableAlias.alias);
  -            buf.append(".");
  -            buf.append(fld.getColumnName());
  -        }
  -        else
  -        {
  -            buf.append(colName);
  -        }
  +        buf.append(colName);
   
           if (functionName != null) // rebuild function
           {
  @@ -233,11 +255,12 @@
   
       /**
        * Get the FieldDescriptor for the PathInfo
  +     * 
        * @param aTableAlias
        * @param aPathInfo
        * @return FieldDescriptor
        */
  -	protected FieldDescriptor getField(TableAlias aTableAlias, PathInfo aPathInfo)
  +	protected FieldDescriptor getFieldDescriptor(TableAlias aTableAlias, PathInfo aPathInfo)
   	{
   		FieldDescriptor fld = null;
   		String colName = aPathInfo.column;
  @@ -293,31 +316,10 @@
           AttributeInfo attrInfo = getAttributeInfo(attr, useOuterJoins, aUserAlias);
           TableAlias tableAlias = attrInfo.tableAlias;
               
  -        appendColName(tableAlias, attrInfo.pathInfo, buf);
  +        appendColName(tableAlias, attrInfo.pathInfo, true, buf);
       }
   
  -    /**
  -     * Add the Column to the StringBuffer <br>
  -     * if translate try to convert attribute name into column name
  -     * 
  -     * @param aTableAlias
  -     * @param aPathInfo
  -     * @param translate
  -     * @param buf
  -     */
  -    protected void appendColName(TableAlias aTableAlias, PathInfo aPathInfo, boolean translate,
StringBuffer buf)
  -    {
  -        if (translate)
  -        {
  -            appendColName(aTableAlias, aPathInfo, buf);
  -        }
  -        else
  -        {
  -            buf.append(aPathInfo.column);
  -        }
  -        
  -    }
  -    
  +  
       /**
        * appends a WHERE-clause to the Statement
        */
  
  
  
  1.10      +17 -29    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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SqlDeleteByQuery.java	19 Jan 2003 11:50:57 -0000	1.9
  +++ SqlDeleteByQuery.java	21 Mar 2003 19:50:59 -0000	1.10
  @@ -97,42 +97,30 @@
   		return stmt.toString();
   	}
   
  -    /**
  -     * Add the Column to the StringBuffer <br>
  -     * if a FieldDescriptor is found for the Criteria the colName is taken from
  -     * there otherwise its taken from Criteria. <br>
  -     * @param alias
  -     * @param pathInfo
  -     * @param buf
  -     */
  -    protected void appendColName(TableAlias alias, PathInfo pathInfo, StringBuffer buf)
  -    {
  -        FieldDescriptor fld = getField(alias, pathInfo);
  -        String functionName = pathInfo.function;
  -        String colName = pathInfo.column;
  +	/* (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)
  +	 */
  +	protected String getColName(TableAlias aTableAlias, PathInfo aPathInfo, boolean translate)
  +	{
  +        FieldDescriptor fld = null;
  +        String result;
   
  -        
  -        if (functionName != null) // rebuild function contains (
  -        {
  -            buf.append(functionName);
  +        if (translate)
  +        {     
  +            fld = getFieldDescriptor(aTableAlias, aPathInfo);
           }
  -
  + 
           if (fld != null)
           {
               // BRJ : No alias for delete
  -            // buf.append(alias.alias);
  -            // buf.append(".");
  -            buf.append(fld.getColumnName());
  +            result = fld.getColumnName();
           }
           else
           {
  -            buf.append(colName);
  -        }
  -
  -        if (functionName != null) // rebuild function
  -        {
  -            buf.append(")");
  +            result = aPathInfo.column;
           }
  -    }
  +       
  +       return result;
  +   }
   
   }
  
  
  

Mime
View raw message