[cvs] expresso commit by lhamel: add convenience for getting dbname from

JCorporate Ltd jcorp at jcorporate.com
Thu Dec 9 02:38:05 UTC 2004


Log Message:
-----------
add convenience for getting dbname from RequestRegistry

Modified Files:
--------------
    expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc:
        DateTime.java

Revision Data
-------------
Index: DateTime.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc/DateTime.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc/DateTime.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc/DateTime.java -u -r1.22 -r1.23
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc/DateTime.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc/DateTime.java
@@ -64,8 +64,10 @@
 
 package com.jcorporate.expresso.core.misc;
 
+import com.jcorporate.expresso.core.db.DBConnection;
 import com.jcorporate.expresso.core.db.DBException;
 import com.jcorporate.expresso.core.i18n.Messages;
+import com.jcorporate.expresso.core.registry.RequestRegistry;
 import com.jcorporate.expresso.kernel.util.FastStringBuffer;
 import org.apache.log4j.Logger;
 
@@ -95,7 +97,6 @@
      * Constructor
      */
     public DateTime() {
-        super();
     } /* DateTime() */
 
     /**
@@ -115,11 +116,16 @@
     /**
      * Get a date/time field formatted for insertion into a database
      * Value of the date/time is the current date and time
+     * uses db context of RequestRegistry
      *
      * @return String The formatted date time field
      */
     public static String getDateTimeForDB() throws com.jcorporate.expresso.core.db.DBException {
-        return getDateTimeForDB(new Date(), "default");
+        String dbname = RequestRegistry.getDataContext();
+        if (dbname == null) {
+            dbname = DBConnection.DEFAULT_DB_CONTEXT_NAME;
+        }
+        return getDateTimeForDB(new Date(), dbname);
     } /* getDateTimeForDB() */
 
     /**
@@ -193,6 +199,7 @@
     /**
      * Get a date/time field formatted for insertion into a database
      * Value of the date/time is the current date and time
+     * uses db context of RequestRegistry
      *
      * @param year  integer year
      * @param month integer month value
@@ -268,12 +275,13 @@
     /**
      * Get a time field formatted for insertion into a database
      * Value of the time is the current time
+     * uses db context of RequestRegistry
      *
      * @return String The formatted time field
      * @throws DBException upon error
      */
     public static String getTimeForDB() throws com.jcorporate.expresso.core.db.DBException {
-        return getTimeForDB(new Date(), "default");
+        return getTimeForDB(new Date());
     } /* getTimeForDB() */
 
     /**
@@ -295,13 +303,18 @@
 
     /**
      * Get a time field formatted for insertion into a database
+     * uses db context of RequestRegistry
      *
      * @param date the <code>java.util.Date</code> object to format for
      *             the default database
      * @return String The formatted time field
      */
     public static String getTimeForDB(Date date) throws com.jcorporate.expresso.core.db.DBException {
-        return getTimeForDB(date, "default");
+        String dbname = RequestRegistry.getDataContext();
+        if (dbname == null) {
+            dbname = DBConnection.DEFAULT_DB_CONTEXT_NAME;
+        }
+        return getTimeForDB(date, dbname);
     } /* getTimeForDB(Date) */
 
     /**
@@ -346,16 +359,18 @@
      * Get a date field formatted for insertion into a database
      * Value of the date is the current date
      * author 		Yves Henri AMAIZO
+     * uses db context of RequestRegistry
      *
      * @return String The formatted date field
      */
     public static String getDateForDB() throws com.jcorporate.expresso.core.db.DBException {
-        return getDateForDB(new Date(), "default");
+        return getDateForDB(new Date());
     } /* getTimeForDB() */
 
     /**
      * Get a date field formatted for insertion into a database
      * author 		Yves Henri AMAIZO
+     * uses db context of RequestRegistry
      *
      * @param year The year as an integer. ex: 1999
      * @param mon  The month as an integer [0-11]
@@ -368,18 +383,29 @@
         cal.set(Calendar.MONTH, mon);
         cal.set(Calendar.DAY_OF_MONTH, day);
 
-        return getDateForDB(cal.getTime(), "default");
+        String dbname = RequestRegistry.getDataContext();
+        if (dbname == null) {
+            dbname = DBConnection.DEFAULT_DB_CONTEXT_NAME;
+        }
+
+        return getDateForDB(cal.getTime(), dbname);
     } /* getTimeForDB(int, int, int) */
 
     /**
      * Get a time field formatted for insertion into a database
      * author 		Yves Henri AMAIZO
+     * uses db context of RequestRegistry
      *
      * @param date The java.util.Date to format
      * @return String The formatted date field
      */
     public static String getDateForDB(Date date) throws com.jcorporate.expresso.core.db.DBException {
-        return getDateForDB(date, "default");
+        String dbname = RequestRegistry.getDataContext();
+        if (dbname == null) {
+            dbname = DBConnection.DEFAULT_DB_CONTEXT_NAME;
+        }
+
+        return getDateForDB(date, dbname);
     } /* getTimeForDB(Date) */
 
     /**


More information about the cvs mailing list