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 AbstractSqlStatement.java SqlQueryStatement.java SqlSelectStatement.java
Date Fri, 25 Nov 2005 21:42:45 GMT
brj         2005/11/25 13:42:45

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql
                        AbstractSqlStatement.java SqlQueryStatement.java
                        SqlSelectStatement.java
  Log:
  minor refactorings
  
  Revision  Changes    Path
  1.4       +28 -1     db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/AbstractSqlStatement.java
  
  Index: AbstractSqlStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/AbstractSqlStatement.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractSqlStatement.java	10 Oct 2005 18:21:14 -0000	1.3
  +++ AbstractSqlStatement.java	25 Nov 2005 21:42:45 -0000	1.4
  @@ -15,6 +15,7 @@
    * limitations under the License.
    */
   
  +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;
  @@ -121,4 +122,30 @@
   
           return m_sqlString;
       }
  +
  +    /**
  +     * Append a Column with alias: A0 name -> A0.name
  +     * @param tableOrAlias A0
  +     * @param aColumn name
  +     * @param buf
  +     */
  +    protected void appendColumn(String tableOrAlias, String aColumn, StringBuffer buf)
  +    {
  +        appendTable(tableOrAlias, buf);
  +        buf.append(".");
  +        appendColumn(aColumn, buf);
  +    }
  +
  +    /**
  +     * Append a Column with alias: A0 name -> A0.name
  +     * @param anAlias the TableAlias
  +     * @param aColumn name
  +     * @param buf
  +     */
  +    protected void appendColumn(TableAlias anAlias, String aColumn, StringBuffer buf)
  +    {
  +        appendTable(anAlias.alias, buf);
  +        buf.append(".");
  +        appendColumn(aColumn, buf);
  +    }
   }
  
  
  
  1.108     +48 -70    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.107
  retrieving revision 1.108
  diff -u -r1.107 -r1.108
  --- SqlQueryStatement.java	23 Nov 2005 20:47:35 -0000	1.107
  +++ SqlQueryStatement.java	25 Nov 2005 21:42:45 -0000	1.108
  @@ -65,8 +65,7 @@
       private TableAliasHandler m_tableAliasHandler;
       
       private Map m_attributeCache = new HashMap();
  -    protected HashMap m_attrToFld = new HashMap();   //attribute -> FieldDescriptor
  -
  +    private Map m_attrToFld = new HashMap();   //attribute -> FieldDescriptor
       
       /**
        * Constructor for SqlCriteriaStatement.
  @@ -276,7 +275,7 @@
               return;
           }
   
  -        // BRJ: special alias for the indirection table has no ClassDescriptor 
  +        // BRJ: special alias for the indirection table has no ClassDescriptor
           if (TableAliasHandler.isMNAlias(tableAlias))
           {
               appendColumn(tableAlias, colName, buf);
  @@ -286,43 +285,43 @@
           // translate attribute name into column name
           FieldDescriptor fld = getFieldDescriptor(tableAlias, colName);
   
  -        if (fld != null)
  +        if (fld == null)
           {
  -            m_attrToFld.put(anAttrInfo.getParent().getAttribute(), fld);
  +            appendColumn(colName, buf);
  +            return;
  +        }
   
  -            // added to suport the super reference descriptor
  -            if (!fld.getClassDescriptor().getFullTableName().equals(tableAlias.table) &&
tableAlias.hasJoins())
  +        setFieldDescriptorForAttribute(anAttrInfo.getParent().getAttribute(), fld);
  +
  +        // added to suport the super reference descriptor
  +        if (!fld.getClassDescriptor().getFullTableName().equals(tableAlias.table) &&
tableAlias.hasJoins())
  +        {
  +            Iterator itr = tableAlias.joins.iterator();
  +            while (itr.hasNext())
               {
  -                Iterator itr = tableAlias.joins.iterator();
  -                while (itr.hasNext())
  +                Join join = (Join) itr.next();
  +                if (join.right.table.equals(fld.getClassDescriptor().getFullTableName()))
                   {
  -                    Join join = (Join) itr.next();
  -                    if (join.right.table.equals(fld.getClassDescriptor().getFullTableName()))
  -                    {
  -                        tableAlias = join.right;
  -                        colName = fld.getColumnName();
  -                        break;
  -                    }
  +                    tableAlias = join.right;
  +                    colName = fld.getColumnName();
  +                    break;
                   }
               }
  -            else
  -            {
  -                 colName = fld.getColumnName();
  -            }
  -            
  -            appendColumn(tableAlias, colName, buf);            
           }
           else
           {
  -            appendColumn(colName, buf);            
  +            colName = fld.getColumnName();
           }
  +
  +        appendColumn(tableAlias, colName, buf);
       }
   
       /**
        * Add the Attribute to the StringBuffer.
  -     *
  -     * @param attrInfo 
  -     * @param translate flag to indicate translation of attrInfo
  +     * 
  +     * @param attrInfo
  +     * @param translate
  +     *            flag to indicate translation of attrInfo
        * @param buf
        * @return true if appended
        */
  @@ -402,7 +401,6 @@
                       {
                           break;
                       }
  -
                   }
               }
           }
  @@ -481,16 +479,18 @@
        * @param buf
        * @return true if appended
        */
  -	protected boolean appendAttribute(String anAttribute, String attrAlias, boolean useOuterJoins,
UserAlias aUserAlias,
  -            StringBuffer buf)
  +	protected boolean appendAttribute(String anAttribute, String attrAlias, boolean useOuterJoins,
  +            UserAlias aUserAlias, StringBuffer buf)
       {
           String aliasedAttr = anAttribute + " as " + attrAlias;
  -        
  +
           return appendAttribute(aliasedAttr, useOuterJoins, aUserAlias, buf);
       }
   
       /**
  -     * Builds the Join for columns if they are not found among the existingColumns.
  +     * Builds the Join for columns if they are not found among the
  +     * existingColumns.
  +     * 
        * @param columns the list of columns represented by Criteria.Field to ensure
        * @param existingColumns the list of column names (String) that are already appended
        */
  @@ -619,7 +619,6 @@
                   stmt.append(asSQLStatement(crit));
                   stmt.append(")");
               }
  -
           }
       }
   
  @@ -635,8 +634,7 @@
               buf.append(") AND ");
           }
           
  -        appendSQLClause(crit, buf);
  -        
  +        appendSQLClause(crit, buf);        
       }
   
       /**
  @@ -693,7 +691,7 @@
        */
       private String asSQLStatement(Criteria crit)
       {
  -        StringBuffer statement = new StringBuffer();
  +        StringBuffer buf = new StringBuffer();
           Iterator iter = crit.getIterator();
   
           while (iter.hasNext())
  @@ -701,11 +699,11 @@
               Object c = iter.next();
               if (c instanceof Criteria)
               {
  -                asSQLStatement((Criteria) c, statement);
  +                asSQLStatement((Criteria) c, buf);
               }
               else if (c instanceof SelectionCriteria)
               {
  -                asSQLStatement((SelectionCriteria) c, statement);
  +                asSQLStatement((SelectionCriteria) c, buf);
               }
               else
               {
  @@ -716,11 +714,11 @@
           // BRJ : negative Criteria surrounded by NOT (...)
           if (crit.isNegative())
           {
  -            statement.insert(0, " NOT (");
  -            statement.append(")");
  +            buf.insert(0, " NOT (");
  +            buf.append(")");
           }
           
  -        return (statement.length() == 0 ? null : statement.toString());
  +        return (buf.length() == 0 ? null : buf.toString());
       }
   
       /**
  @@ -980,7 +978,6 @@
               // alias null
               appendCriteria(attrInfo, c, buf);
           }
  -
       }
   
       /**
  @@ -1045,7 +1042,6 @@
   	 */
       protected void appendOrderByClause(List orderByFields, List selectedFields, StringBuffer
buf)
       {
  -
           if (orderByFields == null || orderByFields.size() == 0)
           {
               return;
  @@ -1105,32 +1101,6 @@
       }
   
       /**
  -     * Append a Column with alias: A0 name -> A0.name
  -     * @param tableOrAlias A0
  -     * @param aColumn name
  -     * @param buf
  -     */
  -    protected void appendColumn(String tableOrAlias, String aColumn, StringBuffer buf)
  -    {
  -        appendTable(tableOrAlias, buf);
  -        buf.append(".");
  -        appendColumn(aColumn, buf);
  -    }
  -
  -    /**
  -     * Append a Column with alias: A0 name -> A0.name
  -     * @param anAlias the TableAlias
  -     * @param aColumn name
  -     * @param buf
  -     */
  -    protected void appendColumn(TableAlias anAlias, String aColumn, StringBuffer buf)
  -    {
  -        appendTable(anAlias.alias, buf);
  -        buf.append(".");
  -        appendColumn(aColumn, buf);
  -    }
  -
  -    /**
        * Append the TableAlias
        * @param anAlias
        * @param buf
  @@ -1198,7 +1168,6 @@
               {
                   appendJoin(where, buf, join);
               }
  -
           }
       }
   
  @@ -1373,4 +1342,13 @@
           return getPlatform().getJoinSyntaxType();
       }
   
  +    protected Map getAttributesToFieldDescriptors()
  +    {
  +        return m_attrToFld;
  +    }
  +
  +    protected void setFieldDescriptorForAttribute(String anAttribute, FieldDescriptor aFieldDescriptor)
  +    {
  +        m_attrToFld.put(anAttribute, aFieldDescriptor);
  +    }
   }
  
  
  
  1.47      +2 -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.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- SqlSelectStatement.java	10 Oct 2005 18:21:14 -0000	1.46
  +++ SqlSelectStatement.java	25 Nov 2005 21:42:45 -0000	1.47
  @@ -369,7 +369,7 @@
   
           if (query instanceof ReportQueryByCriteria)
           {
  -           ((ReportQueryByCriteria) query).setAttributeFieldDescriptors(m_attrToFld);
  +           ((ReportQueryByCriteria) query).setAttributeFieldDescriptors(getAttributesToFieldDescriptors());
           }
   
           return stmt.toString();
  
  
  

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