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 SqlSelectStatement.java
Date Fri, 01 Oct 2004 20:12:33 GMT
brj         2004/10/01 13:12:33

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlQueryStatement.java SqlSelectStatement.java
  Log:
  minor refactorings
  
  Revision  Changes    Path
  1.85      +63 -35    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.84
  retrieving revision 1.85
  diff -u -r1.84 -r1.85
  --- SqlQueryStatement.java	24 Sep 2004 19:36:13 -0000	1.84
  +++ SqlQueryStatement.java	1 Oct 2004 20:12:33 -0000	1.85
  @@ -21,6 +21,7 @@
   import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
  +import java.util.StringTokenizer;
   
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.PersistenceBrokerSQLException;
  @@ -143,6 +144,7 @@
           return m_searchCld;
       }
   
  +
   	/**
   	 * Return the TableAlias and the PathInfo for an Attribute name<br>
   	 * field names in functions (ie: sum(name) ) are tried to resolve ie: name
  @@ -275,7 +277,7 @@
       }
   
       /**
  -     * Add the Column to the StringBuffer <br>
  +     * Add the Attribute to the StringBuffer <br>
        *
        * @param aTableAlias
        * @param aPathInfo
  @@ -283,7 +285,7 @@
        * @param buf
        * @return true if appended
        */
  -    protected boolean appendColName(TableAlias aTableAlias, PathInfo aPathInfo, boolean
translate, StringBuffer buf)
  +    protected boolean appendAttribute(TableAlias aTableAlias, PathInfo aPathInfo, boolean
translate, StringBuffer buf)
       {
           String prefix = aPathInfo.prefix;
           String suffix = aPathInfo.suffix;
  @@ -421,12 +423,12 @@
        * @param buf
        * @return
        */
  -	protected boolean appendColName(String attr, boolean useOuterJoins, UserAlias aUserAlias,
StringBuffer buf)
  +	protected boolean appendAttribute(String attr, boolean useOuterJoins, UserAlias aUserAlias,
StringBuffer buf)
       {
   		AttributeInfo attrInfo = getAttributeInfo(attr, useOuterJoins, aUserAlias, getQuery().getPathClasses());
           TableAlias tableAlias = attrInfo.tableAlias;
   
  -        return appendColName(tableAlias, attrInfo.pathInfo, true, buf);
  +        return appendAttribute(tableAlias, attrInfo.pathInfo, true, buf);
       }
   
       /**
  @@ -444,7 +446,7 @@
        * @param buf
        * @return
        */
  -	protected boolean appendColName(String attr, String attrAlias, boolean useOuterJoins,
UserAlias aUserAlias,
  +	protected boolean appendAttribute(String attr, String attrAlias, boolean useOuterJoins,
UserAlias aUserAlias,
               StringBuffer buf)
       {
   		AttributeInfo attrInfo = getAttributeInfo(attr, useOuterJoins, aUserAlias, getQuery().getPathClasses());
  @@ -460,7 +462,7 @@
               pi.suffix = " as " + attrAlias;
           }
   
  -        return appendColName(tableAlias, pi, true, buf);
  +        return appendAttribute(tableAlias, pi, true, buf);
       }
   
       /**
  @@ -514,7 +516,7 @@
                   existingColumns.add(cf.name);
                   
                   buf.append(",");
  -                appendColName(cf.name, "ojb_col_" + ojb_col, false, null, buf);
  +                appendAttribute(cf.name, "ojb_col_" + ojb_col, false, null, buf);
                   ojb_col++;
               }
           }
  @@ -713,7 +715,7 @@
        */
       private void appendBetweenCriteria(TableAlias alias, PathInfo pathInfo, BetweenCriteria
c, StringBuffer buf)
       {
  -        appendColName(alias, pathInfo, c.isTranslateAttribute(), buf);
  +        appendAttribute(alias, pathInfo, c.isTranslateAttribute(), buf);
           buf.append(c.getClause());
           appendParameter(c.getValue(), buf);
           buf.append(" AND ");
  @@ -743,12 +745,12 @@
        */
       private void appendFieldCriteria(TableAlias alias, PathInfo pathInfo, FieldCriteria
c, StringBuffer buf)
       {
  -        appendColName(alias, pathInfo, c.isTranslateAttribute(), buf);
  +        appendAttribute(alias, pathInfo, c.isTranslateAttribute(), buf);
           buf.append(c.getClause());
   
           if (c.isTranslateField())
           {
  -			appendColName((String) c.getValue(), false, c.getUserAlias(), buf);
  +			appendAttribute((String) c.getValue(), false, c.getUserAlias(), buf);
           }
           else
           {
  @@ -766,7 +768,7 @@
        */
       private void appendInCriteria(TableAlias alias, PathInfo pathInfo, InCriteria c, StringBuffer
buf)
       {
  -        appendColName(alias, pathInfo, c.isTranslateAttribute(), buf);
  +        appendAttribute(alias, pathInfo, c.isTranslateAttribute(), buf);
           buf.append(c.getClause());
   
           if (c.getValue() instanceof Collection)
  @@ -802,7 +804,7 @@
        */
       private void appendNullCriteria(TableAlias alias, PathInfo pathInfo, NullCriteria c,
StringBuffer buf)
       {
  -        appendColName(alias, pathInfo, c.isTranslateAttribute(), buf);
  +        appendAttribute(alias, pathInfo, c.isTranslateAttribute(), buf);
           buf.append(c.getClause());
       }
   
  @@ -823,7 +825,7 @@
        */
       private void appendSelectionCriteria(TableAlias alias, PathInfo pathInfo, SelectionCriteria
c, StringBuffer buf)
       {
  -        appendColName(alias, pathInfo, c.isTranslateAttribute(), buf);
  +        appendAttribute(alias, pathInfo, c.isTranslateAttribute(), buf);
           buf.append(c.getClause());
           appendParameter(c.getValue(), buf);
       }
  @@ -836,7 +838,7 @@
        */
       private void appendLikeCriteria(TableAlias alias, PathInfo pathInfo, LikeCriteria c,
StringBuffer buf)
       {
  -        appendColName(alias, pathInfo, c.isTranslateAttribute(), buf);
  +        appendAttribute(alias, pathInfo, c.isTranslateAttribute(), buf);
           buf.append(c.getClause());
           appendParameter(c.getValue(), buf);
   
  @@ -888,6 +890,42 @@
       }
   
       /**
  +     * Answer the SQL-Clause for a SqlCriteria
  +     * @param c SqlCriteria
  +     */
  +    private void appendSQLClause(SqlCriteria c, StringBuffer buf)
  +    {
  +        buf.append(c.getAttribute());
  +    }
  +
  +    /**
  +     * Answer the SQL-Clause for a Query
  +     * @param q Query
  +     */
  +    private void appendSQLClause(Query q, SelectionCriteria c, StringBuffer buf)
  +    {
  +        buf.append("(");
  +        buf.append(getSubQuerySQL(q));
  +        buf.append(")");
  +        buf.append(c.getClause());
  +        appendParameter(c.getValue(), buf);
  +    }
  +
  +    /**
  +     * Answer the SQL-Clause for a IdentityCriterion
  +     * @param c IdentityCriterion
  +     */
  +    private void appendSQLClause(IdentityCriterion c, StringBuffer buf)
  +    {
  +        Iterator iter = c.getCriteriaList().iterator();
  +        
  +        while (iter.hasNext())
  +        {
  +            asSQLStatement((SelectionCriteria)iter.next(), buf);              
  +        }
  +    }
  +
  +    /**
        * Answer the SQL-Clause for a SelectionCriteria
        * If the Criteria references a class with extents an OR-Clause is
        * added for each extent
  @@ -898,32 +936,21 @@
           // BRJ : handle SqlCriteria
           if (c instanceof SqlCriteria)
           {
  -            buf.append(c.getAttribute());
  +            appendSQLClause((SqlCriteria)c, buf);
               return;
           }
           
           // BRJ : criteria attribute is a query
           if (c.getAttribute() instanceof Query)
           {
  -            Query q = (Query) c.getAttribute();
  -            buf.append("(");
  -            buf.append(getSubQuerySQL(q));
  -            buf.append(")");
  -            buf.append(c.getClause());
  -            appendParameter(c.getValue(), buf);
  +            appendSQLClause((Query) c.getAttribute(), c, buf);
               return;
           }
   
           // BRJ : handle IdentityCriteria
           if (c instanceof IdentityCriterion)
           {
  -            IdentityCriterion idc = (IdentityCriterion) c;
  -            Iterator iter = idc.getCriteriaList().iterator();
  -            
  -            while (iter.hasNext())
  -            {
  -                asSQLStatement((SelectionCriteria)iter.next(), buf);              
  -            }
  +            appendSQLClause((IdentityCriterion) c, buf);
               return;
           }
           
  @@ -1456,7 +1483,7 @@
               }
               else
               {            
  -                appendColName(cf.name, false, null, buf);
  +                appendAttribute(cf.name, false, null, buf);
               }
               
               if (!cf.isAscending)
  @@ -1488,7 +1515,7 @@
                   buf.append(",");
               }
   
  -            appendColName(cf.name, false, null, buf);
  +            appendAttribute(cf.name, false, null, buf);
           }
       }
   
  @@ -1640,7 +1667,7 @@
           // do not build join tree for subQuery attribute                  
           if (crit.getAttribute() != null && crit.getAttribute() instanceof String)
           {
  -			buildJoinTreeForColumn((String) crit.getAttribute(), 
  +			buildJoinTreeForAttribute((String) crit.getAttribute(), 
   			        useOuterJoin, crit.getUserAlias(), crit.getPathClasses());
           }
           
  @@ -1648,7 +1675,7 @@
           if (crit instanceof FieldCriteria)
           {
               FieldCriteria cc = (FieldCriteria) crit;
  -			buildJoinTreeForColumn((String) cc.getValue(), useOuterJoin, crit.getUserAlias(), crit.getPathClasses());
  +			buildJoinTreeForAttribute((String) cc.getValue(), useOuterJoin, crit.getUserAlias(),
crit.getPathClasses());
           }
               
       }    
  @@ -1686,9 +1713,9 @@
   	 * functions and the last segment are removed
   	 * ie: avg(accounts.amount) -> accounts
   	 */
  -	private void buildJoinTreeForColumn(String aColName, boolean useOuterJoin, UserAlias aUserAlias,
Map pathClasses)
  +	private void buildJoinTreeForAttribute(String anAttribName, boolean useOuterJoin, UserAlias
aUserAlias, Map pathClasses)
   	{
  -		String pathName = SqlHelper.cleanPath(aColName);
  +		String pathName = SqlHelper.cleanPath(anAttribName);
   		int sepPos = pathName.lastIndexOf(".");
   
   		if (sepPos >= 0)
  @@ -1698,6 +1725,7 @@
   		}
   	}
   
  +	
       /**
        * build the Join-Information if a super reference exists
        *
  
  
  
  1.27      +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.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- SqlSelectStatement.java	24 Jul 2004 19:43:47 -0000	1.26
  +++ SqlSelectStatement.java	1 Oct 2004 20:12:33 -0000	1.27
  @@ -121,7 +121,7 @@
               {
                   buf.append(",");
               }
  -            appendColName(columns[i], false, null, buf);
  +            appendAttribute(columns[i], false, null, buf);
               columnList.add(columns[i]);
           }
           return columnList;
  
  
  

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