db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gmon...@apache.org
Subject svn commit: r593210 - in /db/torque: site/trunk/xdocs/changes.xml village/trunk/src/java/com/workingdogs/village/Value.java
Date Thu, 08 Nov 2007 15:45:50 GMT
Author: gmonroe
Date: Thu Nov  8 07:45:49 2007
New Revision: 593210

URL: http://svn.apache.org/viewvc?rev=593210&view=rev
Log:
Fix for TORQUE-53. Added better conversion handling in Village for BigDecimal values.  Double
and Float types will be converted using appropriate constructors rather than the somewhat
buggy BigDecimal(String) constructor.

Also reformatted Value.java to Torque standard line lengths.

Modified:
    db/torque/site/trunk/xdocs/changes.xml
    db/torque/village/trunk/src/java/com/workingdogs/village/Value.java

Modified: db/torque/site/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/db/torque/site/trunk/xdocs/changes.xml?rev=593210&r1=593209&r2=593210&view=diff
==============================================================================
--- db/torque/site/trunk/xdocs/changes.xml (original)
+++ db/torque/site/trunk/xdocs/changes.xml Thu Nov  8 07:45:49 2007
@@ -31,6 +31,11 @@
 
   <body>
   <release version="3.3-RC3" date="in SVN">
+    <action type="fix" dev="gmonroe" issue="TORQUE-53" >
+      Added better handling in Village for BigDecimal values.  Double and
+      Float types will be converted using appropriate constructors rather
+      than the somewhat buggy BigDecimal(String) constructor.
+    </action>
     <action type="add" dev="gmonroe">
       Removed Village meta data check for read only column status.  This is
       not fully supported by a lot of JDBC drivers and causes Torque to 

