You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jm...@apache.org on 2001/04/26 04:07:56 UTC

cvs commit: jakarta-turbine/src/java/org/apache/turbine/util/db Criteria.java SqlExpression.java

jmcnally    01/04/25 19:07:56

  Modified:    src/java/org/apache/turbine/util/db Criteria.java
                        SqlExpression.java
  Log:
  A much needed convenience method for Criteria (Criterion).
  contributed by Eric Dobbs eric@dobbse.net
  
  A fix to generate correct sql for NULL fields in SqlExpression
  contributed by Dave Polito dave.polito@planetcad.com
  
  Revision  Changes    Path
  1.24      +17 -2     jakarta-turbine/src/java/org/apache/turbine/util/db/Criteria.java
  
  Index: Criteria.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/util/db/Criteria.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- Criteria.java	2001/03/06 06:13:57	1.23
  +++ Criteria.java	2001/04/26 02:07:53	1.24
  @@ -78,7 +78,8 @@
    * @author <a href="mailto:frank.kim@clearink.com">Frank Y. Kim</a>
    * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
    * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
  - * @version $Id: Criteria.java,v 1.23 2001/03/06 06:13:57 chrise Exp $
  + * @author <a href="mailto:eric@dobbse.net">Eric Dobbs</a>
  + * @version $Id: Criteria.java,v 1.24 2001/04/26 02:07:53 jmcnally Exp $
    */
   public class Criteria extends Hashtable
   {
  @@ -367,6 +368,20 @@
        * to this Criteria.  This can be used to chain the
        * Criterions to form a more complex where clause.
        *
  +     * @param column String full name of column (for example TABLE.COLUMN).
  +     * @return A Criterion.
  +     */
  +    public Criterion getNewCriterion(String column,
  +                                     Object value, String comparison)
  +    {
  +        return new Criterion(column,value,comparison);
  +    }
  +
  +    /**
  +     * Method to return criterion that is not added automatically
  +     * to this Criteria.  This can be used to chain the
  +     * Criterions to form a more complex where clause.
  +     *
        * @param table String name of table.
        * @param column String name of column.
        * @return A Criterion.
  @@ -1547,7 +1562,7 @@
   
           try
           {
  -            sb.append("\nCurrent SQL: ")
  +            sb.append("\nCurrent Query SQL (may not be complete or applicable): ")
                 .append(BasePeer.createQueryString(this));
           }
           catch (Exception exc) {}
  
  
  
  1.15      +33 -3     jakarta-turbine/src/java/org/apache/turbine/util/db/SqlExpression.java
  
  Index: SqlExpression.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/util/db/SqlExpression.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- SqlExpression.java	2001/04/07 08:12:03	1.14
  +++ SqlExpression.java	2001/04/26 02:07:53	1.15
  @@ -63,6 +63,7 @@
   import org.apache.turbine.util.db.adapter.DB;
   import org.apache.turbine.om.StringKey;
   import org.apache.turbine.om.DateKey;
  +import org.apache.turbine.om.ObjectKey;
   
   /**
    * This class represents a part of an SQL query found in the <code>WHERE</code>
  @@ -75,7 +76,7 @@
    * This class is used primarily by {@link org.apache.turbine.om.peer.BasePeer}.
    *
    * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
  - * @version $Id: SqlExpression.java,v 1.14 2001/04/07 08:12:03 dlr Exp $
  + * @version $Id: SqlExpression.java,v 1.15 2001/04/26 02:07:53 jmcnally Exp $
    */
   public class SqlExpression
   {
  @@ -240,12 +241,41 @@
       {
           // Allow null criteria
           // This will result in queries like
  -        // select * from table where field = null
           // insert into table (name, parent) values ('x', null);
           //
  +        
  +        /* Check to see if the criteria is an ObjectKey
  +         * and if the value of that ObjectKey is null.
  +         * In that case, criteria should be null.
  +         */
  +        
  +        if (criteria != null && criteria instanceof ObjectKey)
  +        {
  +            if (((ObjectKey)criteria).getValue() == null)
  +            {
  +                criteria = null;
  +            }
  +        }
  +        /*  If the criteria is null, check to see comparison
  +         *  is an =, <>, or !=.  If so, replace the comparison
  +         *  with the proper IS or IS NOT.
  +         */
  +        
           if (criteria == null)
           {
  -           criteria = "null";
  +            criteria = "null";
  +            if (comparison.equals(Criteria.EQUAL))
  +            {
  +                comparison = " IS ";
  +            }
  +            else if (comparison.equals(Criteria.NOT_EQUAL))
  +            {
  +                comparison = " IS NOT ";
  +            }
  +            else if (comparison.equals(Criteria.ALT_NOT_EQUAL))
  +            {
  +                comparison = " IS NOT ";
  +            }
           }
           else 
           {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org