cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject git commit: relocate decompose() methods to JDBC types
Date Fri, 20 Jan 2012 22:13:32 GMT
Updated Branches:
  refs/heads/trunk c641acca7 -> b226cf93f


relocate decompose() methods to JDBC types

Patch by Rick Shaw; reviewed by eevans for CASSANDRA-3760


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/b226cf93
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/b226cf93
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/b226cf93

Branch: refs/heads/trunk
Commit: b226cf93f8f3a6b6d7c2863df427656a86dd1361
Parents: c641acc
Author: Eric Evans <eevans@apache.org>
Authored: Fri Jan 20 15:23:41 2012 -0600
Committer: Eric Evans <eevans@apache.org>
Committed: Fri Jan 20 16:11:39 2012 -0600

----------------------------------------------------------------------
 .../cassandra/cql/jdbc/AbstractJdbcType.java       |    1 +
 .../org/apache/cassandra/cql/jdbc/JdbcAscii.java   |    6 +++-
 .../org/apache/cassandra/cql/jdbc/JdbcBoolean.java |   10 ++++++-
 .../org/apache/cassandra/cql/jdbc/JdbcBytes.java   |    5 +++
 .../org/apache/cassandra/cql/jdbc/JdbcDate.java    |    7 ++++
 .../org/apache/cassandra/cql/jdbc/JdbcDecimal.java |   23 +++++++++++++++
 .../org/apache/cassandra/cql/jdbc/JdbcDouble.java  |    5 +++
 .../org/apache/cassandra/cql/jdbc/JdbcFloat.java   |    5 +++
 .../org/apache/cassandra/cql/jdbc/JdbcInt32.java   |    5 +++
 .../org/apache/cassandra/cql/jdbc/JdbcInteger.java |    5 +++
 .../apache/cassandra/cql/jdbc/JdbcLexicalUUID.java |    5 +++
 .../org/apache/cassandra/cql/jdbc/JdbcLong.java    |    5 +++
 .../apache/cassandra/cql/jdbc/JdbcTimeUUID.java    |    5 +++
 .../org/apache/cassandra/cql/jdbc/JdbcUTF8.java    |    7 ++++
 .../org/apache/cassandra/cql/jdbc/JdbcUUID.java    |    7 ++++
 .../org/apache/cassandra/db/marshal/AsciiType.java |    5 +--
 .../apache/cassandra/db/marshal/BooleanType.java   |    5 +--
 .../org/apache/cassandra/db/marshal/BytesType.java |    2 +-
 .../cassandra/db/marshal/CounterColumnType.java    |    2 -
 .../org/apache/cassandra/db/marshal/DateType.java  |    4 +--
 .../apache/cassandra/db/marshal/DecimalType.java   |   14 +--------
 .../apache/cassandra/db/marshal/DoubleType.java    |    5 +--
 .../org/apache/cassandra/db/marshal/FloatType.java |    5 +--
 .../org/apache/cassandra/db/marshal/Int32Type.java |    4 +-
 .../apache/cassandra/db/marshal/IntegerType.java   |    2 +-
 .../cassandra/db/marshal/LexicalUUIDType.java      |    2 +-
 .../org/apache/cassandra/db/marshal/LongType.java  |    4 +-
 .../apache/cassandra/db/marshal/TimeUUIDType.java  |    2 +-
 .../org/apache/cassandra/db/marshal/UTF8Type.java  |    5 +--
 .../org/apache/cassandra/db/marshal/UUIDType.java  |    2 +-
 30 files changed, 117 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/cql/jdbc/AbstractJdbcType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql/jdbc/AbstractJdbcType.java b/src/java/org/apache/cassandra/cql/jdbc/AbstractJdbcType.java
index 551fbd0..3e86e53 100644
--- a/src/java/org/apache/cassandra/cql/jdbc/AbstractJdbcType.java
+++ b/src/java/org/apache/cassandra/cql/jdbc/AbstractJdbcType.java
@@ -36,4 +36,5 @@ public abstract class AbstractJdbcType<T>
     public abstract Class<T> getType();
     public abstract int getJdbcType();
     public abstract T compose(ByteBuffer bytes);