Modified: db/torque/village/trunk/src/java/com/workingdogs/village/Value.java
URL: http://svn.apache.org/viewvc/db/torque/village/trunk/src/java/com/workingdogs/village/Value.java?rev=593210&r1=593209&r2=593210&view=diff
==============================================================================
--- db/torque/village/trunk/src/java/com/workingdogs/village/Value.java (original)
+++ db/torque/village/trunk/src/java/com/workingdogs/village/Value.java Thu Nov  8 07:45:49
2007
@@ -32,7 +32,8 @@
 import java.util.Calendar;
 
 /**
- * A Value represents a single cell in a database table. In other words, it is the cross
between a row and column and contains the
+ * A Value represents a single cell in a database table. In other words, 
+ * it is the cross between a row and column and contains the
  * information held there.
  *
  * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
@@ -50,7 +51,8 @@
     private int type;
 
     /**
-     * Creates a new Value object based on the ResultSet, columnNumber and type
+     * Creates a new Value object based on the ResultSet, columnNumber and 
+     * type
      *
      * @param rs
      * @param columnNumber
@@ -285,7 +287,8 @@
             // The following form is reported to work and be necessary for
             // Oracle when the blob exceeds 4k.
             byte [] value = this.asBytes();
-            stmt.setBinaryStream(stmtNumber, new java.io.ByteArrayInputStream(value), value.length);
+            stmt.setBinaryStream(stmtNumber, 
+                    new java.io.ByteArrayInputStream(value), value.length);
 
             break;
 
@@ -379,7 +382,14 @@
             {
                 return (BigDecimal) valueObject;
             }
-            else if (isString() || isDouble() || isFloat() || isInt() || isLong() || isShort()
|| isByte())
+            else if ( isDouble() ) {
+                return new BigDecimal((Double) valueObject );
+            }
+            else if ( isFloat() ) 
+            {
+                return new BigDecimal(((Float) valueObject).doubleValue());
+            }
+            else if(isString() || isInt() || isLong() || isShort() || isByte())
             {
                 return new BigDecimal(asString());
             }
@@ -416,7 +426,16 @@
             {
                 return ((BigDecimal) valueObject).setScale(scale);
             }
-            else if (isString() || isDouble() || isFloat() || isInt() || isLong() || isShort()
|| isByte())
+            else if ( isDouble() )
+            {
+                return new BigDecimal((Double) valueObject ).setScale(scale);
+            } 
+            else if ( isFloat() ) 
+            {
+                return new BigDecimal(((Float) valueObject).doubleValue())
+                                .setScale(scale);
+            }
+            else if(isString() || isInt() || isLong() || isShort() || isByte())
             {
                 return new BigDecimal(asString()).setScale(scale);
             }
@@ -575,7 +594,8 @@
             {
                 return ((Integer) valueObject);
             }
-            else if (isString() || isDouble() || isFloat() || isBigDecimal() || isLong()
|| isShort() || isByte())
+            else if (isString() || isDouble() || isFloat() || isBigDecimal() 
+                     || isLong() || isShort() || isByte())
             {
                 return new Integer(asString());
             }
@@ -669,7 +689,8 @@
             {
                 return ((Byte) valueObject);
             }
-            else if (isString() || isDouble() || isFloat() || isInt() || isLong() || isShort()
|| isBigDecimal())
+            else if (isString() || isDouble() || isFloat() || isInt() || 
+                     isLong() || isShort() || isBigDecimal())
             {
                 return new Byte(asString());
             }
@@ -792,7 +813,8 @@
             {
                 return ((Short) valueObject);
             }
-            else if (isString() || isDouble() || isFloat() || isInt() || isLong() || isBigDecimal()
|| isByte())
+            else if (isString() || isDouble() || isFloat() || isInt() || 
+                     isLong() || isBigDecimal() || isByte())
             {
                 return new Short(asString());
             }
@@ -882,7 +904,8 @@
             {
                 return ((Long) valueObject);
             }
-            else if (isString() || isDouble() || isFloat() || isInt() || isBigDecimal() ||
isShort() || isByte())
+            else if (isString() || isDouble() || isFloat() || isInt() || 
+                     isBigDecimal() || isShort() || isByte())
             {
                 return new Long(asString());
             }
@@ -972,7 +995,8 @@
             {
                 return ((Double) valueObject);
             }
-            else if (isString() || isBigDecimal() || isFloat() || isInt() || isLong() ||
isShort() || isByte())
+            else if (isString() || isBigDecimal() || isFloat() || isInt() || 
+                     isLong() || isShort() || isByte())
             {
                 return new Double(asString());
             }
@@ -1062,7 +1086,8 @@
             {
                 return ((Float) valueObject);
             }
-            else if (isString() || isDouble() || isBigDecimal() || isInt() || isLong() ||
isShort() || isByte())
+            else if (isString() || isDouble() || isBigDecimal() || isInt() || 
+                     isLong() || isShort() || isByte())
             {
                 return new Float(asString());
             }
@@ -1123,7 +1148,8 @@
         }
         catch (IllegalArgumentException a)
         {
-            throw new DataSetException("Bad date value - Java Time Objects cannot be earlier
than 1/1/70");
+            throw new DataSetException("Bad date value - " + 
+                    "Java Time Objects cannot be earlier than 1/1/70");
         }
         catch (Exception b)
         {
@@ -1174,7 +1200,8 @@
         }
         catch (IllegalArgumentException a)
         {
-            throw new DataSetException("Bad date value - Java Timestamp Objects cannot be
earlier than 1/1/70");
+            throw new DataSetException("Bad date value - " + 
+                       "Java Timestamp Objects cannot be earlier than 1/1/70");
         }
         catch (Exception b)
         {
@@ -1217,15 +1244,17 @@
             {
                 cal.setTime((Time) valueObject);
 
-                return java.sql.Date.valueOf(cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH)
+ 1) + "-"
-                    + cal.get(Calendar.DAY_OF_MONTH));
+                return java.sql.Date.valueOf(cal.get(Calendar.YEAR) + "-" + 
+                                            (cal.get(Calendar.MONTH) + 1) + "-"
+                                            + cal.get(Calendar.DAY_OF_MONTH));
             }
             else if (isUtilDate())
             {
                 cal.setTime((java.util.Date) valueObject);
 
-                return java.sql.Date.valueOf(cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH)
+ 1) + "-"
-                    + cal.get(Calendar.DAY_OF_MONTH));
+                return java.sql.Date.valueOf(cal.get(Calendar.YEAR) + "-" + 
+                                            (cal.get(Calendar.MONTH) + 1) + "-"
+                                            + cal.get(Calendar.DAY_OF_MONTH));
             }
             else if (isString())
             {
@@ -1238,7 +1267,8 @@
         }
         catch (IllegalArgumentException a)
         {
-            throw new DataSetException("Bad date value - Java Timestamp Objects cannot be
earlier than 1/1/70");
+            throw new DataSetException("Bad date value - " + 
+                    "Java Timestamp Objects cannot be earlier than 1/1/70");
         }
         catch (Exception b)
         {
@@ -1281,15 +1311,17 @@
             {
                 cal.setTime((Time) valueObject);
 
-                return java.sql.Date.valueOf(cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH)
+ 1) + "-"
-                    + cal.get(Calendar.DAY_OF_MONTH));
+                return java.sql.Date.valueOf(cal.get(Calendar.YEAR) + "-" + 
+                                            (cal.get(Calendar.MONTH) + 1) + "-"
+                                            + cal.get(Calendar.DAY_OF_MONTH));
             }
             else if (isUtilDate())
             {
                 cal.setTime((java.util.Date) valueObject);
 
-                return java.sql.Date.valueOf(cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH)
+ 1) + "-"
-                    + cal.get(Calendar.DAY_OF_MONTH));
+                return java.sql.Date.valueOf(cal.get(Calendar.YEAR) + "-" + 
+                                            (cal.get(Calendar.MONTH) + 1) + "-"
+                                            + cal.get(Calendar.DAY_OF_MONTH));
             }
             else
             {
@@ -1298,7 +1330,8 @@
         }
         catch (IllegalArgumentException a)
         {
-            throw new DataSetException("Bad date value - Java java.util.Date Objects cannot
be earlier than 1/1/70");
+            throw new DataSetException("Bad date value - " + 
+                  "Java java.util.Date Objects cannot be earlier than 1/1/70");
         }
         catch (Exception b)
         {
@@ -1485,7 +1518,8 @@
      */
     private boolean isTrue(String value)
     {
-        return (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("t") || value.equalsIgnoreCase("yes")
+        return (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("t") 
+                || value.equalsIgnoreCase("yes")
         || value.equalsIgnoreCase("y") || value.equals("1"));
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message