You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by do...@apache.org on 2002/02/21 00:57:56 UTC

cvs commit: jakarta-turbine-torque/src/java/org/apache/torque/util BasePeer.java

dobbs       02/02/20 15:57:55

  Modified:    src/java/org/apache/torque/util BasePeer.java
  Log:
  Improve the error message when columns don't conform to the table.column
  form.
  
  Thanks to Kevin Rutherford <ke...@planetcad.com> and Will
  Glass-Husain <wg...@forio.com> for identifying and locating the
  problem
  
  Dan, thanks for reviewing the patch.
  
  Revision  Changes    Path
  1.23      +54 -1     jakarta-turbine-torque/src/java/org/apache/torque/util/BasePeer.java
  
  Index: BasePeer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/util/BasePeer.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- BasePeer.java	26 Jan 2002 02:32:29 -0000	1.22
  +++ BasePeer.java	20 Feb 2002 23:57:55 -0000	1.23
  @@ -110,7 +110,7 @@
    * @author <a href="mailto:frank.kim@clearink.com">Frank Y. Kim</a>
    * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a>
    * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
  - * @version $Id: BasePeer.java,v 1.22 2002/01/26 02:32:29 dlr Exp $
  + * @version $Id: BasePeer.java,v 1.23 2002/02/20 23:57:55 dobbs Exp $
    */
   public abstract class BasePeer implements java.io.Serializable
   {
  @@ -971,6 +971,10 @@
           for (int i=0; i<select.size(); i++)
           {
               String columnName = select.get(i);
  +            if (columnName.indexOf('.') == -1)
  +            {
  +                throw getMalformedColumnNameException("select", columnName);
  +            }
               String tableName = null;
               selectClause.add(columnName);
               int parenPos = columnName.indexOf('(');
  @@ -1060,6 +1064,14 @@
               {
                   String join1 = (String)join.get(i);
                   String join2 = (String)criteria.getJoinR().get(i);
  +                if (join1.indexOf('.') == -1)
  +                {
  +                    throw getMalformedColumnNameException("join",join1);
  +                }
  +                if (join2.indexOf('.') == -1)
  +                {
  +                    throw getMalformedColumnNameException("join",join2);
  +                }
   
                   String tableName = join1.substring(0, join1.indexOf('.'));
                   String table = criteria.getTableForAlias(tableName);
  @@ -1111,6 +1123,10 @@
               for (int i=0; i<orderBy.size(); i++)
               {
                   String orderByColumn = orderBy.get(i);
  +                if (orderByColumn.indexOf('.') == -1)
  +                {
  +                    throw getMalformedColumnNameException("order by",orderByColumn);
  +                }
                   String table = orderByColumn.substring(0,orderByColumn.indexOf('.') );
                   // See if there's a space (between the column list and sort
                   // order in ORDER BY table.column DESC).
  @@ -2096,6 +2112,10 @@
           for (int i=0; i<select.size(); i++)
           {
               String columnName = select.get(i);
  +            if (columnName.indexOf('.') == -1)
  +            {
  +                throw getMalformedColumnNameException("select", columnName);
  +            }
               String tableName = null;
               selectClause.add(columnName);
               int parenPos = columnName.indexOf('(');
  @@ -2182,6 +2202,14 @@
               {
                   String join1 = (String)join.get(i);
                   String join2 = (String)criteria.getJoinR().get(i);
  +                if (join1.indexOf('.') == -1)
  +                {
  +                    throw getMalformedColumnNameException("join",join1);
  +                }
  +                if (join2.indexOf('.') == -1)
  +                {
  +                    throw getMalformedColumnNameException("join",join2);
  +                }
   
                   String tableName = join1.substring(0, join1.indexOf('.'));
                   String table = criteria.getTableForAlias(tableName);
  @@ -2233,6 +2261,10 @@
               for (int i=0; i<orderBy.size(); i++)
               {
                   String orderByColumn = orderBy.get(i);
  +                if (orderByColumn.indexOf('.') == -1)
  +                {
  +                    throw getMalformedColumnNameException("order by",orderByColumn);
  +                }
                   String table = orderByColumn.substring(0,orderByColumn.indexOf('.') );
                   // See if there's a space (between the column list and sort
                   // order in ORDER BY table.column DESC).
  @@ -2299,5 +2331,26 @@
           String sql = query.toString();
           category.debug(sql);
           queryString.append (sql);
  +    }
  +
  +    /**
  +     * return an Exception with the malformed column name error message.
  +     * The error message looks like this:<p>
  +     *
  +     * <code>
  +     *     malformed column name in Criteria [criteriaPhrase]:
  +     *     '[columnName]' is not of the form 'table.column'
  +     * </code>
  +     *
  +     * @param criteriaPhrase a String, one of "select", "join", or "order by"
  +     * @param columnName a String containing the offending column name
  +     */
  +    private static Exception getMalformedColumnNameException(String criteriaPhrase,
  +                                                             String columnName)
  +    {
  +        return new Exception("malformed column name in Criteria "
  +                             + criteriaPhrase + ": '"
  +                             + columnName
  +                             + "' is not of the form 'table.column'");
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>