|
From: <mla...@us...> - 2003-12-05 09:26:39
|
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset/datatype
In directory sc8-pr-cvs1:/tmp/cvs-serv11752/src/java/org/dbunit/dataset/datatype
Modified Files:
DateDataType.java TimestampDataType.java
Log Message:
Ability to typecast a string formated as a Timestamp to a Date and vice versa.
Index: DateDataType.java
===================================================================
RCS file: /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset/datatype/DateDataType.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** DateDataType.java 17 May 2003 15:38:52 -0000 1.10
--- DateDataType.java 5 Dec 2003 02:25:59 -0000 1.11
***************
*** 68,78 ****
if (value instanceof String)
{
try
{
! return java.sql.Date.valueOf((String)value);
}
catch (IllegalArgumentException e)
{
! throw new TypeCastException((String)value, e);
}
}
--- 68,95 ----
if (value instanceof String)
{
+ String stringValue = (String)value;
+
+ // Probably a Timestamp, try it just in case!
+ if (stringValue.length() > 10)
+ {
+ try
+ {
+ long time = java.sql.Timestamp.valueOf(stringValue).getTime();
+ return new java.sql.Date(time);
+ // return java.sql.Date.valueOf(new java.sql.Date(time).toString());
+ }
+ catch (IllegalArgumentException e)
+ {
+ // Was not a Timestamp, let java.sql.Date handle this value
+ }
+ }
+
try
{
! return java.sql.Date.valueOf(stringValue);
}
catch (IllegalArgumentException e)
{
! throw new TypeCastException(stringValue, e);
}
}
Index: TimestampDataType.java
===================================================================
RCS file: /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset/datatype/TimestampDataType.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** TimestampDataType.java 17 May 2003 15:38:52 -0000 1.10
--- TimestampDataType.java 5 Dec 2003 02:25:59 -0000 1.11
***************
*** 69,79 ****
if (value instanceof String)
{
try
{
! return java.sql.Timestamp.valueOf((String)value);
}
catch (IllegalArgumentException e)
{
! throw new TypeCastException((String)value, e);
}
}
--- 69,95 ----
if (value instanceof String)
{
+ String stringValue = (String)value;
+
+ // Probably a java.sql.Date, try it just in case!
+ if (stringValue.length() == 10)
+ {
+ try
+ {
+ long time = java.sql.Date.valueOf(stringValue).getTime();
+ return new java.sql.Timestamp(time);
+ }
+ catch (IllegalArgumentException e)
+ {
+ // Was not a java.sql.Date, let Timestamp handle this value
+ }
+ }
+
try
{
! return java.sql.Timestamp.valueOf(stringValue);
}
catch (IllegalArgumentException e)
{
! throw new TypeCastException(stringValue, e);
}
}
|