empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1457792 - in /empire-db/trunk/empire-db/src/main/java/org/apache/empire/db: DBDatabase.java DBDatabaseDriver.java DBRowSet.java
Date Mon, 18 Mar 2013 15:04:04 GMT
Author: doebele
Date: Mon Mar 18 15:04:04 2013
New Revision: 1457792

URL: http://svn.apache.org/r1457792
Log:
EMPIREDB-179
Minor change in String to Date conversion.

Modified:
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java?rev=1457792&r1=1457791&r2=1457792&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java Mon Mar 18
15:04:04 2013
@@ -88,6 +88,8 @@ public abstract class DBDatabase extends
     // Database specific date
     public static final DBSystemDate SYSDATE  = new DBSystemDate();
     
+    public static final String DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss.SSSZ";
+    
     public static final String EMPTY_STRING = "\0"; // will be replaced by ''
 
     // Logger

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java?rev=1457792&r1=1457791&r2=1457792&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java Mon
Mar 18 15:04:04 2013
@@ -25,7 +25,6 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.sql.Timestamp;
-import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -39,6 +38,7 @@ import org.apache.empire.commons.StringU
 import org.apache.empire.data.DataMode;
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.exceptions.EmpireSQLException;
+import org.apache.empire.exceptions.InvalidArgumentException;
 import org.apache.empire.exceptions.NotImplementedException;
 import org.apache.empire.exceptions.NotSupportedException;
 import org.slf4j.Logger;
@@ -726,13 +726,19 @@ public abstract class DBDatabaseDriver i
         if ((value instanceof Date)==false)
         {   // Convert String to Date
             try
-            {
-                DateFormat source = DateFormat.getDateInstance(DateFormat.SHORT);
-                Date dt = source.parse(value.toString());
-               datetime = sqlFormat.format(dt);
-            } catch (ParseException e)
-            {
-                log.error("Date parsing error ", e);
+            {	// init DateFormat
+            	String dtValue   = value.toString().trim();
+            	String dtPattern = DBDatabase.DATETIME_PATTERN.substring(0, Math.min(dtValue.length(),
24));  
+                SimpleDateFormat sdFormat = new SimpleDateFormat(dtPattern);
+                // Parse value
+                sdFormat.setLenient(true);
+                Date dt = sdFormat.parse(dtValue);
+                // Format to SQL pattern
+               	datetime = sqlFormat.format(dt);
+            } catch (ParseException e) {
+            	// Invalid date
+                log.error("Unable to parse date value "+datetime, e);
+                throw new InvalidArgumentException("value", value);
             }
         }
         else

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java?rev=1457792&r1=1457791&r2=1457792&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java Mon Mar 18
15:04:04 2013
@@ -736,7 +736,7 @@ public abstract class DBRowSet extends D
                 // Add the value to the command
                 if (empty==false)
                 {   // Check the value
-                    if (col.isAutoGenerated()==false)
+                    if (col.isAutoGenerated()==false && rec.isValidateFieldValues())
                         col.validate(value);
                     // Insert a field
                     cmd.set(col.to(value));



Mime
View raw message