cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1166497 - in /cassandra/trunk: drivers/java/CHANGES.txt drivers/java/src/org/apache/cassandra/cql/jdbc/CResultSet.java src/java/org/apache/cassandra/cql/jdbc/TypesMap.java
Date Thu, 08 Sep 2011 01:40:14 GMT
Author: jbellis
Date: Thu Sep  8 01:40:14 2011
New Revision: 1166497

URL: http://svn.apache.org/viewvc?rev=1166497&view=rev
Log:
add jdbc BigDecimal support
patch by Rick Shaw; reviewed by jbellis for CASSANDRA-3153

Modified:
    cassandra/trunk/drivers/java/CHANGES.txt
    cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/CResultSet.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/jdbc/TypesMap.java

Modified: cassandra/trunk/drivers/java/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/trunk/drivers/java/CHANGES.txt?rev=1166497&r1=1166496&r2=1166497&view=diff
==============================================================================
--- cassandra/trunk/drivers/java/CHANGES.txt (original)
+++ cassandra/trunk/drivers/java/CHANGES.txt Thu Sep  8 01:40:14 2011
@@ -2,3 +2,4 @@
  * improve JDBC spec compliance (CASSANDRA-2720, 2754, 3052, 3089)
  * cooperate with other jdbc drivers (CASSANDRA-2842)
  * fix unbox-to-NPE with null primitives (CASSANDRA-2956)
+ * add BigDecimal support (CASSANDRA-3153)

Modified: cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/CResultSet.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/CResultSet.java?rev=1166497&r1=1166496&r2=1166497&view=diff
==============================================================================
--- cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/CResultSet.java (original)
+++ cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/CResultSet.java Thu Sep
 8 01:40:14 2011
@@ -165,28 +165,60 @@ class CResultSet extends AbstractResultS
         throw new SQLFeatureNotSupportedException(NOT_SUPPORTED);
     }
 
-    // Big Decimal (awaiting a new AbstractType implementation)
 
-    public BigDecimal getBigDecimal(int arg0) throws SQLException
+    public BigDecimal getBigDecimal(int index) throws SQLException
     {
-        throw new SQLFeatureNotSupportedException(NOT_SUPPORTED);
+        checkIndex(index);
+        return getBigDecimal(values.get(index - 1));
     }
 
-    public BigDecimal getBigDecimal(int arg0, int arg1) throws SQLException
+    /** @deprecated */
+    public BigDecimal getBigDecimal(int index, int scale) throws SQLException
     {
-        throw new SQLFeatureNotSupportedException(NOT_SUPPORTED);
+        checkIndex(index);
+        return (getBigDecimal(values.get(index - 1))).setScale(scale);
     }
 
-    public BigDecimal getBigDecimal(String arg0) throws SQLException
+    public BigDecimal getBigDecimal(String name) throws SQLException
     {
-        throw new SQLFeatureNotSupportedException(NOT_SUPPORTED);
+        checkName(name);
+        return getBigDecimal(valueMap.get(name));
     }
 
-    public BigDecimal getBigDecimal(String arg0, int arg1) throws SQLException
+    /** @deprecated */
+    public BigDecimal getBigDecimal(String name, int scale) throws SQLException
     {
-        throw new SQLFeatureNotSupportedException(NOT_SUPPORTED);
+        checkName(name);
+        return (getBigDecimal(valueMap.get(name))).setScale(scale);
     }
 
+    private BigDecimal getBigDecimal(TypedColumn column) throws SQLException
+    {
+        checkNotClosed();
+        Object value = column.getValue();
+        wasNull = value == null;
+
+        if (wasNull) return BigDecimal.ZERO;
+
+        if (value instanceof BigDecimal) return (BigDecimal) value;
+
+        if (value instanceof Long) return BigDecimal.valueOf((Long) value);
+        
+        if (value instanceof Double) return BigDecimal.valueOf((Double) value);
+
+        if (value instanceof BigInteger) return new BigDecimal((BigInteger) value);
+
+        try
+        {
+            if (value instanceof String) return (new BigDecimal((String) value));
+        }
+        catch (NumberFormatException e)
+        {
+            throw new SQLSyntaxErrorException(e);
+        }
+
+        throw new SQLSyntaxErrorException(String.format(NOT_TRANSLATABLE, value.getClass().getSimpleName(),
"BigDecimal"));
+    }
     public BigInteger getBigInteger(int index) throws SQLException
     {
         checkIndex(index);

Modified: cassandra/trunk/src/java/org/apache/cassandra/cql/jdbc/TypesMap.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/jdbc/TypesMap.java?rev=1166497&r1=1166496&r2=1166497&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/jdbc/TypesMap.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/jdbc/TypesMap.java Thu Sep  8 01:40:14
2011
@@ -14,6 +14,7 @@ public class TypesMap
         map.put("org.apache.cassandra.db.marshal.BytesType", JdbcBytes.instance);
         map.put("org.apache.cassandra.db.marshal.ColumnCounterType", JdbcCounterColumn.instance);
         map.put("org.apache.cassandra.db.marshal.DateType", JdbcDate.instance);
+        map.put("org.apache.cassandra.db.marshal.DecimalType", JdbcDecimal.instance);
         map.put("org.apache.cassandra.db.marshal.DoubleType", JdbcDouble.instance);
         map.put("org.apache.cassandra.db.marshal.FloatType", JdbcFloat.instance);
         map.put("org.apache.cassandra.db.marshal.IntegerType", JdbcInteger.instance);



Mime
View raw message