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/04/22 01:35:46 UTC

cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/util/db/adapter DB.java DBSapDB.java

dobbs       02/04/21 16:35:46

  Modified:    src/java/org/apache/turbine/util/db SqlExpression.java
               src/java/org/apache/turbine/util/db/adapter DB.java
                        DBSapDB.java
  Log:
  pushed the jdbc date escape string formatting {ts '...'} into the
  database adaptors so I can override it in SapDB.  This part doesn't
  work for equality comparisons in SapDB where clauses -- it seems to
  drop the millisecond resolution which prevents date values from
  matching correctly:
  "{ts '" + new Timestamp(date.getTime()).toString() + "'}"
  
  this does work correctly:
  "{ts '" + date.toString() + "'}"
  
  Revision  Changes    Path
  1.4       +2 -3      jakarta-turbine-2/src/java/org/apache/turbine/util/db/SqlExpression.java
  
  Index: SqlExpression.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/util/db/SqlExpression.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SqlExpression.java	15 Oct 2001 16:27:57 -0000	1.3
  +++ SqlExpression.java	21 Apr 2002 23:35:46 -0000	1.4
  @@ -80,7 +80,7 @@
    *
    * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
    * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
  - * @version $Id: SqlExpression.java,v 1.3 2001/10/15 16:27:57 dlr Exp $
  + * @version $Id: SqlExpression.java,v 1.4 2002/04/21 23:35:46 dobbs Exp $
    */
   public class SqlExpression
   {
  @@ -291,8 +291,7 @@
              else if( criteria instanceof java.util.Date ||
                       criteria instanceof DateKey)
              {
  -               Date dt = criteria instanceof Date?(Date) criteria:((DateKey)criteria).getDate();
  -               criteria = "{ts '" + new Timestamp(dt.getTime()).toString() + "'}";
  +               criteria = db.getDateString((Date)criteria);
              }
              else if( criteria instanceof Boolean )
              {
  
  
  
  1.4       +16 -1     jakarta-turbine-2/src/java/org/apache/turbine/util/db/adapter/DB.java
  
  Index: DB.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/util/db/adapter/DB.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DB.java	12 Sep 2001 17:07:38 -0000	1.3
  +++ DB.java	21 Apr 2002 23:35:46 -0000	1.4
  @@ -58,6 +58,8 @@
   import java.sql.Connection;
   import java.sql.DriverManager;
   import java.sql.SQLException;
  +import java.sql.Timestamp;
  +import java.util.Date;
   
   import javax.sql.ConnectionPoolDataSource;
   import org.apache.turbine.util.db.map.IDMethod;
  @@ -102,7 +104,7 @@
    * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
    * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
    * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
  - * @version $Id: DB.java,v 1.3 2001/09/12 17:07:38 mpoeschl Exp $
  + * @version $Id: DB.java,v 1.4 2002/04/21 23:35:46 dobbs Exp $
    */
   public abstract class DB implements Serializable, IDMethod
   {
  @@ -398,7 +400,20 @@
        * This method is used to format any date string.
        * Database can use different default date formats.
        *
  +     * @param date the Date object to be formatted as a string.
        * @return The proper date formated String.
  +     */
  +    public String getDateString(Date date)
  +    {
  +        return "{ts '" + new Timestamp(date.getTime()).toString() + "'}";
  +    }
  +
  +    /**
  +     * This method is used to format any date string.
  +     * Database can use different default date formats.
  +     *
  +     * @return The proper date formated String.
  +     * @deprecated use getDateString(Date) instead.
        */
       public String getDateString(String dateString)
       {
  
  
  
  1.4       +21 -1     jakarta-turbine-2/src/java/org/apache/turbine/util/db/adapter/DBSapDB.java
  
  Index: DBSapDB.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/util/db/adapter/DBSapDB.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DBSapDB.java	12 Sep 2001 17:07:38 -0000	1.3
  +++ DBSapDB.java	21 Apr 2002 23:35:46 -0000	1.4
  @@ -60,6 +60,7 @@
   import java.sql.ResultSet;
   import java.sql.SQLException;
   import java.sql.Statement;
  +import java.util.Date;
   
   /**
    * This is used to connect to SapDB databases.
  @@ -68,7 +69,7 @@
    *
    * @author <a href="mailto:dave.polito@planetcad.com">Dave Polito</a>
    * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
  - * @version $Id: DBSapDB.java,v 1.3 2001/09/12 17:07:38 mpoeschl Exp $
  + * @version $Id: DBSapDB.java,v 1.4 2002/04/21 23:35:46 dobbs Exp $
    */
   public class DBSapDB
       extends DB
  @@ -186,5 +187,24 @@
           // Tables in SapDB are unlocked when a commit is issued.  The
           // user may have issued a commit but do it here to be sure.
           con.commit();
  +    }
  +
  +    /**
  +     * This method is used to format a date string.
  +     * This implementation uses the following format:
  +     * "{ts '" + date.toString() + "'}"
  +     *
  +     * The default format provided by DB, prevents SapDB from matching
  +     * criteria of the following form:
  +     * <code>"WHERE SOME_DATE_FIELD = " + getDateString(Date)</code>
  +     *
  +     * Whereas, the implementation provided here successfully matches
  +     * that criteria.
  +     *
  +     * @param date the Date object to be formatted as a string.
  +     * @return The proper date formated String.  */
  +    public String getDateString(Date date)
  +    {
  +        return "{ts '" + date.toString() + "'}";
       }
   }
  
  
  

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