fedor 01/09/01 01:37:14
Modified: src/java/org/apache/turbine/om DateKey.java Persistent.java
src/java/org/apache/turbine/util/db SqlExpression.java
Log:
1) implemented Gonzalo's suggestion to use JDBC escapes for dates. Seems to
work well and solves all the inherent problems with dates.
2) reverted my change to DateKey.toString() - it was an attempt to solve the
problem above, but did not work out very well. With the fix above it is no
longer needed, and it was causing inconsistent behaviour - toString()
results were different depending on the history of the DateKey.
3) added save(String) and save(DBConnection) methods to Persistent interface
so that it is enough to cast an object to Persistent to use those methods.
Revision Changes Path
1.3 +3 -2 jakarta-turbine-2/src/java/org/apache/turbine/om/DateKey.java
Index: DateKey.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/om/DateKey.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DateKey.java 2001/08/20 03:49:49 1.2
+++ DateKey.java 2001/09/01 08:37:14 1.3
@@ -155,9 +155,10 @@
public String toString()
{
- if ( key != null )
+ Date dt = getDate();
+ if ( dt != null )
{
- return key.toString();
+ return Long.toString(dt.getTime());
}
return "";
}
1.2 +18 -1 jakarta-turbine-2/src/java/org/apache/turbine/om/Persistent.java
Index: Persistent.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/om/Persistent.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Persistent.java 2001/08/16 05:08:39 1.1
+++ Persistent.java 2001/09/01 08:37:14 1.2
@@ -1,5 +1,7 @@
package org.apache.turbine.om;
+import org.apache.turbine.util.db.pool.DBConnection;
+
/* ====================================================================
* The Apache Software License, Version 1.1
*
@@ -59,7 +61,7 @@
* This interface defines methods related to saving an object
*
* @author <a href="mailto:[EMAIL PROTECTED]">John D. McNally</a>
- * @version $Id: Persistent.java,v 1.1 2001/08/16 05:08:39 jvanzyl Exp $
+ * @version $Id: Persistent.java,v 1.2 2001/09/01 08:37:14 fedor Exp $
*/
public interface Persistent
{
@@ -122,4 +124,19 @@
* Saves the object.
*/
public void save() throws Exception;
+
+ /**
+ * Stores the object in the database. If the object is new,
+ * it inserts it; otherwise an update is performed.
+ */
+ public void save(String dbName) throws Exception;
+
+ /**
+ * Stores the object in the database. If the object is new,
+ * it inserts it; otherwise an update is performed. This method
+ * is meant to be used as part of a transaction, otherwise use
+ * the save() method and the connection details will be handled
+ * internally
+ */
+ public void save(DBConnection dbCon) throws Exception;
}
1.2 +4 -2
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SqlExpression.java 2001/08/16 05:09:49 1.1
+++ SqlExpression.java 2001/09/01 08:37:14 1.2
@@ -59,6 +59,7 @@
import java.util.Date;
import java.util.Iterator;
import java.util.List;
+import java.sql.Timestamp;
import org.apache.turbine.om.DateKey;
import org.apache.turbine.om.ObjectKey;
@@ -79,7 +80,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">John D. McNally</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Daniel Rall</a>
- * @version $Id: SqlExpression.java,v 1.1 2001/08/16 05:09:49 jvanzyl Exp $
+ * @version $Id: SqlExpression.java,v 1.2 2001/09/01 08:37:14 fedor Exp $
*/
public class SqlExpression
{
@@ -290,7 +291,8 @@
else if( criteria instanceof java.util.Date ||
criteria instanceof DateKey)
{
- criteria = db.getDateString(criteria.toString());
+ Date dt = criteria instanceof Date?(Date)
criteria:((DateKey)criteria).getDate();
+ criteria = "{ts '" + new Timestamp(dt.getTime()).toString() + "'}";
}
else if( criteria instanceof Boolean )
{
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]