+    public abstract ByteBuffer decompose(T obj);
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/cql/jdbc/JdbcAscii.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql/jdbc/JdbcAscii.java b/src/java/org/apache/cassandra/cql/jdbc/JdbcAscii.java
index f4fd325..f4c4f17 100644
--- a/src/java/org/apache/cassandra/cql/jdbc/JdbcAscii.java
+++ b/src/java/org/apache/cassandra/cql/jdbc/JdbcAscii.java
@@ -96,5 +96,9 @@ public class JdbcAscii extends AbstractJdbcType<String>
     {
         return getString(bytes);
     }
-
+    
+    public ByteBuffer decompose(String value)
+    {
+        return ByteBufferUtil.bytes(value, Charsets.US_ASCII);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/cql/jdbc/JdbcBoolean.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql/jdbc/JdbcBoolean.java b/src/java/org/apache/cassandra/cql/jdbc/JdbcBoolean.java
index ea610cb..99b5805 100644
--- a/src/java/org/apache/cassandra/cql/jdbc/JdbcBoolean.java
+++ b/src/java/org/apache/cassandra/cql/jdbc/JdbcBoolean.java
@@ -24,6 +24,8 @@ package org.apache.cassandra.cql.jdbc;
 import java.nio.ByteBuffer;
 import java.sql.Types;
 
+import org.apache.cassandra.utils.ByteBufferUtil;
+
 public class JdbcBoolean extends AbstractJdbcType<Boolean>
 {
     public static final JdbcBoolean instance = new JdbcBoolean();
@@ -95,5 +97,11 @@ public class JdbcBoolean extends AbstractJdbcType<Boolean>
         byte value = bytes.get(bytes.position());
         return Boolean.valueOf(value ==0 ? false:true);
     }
-
+    
+    public ByteBuffer decompose(Boolean value)
+    {
+      return (value==null) ? ByteBufferUtil.EMPTY_BYTE_BUFFER
+                           : value ? ByteBuffer.wrap(new byte[]{1})  // true
+                                   : ByteBuffer.wrap(new byte[]{0}); // false
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/cql/jdbc/JdbcBytes.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql/jdbc/JdbcBytes.java b/src/java/org/apache/cassandra/cql/jdbc/JdbcBytes.java
index 397de2d..cbb6355 100644
--- a/src/java/org/apache/cassandra/cql/jdbc/JdbcBytes.java
+++ b/src/java/org/apache/cassandra/cql/jdbc/JdbcBytes.java
@@ -87,4 +87,9 @@ public class JdbcBytes extends AbstractJdbcType<ByteBuffer>
     {
         return bytes.duplicate();
     }
+    
+    public ByteBuffer decompose(ByteBuffer value)
+    {
+        return value;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/cql/jdbc/JdbcDate.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql/jdbc/JdbcDate.java b/src/java/org/apache/cassandra/cql/jdbc/JdbcDate.java
index ae4bb39..44c2274 100644
--- a/src/java/org/apache/cassandra/cql/jdbc/JdbcDate.java
+++ b/src/java/org/apache/cassandra/cql/jdbc/JdbcDate.java
@@ -113,4 +113,11 @@ public class JdbcDate extends AbstractJdbcType<Date>
     {
         return new Date(ByteBufferUtil.toLong(bytes));
     }
+    
+    public ByteBuffer decompose(Date value)
+    {
+      return (value==null) ? ByteBufferUtil.EMPTY_BYTE_BUFFER
+                           : ByteBufferUtil.bytes(value.getTime());
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/cql/jdbc/JdbcDecimal.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql/jdbc/JdbcDecimal.java b/src/java/org/apache/cassandra/cql/jdbc/JdbcDecimal.java
index f97634e..3792795 100644
--- a/src/java/org/apache/cassandra/cql/jdbc/JdbcDecimal.java
+++ b/src/java/org/apache/cassandra/cql/jdbc/JdbcDecimal.java
@@ -25,6 +25,8 @@ import java.math.BigInteger;
 import java.nio.ByteBuffer;
 import java.sql.Types;
 
+import org.apache.cassandra.utils.ByteBufferUtil;
+
 public class JdbcDecimal extends AbstractJdbcType<BigDecimal>
 {
     public static final JdbcDecimal instance = new JdbcDecimal();
@@ -96,4 +98,25 @@ public class JdbcDecimal extends AbstractJdbcType<BigDecimal>
         BigInteger bi = new BigInteger(bibytes);
         return new BigDecimal(bi,scale);
     }
+
+    /**
+     * The bytes of the ByteBuffer are made up of 4 bytes of int containing the scale
+     * followed by the n bytes it takes to store a BigInteger.
+     */
+    public ByteBuffer decompose(BigDecimal value)
+    {
+        if (value == null) return ByteBufferUtil.EMPTY_BYTE_BUFFER;
+        
+        BigInteger bi = value.unscaledValue();
+        Integer scale = value.scale();
+        byte[] bibytes = bi.toByteArray();
+        byte[] sbytes = ByteBufferUtil.bytes(scale).array();
+        byte[] bytes = new byte[bi.toByteArray().length+4];
+        
+        for (int i = 0 ; i < 4 ; i++) bytes[i] = sbytes[i];
+        for (int i = 4 ; i < bibytes.length+4 ; i++) bytes[i] = bibytes[i-4];
+        
+        return ByteBuffer.wrap(bytes);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/cql/jdbc/JdbcDouble.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql/jdbc/JdbcDouble.java b/src/java/org/apache/cassandra/cql/jdbc/JdbcDouble.java
index 89f3d28..6036608 100644
--- a/src/java/org/apache/cassandra/cql/jdbc/JdbcDouble.java
+++ b/src/java/org/apache/cassandra/cql/jdbc/JdbcDouble.java
@@ -95,4 +95,9 @@ public class JdbcDouble extends AbstractJdbcType<Double>
     {
         return ByteBufferUtil.toDouble(bytes);
     }
+    
+    public ByteBuffer decompose(Double value)
+    {
+        return (value==null) ? ByteBufferUtil.EMPTY_BYTE_BUFFER : ByteBufferUtil.bytes(value);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/cql/jdbc/JdbcFloat.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql/jdbc/JdbcFloat.java b/src/java/org/apache/cassandra/cql/jdbc/JdbcFloat.java
index e06e860..82d755b 100644
--- a/src/java/org/apache/cassandra/cql/jdbc/JdbcFloat.java
+++ b/src/java/org/apache/cassandra/cql/jdbc/JdbcFloat.java
@@ -95,4 +95,9 @@ public class JdbcFloat extends AbstractJdbcType<Float>
     {
         return ByteBufferUtil.toFloat(bytes);
     }
+    
+    public ByteBuffer decompose(Float value)
+    {
+        return (value==null) ? ByteBufferUtil.EMPTY_BYTE_BUFFER : ByteBufferUtil.bytes(value);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/cql/jdbc/JdbcInt32.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql/jdbc/JdbcInt32.java b/src/java/org/apache/cassandra/cql/jdbc/JdbcInt32.java
index 21bdc33..5a05a80 100644
--- a/src/java/org/apache/cassandra/cql/jdbc/JdbcInt32.java
+++ b/src/java/org/apache/cassandra/cql/jdbc/JdbcInt32.java
@@ -97,4 +97,9 @@ public class JdbcInt32 extends AbstractJdbcType<Integer>
     {
         return ByteBufferUtil.toInt(bytes);
     }
+
+    public ByteBuffer decompose(Integer value)
+    {
+        return ByteBufferUtil.bytes(value);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/cql/jdbc/JdbcInteger.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql/jdbc/JdbcInteger.java b/src/java/org/apache/cassandra/cql/jdbc/JdbcInteger.java
index b1f68b0..358a1a4 100644
--- a/src/java/org/apache/cassandra/cql/jdbc/JdbcInteger.java
+++ b/src/java/org/apache/cassandra/cql/jdbc/JdbcInteger.java
@@ -92,4 +92,9 @@ public class JdbcInteger extends AbstractJdbcType<BigInteger>
     {
         return new BigInteger(ByteBufferUtil.getArray(bytes));
     }
+
+    public ByteBuffer decompose(BigInteger value)
+    {
+        return ByteBuffer.wrap(value.toByteArray());
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/cql/jdbc/JdbcLexicalUUID.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql/jdbc/JdbcLexicalUUID.java b/src/java/org/apache/cassandra/cql/jdbc/JdbcLexicalUUID.java
index ea39232..30fbdee 100644
--- a/src/java/org/apache/cassandra/cql/jdbc/JdbcLexicalUUID.java
+++ b/src/java/org/apache/cassandra/cql/jdbc/JdbcLexicalUUID.java
@@ -49,4 +49,9 @@ public class JdbcLexicalUUID extends AbstractJdbcUUID
     {
         return UUIDGen.getUUID(bytes);
     }
+
+    public ByteBuffer decompose(UUID value)
+    {
+        return ByteBuffer.wrap(UUIDGen.decompose(value));
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/cql/jdbc/JdbcLong.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql/jdbc/JdbcLong.java b/src/java/org/apache/cassandra/cql/jdbc/JdbcLong.java
index b6c6e27..c54d871 100644
--- a/src/java/org/apache/cassandra/cql/jdbc/JdbcLong.java
+++ b/src/java/org/apache/cassandra/cql/jdbc/JdbcLong.java
@@ -97,4 +97,9 @@ public class JdbcLong extends AbstractJdbcType<Long>
     {
         return ByteBufferUtil.toLong(bytes);
     }
+
+    public ByteBuffer decompose(Long value)
+    {
+        return ByteBufferUtil.bytes(value);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/cql/jdbc/JdbcTimeUUID.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql/jdbc/JdbcTimeUUID.java b/src/java/org/apache/cassandra/cql/jdbc/JdbcTimeUUID.java
index 3fc7db4..314ab82 100644
--- a/src/java/org/apache/cassandra/cql/jdbc/JdbcTimeUUID.java
+++ b/src/java/org/apache/cassandra/cql/jdbc/JdbcTimeUUID.java
@@ -54,4 +54,9 @@ public class JdbcTimeUUID extends AbstractJdbcUUID
     {
         return UUIDGen.getUUID(bytes);
     }
+
+    public ByteBuffer decompose(UUID value)
+    {
+        return ByteBuffer.wrap(UUIDGen.decompose(value));
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/cql/jdbc/JdbcUTF8.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql/jdbc/JdbcUTF8.java b/src/java/org/apache/cassandra/cql/jdbc/JdbcUTF8.java
index d7379c0..1d8aba9 100644
--- a/src/java/org/apache/cassandra/cql/jdbc/JdbcUTF8.java
+++ b/src/java/org/apache/cassandra/cql/jdbc/JdbcUTF8.java
@@ -27,6 +27,8 @@ import java.sql.Types;
 
 import org.apache.cassandra.utils.ByteBufferUtil;
 
+import com.google.common.base.Charsets;
+
 public class JdbcUTF8 extends AbstractJdbcType<String>
 {
     public static final JdbcUTF8 instance = new JdbcUTF8();
@@ -94,4 +96,9 @@ public class JdbcUTF8 extends AbstractJdbcType<String>
     {
         return getString(bytes);
     }
+
+    public ByteBuffer decompose(String value)
+    {
+        return ByteBufferUtil.bytes(value, Charsets.UTF_8);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/cql/jdbc/JdbcUUID.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql/jdbc/JdbcUUID.java b/src/java/org/apache/cassandra/cql/jdbc/JdbcUUID.java
index a375c81..375c1f0 100644
--- a/src/java/org/apache/cassandra/cql/jdbc/JdbcUUID.java
+++ b/src/java/org/apache/cassandra/cql/jdbc/JdbcUUID.java
@@ -24,6 +24,8 @@ package org.apache.cassandra.cql.jdbc;
 import java.nio.ByteBuffer;
 import java.util.UUID;
 
+import org.apache.cassandra.utils.UUIDGen;
+
 public class JdbcUUID extends AbstractJdbcUUID
 {
     public static final JdbcUUID instance = new JdbcUUID();
@@ -51,4 +53,9 @@ public class JdbcUUID extends AbstractJdbcUUID
         
         return compose(bytes).toString();
     }
+
+    public ByteBuffer decompose(UUID value)
+    {
+        return ByteBuffer.wrap(UUIDGen.decompose(value));
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/db/marshal/AsciiType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/AsciiType.java b/src/java/org/apache/cassandra/db/marshal/AsciiType.java
index b759f7f..9522f09 100644
--- a/src/java/org/apache/cassandra/db/marshal/AsciiType.java
+++ b/src/java/org/apache/cassandra/db/marshal/AsciiType.java
@@ -23,10 +23,7 @@ package org.apache.cassandra.db.marshal;
 
 import java.nio.ByteBuffer;
 
-import com.google.common.base.Charsets;
-
 import org.apache.cassandra.cql.jdbc.JdbcAscii;
-import org.apache.cassandra.utils.ByteBufferUtil;
 
 public class AsciiType extends AbstractType<String>
 {
@@ -58,7 +55,7 @@ public class AsciiType extends AbstractType<String>
 
     public ByteBuffer decompose(String value)
     {
-        return ByteBufferUtil.bytes(value, Charsets.US_ASCII);
+        return JdbcAscii.instance.decompose(value);
     }
 
     public ByteBuffer fromString(String source)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/db/marshal/BooleanType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/BooleanType.java b/src/java/org/apache/cassandra/db/marshal/BooleanType.java
index 5bddc3c..00af80a 100644
--- a/src/java/org/apache/cassandra/db/marshal/BooleanType.java
+++ b/src/java/org/apache/cassandra/db/marshal/BooleanType.java
@@ -23,7 +23,6 @@ package org.apache.cassandra.db.marshal;
 import java.nio.ByteBuffer;
 
 import org.apache.cassandra.cql.jdbc.JdbcBoolean;
-import org.apache.cassandra.utils.ByteBufferUtil;
 
 public class BooleanType extends AbstractType<Boolean>
 {
@@ -38,9 +37,7 @@ public class BooleanType extends AbstractType<Boolean>
 
   public ByteBuffer decompose(Boolean value)
   {
-    return (value==null) ? ByteBufferUtil.EMPTY_BYTE_BUFFER
-                         : value ? ByteBuffer.wrap(new byte[]{1})  // true
-                                 : ByteBuffer.wrap(new byte[]{0}); // false
+      return JdbcBoolean.instance.decompose(value);
   }
   
   public int compare(ByteBuffer o1, ByteBuffer o2)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/db/marshal/BytesType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/BytesType.java b/src/java/org/apache/cassandra/db/marshal/BytesType.java
index 5da76f4..7ab70df 100644
--- a/src/java/org/apache/cassandra/db/marshal/BytesType.java
+++ b/src/java/org/apache/cassandra/db/marshal/BytesType.java
@@ -40,7 +40,7 @@ public class BytesType extends AbstractType<ByteBuffer>
 
     public ByteBuffer decompose(ByteBuffer value)
     {
-        return value;
+        return JdbcBytes.instance.decompose(value);
     }
     
     public int compare(ByteBuffer o1, ByteBuffer o2)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/db/marshal/CounterColumnType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/CounterColumnType.java b/src/java/org/apache/cassandra/db/marshal/CounterColumnType.java
index 52b7f24..6dbd2cb 100644
--- a/src/java/org/apache/cassandra/db/marshal/CounterColumnType.java
+++ b/src/java/org/apache/cassandra/db/marshal/CounterColumnType.java
@@ -20,12 +20,10 @@
  */
 package org.apache.cassandra.db.marshal;
 
-import java.net.InetAddress;
 import java.nio.ByteBuffer;
 
 import org.apache.cassandra.db.*;
 import org.apache.cassandra.utils.ByteBufferUtil;
-import org.apache.cassandra.utils.HeapAllocator;
 
 public class CounterColumnType extends AbstractCommutativeType
 {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/db/marshal/DateType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/DateType.java b/src/java/org/apache/cassandra/db/marshal/DateType.java
index affeb07..a8dbcef 100644
--- a/src/java/org/apache/cassandra/db/marshal/DateType.java
+++ b/src/java/org/apache/cassandra/db/marshal/DateType.java
@@ -47,11 +47,9 @@ public class DateType extends AbstractType<Date>
     
     public ByteBuffer decompose(Date value)
     {
-      return (value==null) ? ByteBufferUtil.EMPTY_BYTE_BUFFER
-                           : ByteBufferUtil.bytes(value.getTime());
+        return JdbcDate.instance.decompose(value);
     }
     
-
     public int compare(ByteBuffer o1, ByteBuffer o2)
     {
         if (o1.remaining() == 0)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/db/marshal/DecimalType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/DecimalType.java b/src/java/org/apache/cassandra/db/marshal/DecimalType.java
index e98e228..1c44b97 100644
--- a/src/java/org/apache/cassandra/db/marshal/DecimalType.java
+++ b/src/java/org/apache/cassandra/db/marshal/DecimalType.java
@@ -21,7 +21,6 @@ package org.apache.cassandra.db.marshal;
  */
 
 import java.math.BigDecimal;
-import java.math.BigInteger;
 import java.nio.ByteBuffer;
 
 import org.apache.cassandra.cql.jdbc.JdbcDecimal;
@@ -58,18 +57,7 @@ public class DecimalType extends AbstractType<BigDecimal>
      */
     public ByteBuffer decompose(BigDecimal value)
     {
-        if (value == null) return ByteBufferUtil.EMPTY_BYTE_BUFFER;
-        
-        BigInteger bi = value.unscaledValue();
-        Integer scale = value.scale();
-        byte[] bibytes = bi.toByteArray();
-        byte[] sbytes = ByteBufferUtil.bytes(scale).array();
-        byte[] bytes = new byte[bi.toByteArray().length+4];
-        
-        for (int i = 0 ; i < 4 ; i++) bytes[i] = sbytes[i];
-        for (int i = 4 ; i < bibytes.length+4 ; i++) bytes[i] = bibytes[i-4];
-        
-        return ByteBuffer.wrap(bytes);
+        return JdbcDecimal.instance.decompose(value);
     }
 
     public String getString(ByteBuffer bytes)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/db/marshal/DoubleType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/DoubleType.java b/src/java/org/apache/cassandra/db/marshal/DoubleType.java
index 728477d..44d086b 100644
--- a/src/java/org/apache/cassandra/db/marshal/DoubleType.java
+++ b/src/java/org/apache/cassandra/db/marshal/DoubleType.java
@@ -38,9 +38,8 @@ public class DoubleType extends AbstractType<Double>
     
     public ByteBuffer decompose(Double value)
     {
-        return (value==null) ? ByteBufferUtil.EMPTY_BYTE_BUFFER : ByteBufferUtil.bytes(value);
-    }
-    
+        return JdbcDouble.instance.decompose(value);
+    }    
 
     public int compare(ByteBuffer o1, ByteBuffer o2)
     {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/db/marshal/FloatType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/FloatType.java b/src/java/org/apache/cassandra/db/marshal/FloatType.java
index 9da60de..b946407 100644
--- a/src/java/org/apache/cassandra/db/marshal/FloatType.java
+++ b/src/java/org/apache/cassandra/db/marshal/FloatType.java
@@ -39,9 +39,8 @@ public class FloatType extends AbstractType<Float>
     
     public ByteBuffer decompose(Float value)
     {
-        return (value==null) ? ByteBufferUtil.EMPTY_BYTE_BUFFER : ByteBufferUtil.bytes(value);
-    }
-    
+        return JdbcFloat.instance.decompose(value);
+    }    
 
     public int compare(ByteBuffer o1, ByteBuffer o2)
     {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/db/marshal/Int32Type.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/Int32Type.java b/src/java/org/apache/cassandra/db/marshal/Int32Type.java
index 22ec9e4..c377496 100644
--- a/src/java/org/apache/cassandra/db/marshal/Int32Type.java
+++ b/src/java/org/apache/cassandra/db/marshal/Int32Type.java
@@ -34,12 +34,12 @@ public class Int32Type extends AbstractType<Integer>
 
     public Integer compose(ByteBuffer bytes)
     {
-        return ByteBufferUtil.toInt(bytes);
+        return JdbcInt32.instance.compose(bytes);
     }
 
     public ByteBuffer decompose(Integer value)
     {
-        return ByteBufferUtil.bytes(value);
+        return JdbcInt32.instance.decompose(value);
     }
 
     public int compare(ByteBuffer o1, ByteBuffer o2)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/db/marshal/IntegerType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/IntegerType.java b/src/java/org/apache/cassandra/db/marshal/IntegerType.java
index 6d87cd1..9f303b2 100644
--- a/src/java/org/apache/cassandra/db/marshal/IntegerType.java
+++ b/src/java/org/apache/cassandra/db/marshal/IntegerType.java
@@ -64,7 +64,7 @@ public final class IntegerType extends AbstractType<BigInteger>
 
     public ByteBuffer decompose(BigInteger value)
     {
-        return ByteBuffer.wrap(value.toByteArray());
+        return JdbcInteger.instance.decompose(value);
     }
 
     public int compare(ByteBuffer lhs, ByteBuffer rhs)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java b/src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java
index decf3f9..664752c 100644
--- a/src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java
+++ b/src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java
@@ -41,7 +41,7 @@ public class LexicalUUIDType extends AbstractType<UUID>
 
     public ByteBuffer decompose(UUID value)
     {
-        return ByteBuffer.wrap(UUIDGen.decompose(value));
+        return JdbcLexicalUUID.instance.decompose(value);
     }
 
     public int compare(ByteBuffer o1, ByteBuffer o2)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/db/marshal/LongType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/LongType.java b/src/java/org/apache/cassandra/db/marshal/LongType.java
index 1cecb72..b604cac 100644
--- a/src/java/org/apache/cassandra/db/marshal/LongType.java
+++ b/src/java/org/apache/cassandra/db/marshal/LongType.java
@@ -34,12 +34,12 @@ public class LongType extends AbstractType<Long>
 
     public Long compose(ByteBuffer bytes)
     {
-        return ByteBufferUtil.toLong(bytes);
+        return JdbcLong.instance.compose(bytes);
     }
 
     public ByteBuffer decompose(Long value)
     {
-        return ByteBufferUtil.bytes(value);
+        return JdbcLong.instance.decompose(value);
     }
 
     public int compare(ByteBuffer o1, ByteBuffer o2)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java b/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java
index bf9a693..81f226c 100644
--- a/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java
+++ b/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java
@@ -49,7 +49,7 @@ public class TimeUUIDType extends AbstractType<UUID>
 
     public ByteBuffer decompose(UUID value)
     {
-        return ByteBuffer.wrap(UUIDGen.decompose(value));
+        return JdbcTimeUUID.instance.decompose(value);
     }
 
     public int compare(ByteBuffer o1, ByteBuffer o2)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/db/marshal/UTF8Type.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/UTF8Type.java b/src/java/org/apache/cassandra/db/marshal/UTF8Type.java
index 434ea19..e743e96 100644
--- a/src/java/org/apache/cassandra/db/marshal/UTF8Type.java
+++ b/src/java/org/apache/cassandra/db/marshal/UTF8Type.java
@@ -22,10 +22,7 @@ package org.apache.cassandra.db.marshal;
 
 import java.nio.ByteBuffer;
 
-import com.google.common.base.Charsets;
-
 import org.apache.cassandra.cql.jdbc.JdbcUTF8;
-import org.apache.cassandra.utils.ByteBufferUtil;
 
 public class UTF8Type extends AbstractType<String>
 {
@@ -40,7 +37,7 @@ public class UTF8Type extends AbstractType<String>
 
     public ByteBuffer decompose(String value)
     {
-        return ByteBufferUtil.bytes(value, Charsets.UTF_8);
+        return JdbcUTF8.instance.decompose(value);
     }
 
     public int compare(ByteBuffer o1, ByteBuffer o2)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b226cf93/src/java/org/apache/cassandra/db/marshal/UUIDType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/UUIDType.java b/src/java/org/apache/cassandra/db/marshal/UUIDType.java
index 77f984c..e6ab166 100644
--- a/src/java/org/apache/cassandra/db/marshal/UUIDType.java
+++ b/src/java/org/apache/cassandra/db/marshal/UUIDType.java
@@ -187,7 +187,7 @@ public class UUIDType extends AbstractType<UUID>
 
     public ByteBuffer decompose(UUID value)
     {
-        return ByteBuffer.wrap(UUIDGen.decompose(value));
+        return JdbcUUID.instance.decompose(value);
     }
 
     @Override


Mime
View raw message