cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [2/4] Don't tie client side use of AbstractType to JDBC
Date Mon, 08 Jul 2013 16:57:14 GMT
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/db/marshal/CollectionType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/CollectionType.java b/src/java/org/apache/cassandra/db/marshal/CollectionType.java
index f7cdf28..7b2bce2 100644
--- a/src/java/org/apache/cassandra/db/marshal/CollectionType.java
+++ b/src/java/org/apache/cassandra/db/marshal/CollectionType.java
@@ -22,6 +22,7 @@ import java.util.List;
 
 import org.apache.cassandra.cql3.CQL3Type;
 import org.apache.cassandra.db.Column;
+import org.apache.cassandra.type.MarshalException;
 import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.cassandra.utils.Pair;
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/db/marshal/ColumnToCollectionType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/ColumnToCollectionType.java b/src/java/org/apache/cassandra/db/marshal/ColumnToCollectionType.java
index bb5d2fa..fa9705b 100644
--- a/src/java/org/apache/cassandra/db/marshal/ColumnToCollectionType.java
+++ b/src/java/org/apache/cassandra/db/marshal/ColumnToCollectionType.java
@@ -25,6 +25,9 @@ import com.google.common.collect.ImmutableMap;
 
 import org.apache.cassandra.exceptions.ConfigurationException;
 import org.apache.cassandra.exceptions.SyntaxException;
+import org.apache.cassandra.type.AbstractSerializer;
+import org.apache.cassandra.type.BytesSerializer;
+import org.apache.cassandra.type.MarshalException;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 public class ColumnToCollectionType extends AbstractType<ByteBuffer>
@@ -103,6 +106,11 @@ public class ColumnToCollectionType extends AbstractType<ByteBuffer>
         throw new UnsupportedOperationException("ColumnToCollectionType should only be used in composite types, never alone");
     }
 
+    public AbstractSerializer<ByteBuffer> asComposer()
+    {
+        return BytesSerializer.instance;
+    }
+
     public void validateCollectionMember(ByteBuffer bytes, ByteBuffer collectionName) throws MarshalException
     {
         CollectionType t = defined.get(collectionName);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/db/marshal/CompositeType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/CompositeType.java b/src/java/org/apache/cassandra/db/marshal/CompositeType.java
index 7679907..6a25d14 100644
--- a/src/java/org/apache/cassandra/db/marshal/CompositeType.java
+++ b/src/java/org/apache/cassandra/db/marshal/CompositeType.java
@@ -34,6 +34,7 @@ import org.apache.cassandra.exceptions.SyntaxException;
 import org.apache.cassandra.cql3.ColumnNameBuilder;
 import org.apache.cassandra.cql3.Relation;
 import org.apache.cassandra.io.util.DataOutputBuffer;
+import org.apache.cassandra.type.MarshalException;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 /*

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/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 9ee772c..4a84ece 100644
--- a/src/java/org/apache/cassandra/db/marshal/CounterColumnType.java
+++ b/src/java/org/apache/cassandra/db/marshal/CounterColumnType.java
@@ -21,6 +21,9 @@ import java.nio.ByteBuffer;
 
 import org.apache.cassandra.cql3.CQL3Type;
 import org.apache.cassandra.db.*;
+import org.apache.cassandra.type.AbstractSerializer;
+import org.apache.cassandra.type.CounterSerializer;
+import org.apache.cassandra.type.MarshalException;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 public class CounterColumnType extends AbstractCommutativeType
@@ -65,4 +68,9 @@ public class CounterColumnType extends AbstractCommutativeType
     {
         return CQL3Type.Native.COUNTER;
     }
+
+    public AbstractSerializer<Long> asComposer()
+    {
+        return CounterSerializer.instance;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/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 875169d..dcd8c9f 100644
--- a/src/java/org/apache/cassandra/db/marshal/DateType.java
+++ b/src/java/org/apache/cassandra/db/marshal/DateType.java
@@ -17,15 +17,17 @@
  */
 package org.apache.cassandra.db.marshal;
 
-import static org.apache.cassandra.cql.jdbc.JdbcDate.iso8601Patterns;
+import static org.apache.cassandra.type.DateSerializer.iso8601Patterns;
 
 import java.nio.ByteBuffer;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
-import org.apache.cassandra.cql.jdbc.JdbcDate;
 import org.apache.cassandra.cql3.CQL3Type;
+import org.apache.cassandra.type.AbstractSerializer;
+import org.apache.cassandra.type.DateSerializer;
+import org.apache.cassandra.type.MarshalException;
 import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.commons.lang.time.DateUtils;
 
@@ -40,12 +42,12 @@ public class DateType extends AbstractType<Date>
 
     public Date compose(ByteBuffer bytes)
     {
-        return JdbcDate.instance.compose(bytes);
+        return DateSerializer.instance.serialize(bytes);
     }
 
     public ByteBuffer decompose(Date value)
     {
-        return JdbcDate.instance.decompose(value);
+        return DateSerializer.instance.deserialize(value);
     }
 
     public int compare(ByteBuffer o1, ByteBuffer o2)
@@ -64,14 +66,7 @@ public class DateType extends AbstractType<Date>
 
     public String getString(ByteBuffer bytes)
     {
-        try
-        {
-            return JdbcDate.instance.getString(bytes);
-        }
-        catch (org.apache.cassandra.cql.jdbc.MarshalException e)
-        {
-            throw new MarshalException(e.getMessage());
-        }
+        return DateSerializer.instance.getString(bytes);
     }
 
     public ByteBuffer fromString(String source) throws MarshalException
@@ -121,12 +116,16 @@ public class DateType extends AbstractType<Date>
 
     public void validate(ByteBuffer bytes) throws MarshalException
     {
-        if (bytes.remaining() != 8 && bytes.remaining() != 0)
-            throw new MarshalException(String.format("Expected 8 or 0 byte long for date (%d)", bytes.remaining()));
+        DateSerializer.instance.validate(bytes);
     }
 
     public CQL3Type asCQL3Type()
     {
         return CQL3Type.Native.TIMESTAMP;
     }
+
+    public AbstractSerializer<Date> asComposer()
+    {
+        return DateSerializer.instance;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/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 825f208..e213703 100644
--- a/src/java/org/apache/cassandra/db/marshal/DecimalType.java
+++ b/src/java/org/apache/cassandra/db/marshal/DecimalType.java
@@ -20,8 +20,10 @@ package org.apache.cassandra.db.marshal;
 import java.math.BigDecimal;
 import java.nio.ByteBuffer;
 
-import org.apache.cassandra.cql.jdbc.JdbcDecimal;
 import org.apache.cassandra.cql3.CQL3Type;
+import org.apache.cassandra.type.AbstractSerializer;
+import org.apache.cassandra.type.DecimalSerializer;
+import org.apache.cassandra.type.MarshalException;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 public class DecimalType extends AbstractType<BigDecimal>
@@ -46,7 +48,7 @@ public class DecimalType extends AbstractType<BigDecimal>
 
     public BigDecimal compose(ByteBuffer bytes)
     {
-        return JdbcDecimal.instance.compose(bytes);
+        return DecimalSerializer.instance.serialize(bytes);
     }
 
     /**
@@ -55,12 +57,12 @@ public class DecimalType extends AbstractType<BigDecimal>
      */
     public ByteBuffer decompose(BigDecimal value)
     {
-        return JdbcDecimal.instance.decompose(value);
+        return DecimalSerializer.instance.deserialize(value);
     }
 
     public String getString(ByteBuffer bytes)
     {
-        return JdbcDecimal.instance.getString(bytes);
+        return DecimalSerializer.instance.getString(bytes);
     }
 
     public ByteBuffer fromString(String source) throws MarshalException
@@ -84,11 +86,17 @@ public class DecimalType extends AbstractType<BigDecimal>
 
     public void validate(ByteBuffer bytes) throws MarshalException
     {
-        // no useful check for invalid decimals.
+        DecimalSerializer.instance.validate(bytes);
     }
 
     public CQL3Type asCQL3Type()
     {
         return CQL3Type.Native.DECIMAL;
     }
+
+    @Override
+    public AbstractSerializer<BigDecimal> asComposer()
+    {
+        return DecimalSerializer.instance;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/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 f2c7378..89f11af 100644
--- a/src/java/org/apache/cassandra/db/marshal/DoubleType.java
+++ b/src/java/org/apache/cassandra/db/marshal/DoubleType.java
@@ -19,8 +19,10 @@ package org.apache.cassandra.db.marshal;
 
 import java.nio.ByteBuffer;
 
-import org.apache.cassandra.cql.jdbc.JdbcDouble;
 import org.apache.cassandra.cql3.CQL3Type;
+import org.apache.cassandra.type.AbstractSerializer;
+import org.apache.cassandra.type.DoubleSerializer;
+import org.apache.cassandra.type.MarshalException;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 public class DoubleType extends AbstractType<Double>
@@ -31,12 +33,12 @@ public class DoubleType extends AbstractType<Double>
 
     public Double compose(ByteBuffer bytes)
     {
-        return JdbcDouble.instance.compose(bytes);
+        return DoubleSerializer.instance.serialize(bytes);
     }
 
     public ByteBuffer decompose(Double value)
     {
-        return JdbcDouble.instance.decompose(value);
+        return DoubleSerializer.instance.deserialize(value);
     }
 
     public int compare(ByteBuffer o1, ByteBuffer o2)
@@ -55,14 +57,7 @@ public class DoubleType extends AbstractType<Double>
 
     public String getString(ByteBuffer bytes)
     {
-        try
-        {
-            return JdbcDouble.instance.getString(bytes);
-        }
-        catch (org.apache.cassandra.cql.jdbc.MarshalException e)
-        {
-            throw new MarshalException(e.getMessage());
-        }
+        return DoubleSerializer.instance.getString(bytes);
     }
 
     public ByteBuffer fromString(String source) throws MarshalException
@@ -86,12 +81,17 @@ public class DoubleType extends AbstractType<Double>
 
     public void validate(ByteBuffer bytes) throws MarshalException
     {
-        if (bytes.remaining() != 8 && bytes.remaining() != 0)
-            throw new MarshalException(String.format("Expected 8 or 0 byte value for a double (%d)", bytes.remaining()));
+        DoubleSerializer.instance.validate(bytes);
     }
 
     public CQL3Type asCQL3Type()
     {
         return CQL3Type.Native.DOUBLE;
     }
+
+    @Override
+    public AbstractSerializer<Double> asComposer()
+    {
+        return DoubleSerializer.instance;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/db/marshal/DynamicCompositeType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/DynamicCompositeType.java b/src/java/org/apache/cassandra/db/marshal/DynamicCompositeType.java
index 027f9c4..b00a026 100644
--- a/src/java/org/apache/cassandra/db/marshal/DynamicCompositeType.java
+++ b/src/java/org/apache/cassandra/db/marshal/DynamicCompositeType.java
@@ -24,6 +24,8 @@ import java.util.Map;
 
 import org.apache.cassandra.exceptions.ConfigurationException;
 import org.apache.cassandra.exceptions.SyntaxException;
+import org.apache.cassandra.type.AbstractSerializer;
+import org.apache.cassandra.type.MarshalException;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 /*
@@ -358,5 +360,11 @@ public class DynamicCompositeType extends AbstractCompositeType
         {
             throw new UnsupportedOperationException();
         }
+
+        @Override
+        public AbstractSerializer<Void> asComposer()
+        {
+            throw new UnsupportedOperationException();
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/db/marshal/EmptyType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/EmptyType.java b/src/java/org/apache/cassandra/db/marshal/EmptyType.java
index 6bbd006..0ad704f 100644
--- a/src/java/org/apache/cassandra/db/marshal/EmptyType.java
+++ b/src/java/org/apache/cassandra/db/marshal/EmptyType.java
@@ -19,6 +19,9 @@ package org.apache.cassandra.db.marshal;
 
 import java.nio.ByteBuffer;
 
+import org.apache.cassandra.type.AbstractSerializer;
+import org.apache.cassandra.type.EmptySerializer;
+import org.apache.cassandra.type.MarshalException;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 /**
@@ -61,7 +64,11 @@ public class EmptyType extends AbstractType<Void>
 
     public void validate(ByteBuffer bytes) throws MarshalException
     {
-        if (bytes.remaining() > 0)
-            throw new MarshalException("EmptyType only accept empty values");
+        EmptySerializer.instance.validate(bytes);
+    }
+
+    public AbstractSerializer<Void> asComposer()
+    {
+        return EmptySerializer.instance;
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/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 cb3cc3b..c0940f4 100644
--- a/src/java/org/apache/cassandra/db/marshal/FloatType.java
+++ b/src/java/org/apache/cassandra/db/marshal/FloatType.java
@@ -19,8 +19,10 @@ package org.apache.cassandra.db.marshal;
 
 import java.nio.ByteBuffer;
 
-import org.apache.cassandra.cql.jdbc.JdbcFloat;
 import org.apache.cassandra.cql3.CQL3Type;
+import org.apache.cassandra.type.AbstractSerializer;
+import org.apache.cassandra.type.FloatSerializer;
+import org.apache.cassandra.type.MarshalException;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 
@@ -32,12 +34,12 @@ public class FloatType extends AbstractType<Float>
 
     public Float compose(ByteBuffer bytes)
     {
-        return JdbcFloat.instance.compose(bytes);
+        return FloatSerializer.instance.serialize(bytes);
     }
 
     public ByteBuffer decompose(Float value)
     {
-        return JdbcFloat.instance.decompose(value);
+        return FloatSerializer.instance.deserialize(value);
     }
 
     public int compare(ByteBuffer o1, ByteBuffer o2)
@@ -56,14 +58,7 @@ public class FloatType extends AbstractType<Float>
 
     public String getString(ByteBuffer bytes)
     {
-        try
-        {
-            return JdbcFloat.instance.getString(bytes);
-        }
-        catch (org.apache.cassandra.cql.jdbc.MarshalException e)
-        {
-            throw new MarshalException(e.getMessage());
-        }
+        return FloatSerializer.instance.getString(bytes);
     }
 
     public ByteBuffer fromString(String source) throws MarshalException
@@ -85,12 +80,17 @@ public class FloatType extends AbstractType<Float>
 
     public void validate(ByteBuffer bytes) throws MarshalException
     {
-        if (bytes.remaining() != 4 && bytes.remaining() != 0)
-            throw new MarshalException(String.format("Expected 4 or 0 byte value for a float (%d)", bytes.remaining()));
+        FloatSerializer.instance.validate(bytes);
     }
 
     public CQL3Type asCQL3Type()
     {
         return CQL3Type.Native.FLOAT;
     }
+
+    @Override
+    public AbstractSerializer<Float> asComposer()
+    {
+        return FloatSerializer.instance;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/db/marshal/InetAddressType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/InetAddressType.java b/src/java/org/apache/cassandra/db/marshal/InetAddressType.java
index f060354..a86f578 100644
--- a/src/java/org/apache/cassandra/db/marshal/InetAddressType.java
+++ b/src/java/org/apache/cassandra/db/marshal/InetAddressType.java
@@ -18,11 +18,12 @@
 package org.apache.cassandra.db.marshal;
 
 import java.net.InetAddress;
-import java.net.UnknownHostException;
 import java.nio.ByteBuffer;
 
-import org.apache.cassandra.cql.jdbc.JdbcInetAddress;
 import org.apache.cassandra.cql3.CQL3Type;
+import org.apache.cassandra.type.AbstractSerializer;
+import org.apache.cassandra.type.InetAddressSerializer;
+import org.apache.cassandra.type.MarshalException;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 public class InetAddressType extends AbstractType<InetAddress>
@@ -33,12 +34,12 @@ public class InetAddressType extends AbstractType<InetAddress>
 
     public InetAddress compose(ByteBuffer bytes)
     {
-        return JdbcInetAddress.instance.compose(bytes);
+        return InetAddressSerializer.instance.serialize(bytes);
     }
 
     public ByteBuffer decompose(InetAddress value)
     {
-        return JdbcInetAddress.instance.decompose(value);
+        return InetAddressSerializer.instance.deserialize(value);
     }
 
     public int compare(ByteBuffer o1, ByteBuffer o2)
@@ -48,7 +49,7 @@ public class InetAddressType extends AbstractType<InetAddress>
 
     public String getString(ByteBuffer bytes)
     {
-        return JdbcInetAddress.instance.getString(bytes);
+        return InetAddressSerializer.instance.getString(bytes);
     }
 
     public ByteBuffer fromString(String source) throws MarshalException
@@ -73,18 +74,17 @@ public class InetAddressType extends AbstractType<InetAddress>
 
     public void validate(ByteBuffer bytes) throws MarshalException
     {
-        try
-        {
-            InetAddress.getByAddress(ByteBufferUtil.getArray(bytes));
-        }
-        catch (UnknownHostException e)
-        {
-            throw new MarshalException(String.format("Expected 4 or 16 byte inetaddress; got %s", ByteBufferUtil.bytesToHex(bytes)));
-        }
+        InetAddressSerializer.instance.validate(bytes);
     }
 
     public CQL3Type asCQL3Type()
     {
         return CQL3Type.Native.INET;
     }
+
+    @Override
+    public AbstractSerializer<InetAddress> asComposer()
+    {
+        return InetAddressSerializer.instance;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/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 1e206ff..0ec7240 100644
--- a/src/java/org/apache/cassandra/db/marshal/Int32Type.java
+++ b/src/java/org/apache/cassandra/db/marshal/Int32Type.java
@@ -19,24 +19,28 @@ package org.apache.cassandra.db.marshal;
 
 import java.nio.ByteBuffer;
 
-import org.apache.cassandra.cql.jdbc.JdbcInt32;
 import org.apache.cassandra.cql3.CQL3Type;
+import org.apache.cassandra.type.AbstractSerializer;
+import org.apache.cassandra.type.Int32Serializer;
+import org.apache.cassandra.type.MarshalException;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 public class Int32Type extends AbstractType<Integer>
 {
     public static final Int32Type instance = new Int32Type();
 
-    Int32Type() {} // singleton
+    Int32Type()
+    {
+    } // singleton
 
     public Integer compose(ByteBuffer bytes)
     {
-        return JdbcInt32.instance.compose(bytes);
+        return Int32Serializer.instance.serialize(bytes);
     }
 
     public ByteBuffer decompose(Integer value)
     {
-        return JdbcInt32.instance.decompose(value);
+        return Int32Serializer.instance.deserialize(value);
     }
 
     public int compare(ByteBuffer o1, ByteBuffer o2)
@@ -60,14 +64,7 @@ public class Int32Type extends AbstractType<Integer>
 
     public String getString(ByteBuffer bytes)
     {
-        try
-        {
-            return JdbcInt32.instance.getString(bytes);
-        }
-        catch (org.apache.cassandra.cql.jdbc.MarshalException e)
-        {
-            throw new MarshalException(e.getMessage());
-        }
+        return Int32Serializer.instance.getString(bytes);
     }
 
     public ByteBuffer fromString(String source) throws MarshalException
@@ -92,12 +89,17 @@ public class Int32Type extends AbstractType<Integer>
 
     public void validate(ByteBuffer bytes) throws MarshalException
     {
-        if (bytes.remaining() != 4 && bytes.remaining() != 0)
-            throw new MarshalException(String.format("Expected 4 or 0 byte int (%d)", bytes.remaining()));
+        Int32Serializer.instance.validate(bytes);
     }
 
     public CQL3Type asCQL3Type()
     {
         return CQL3Type.Native.INT;
     }
+
+    @Override
+    public AbstractSerializer<Integer> asComposer()
+    {
+        return Int32Serializer.instance;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/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 de675f6..7fed5f6 100644
--- a/src/java/org/apache/cassandra/db/marshal/IntegerType.java
+++ b/src/java/org/apache/cassandra/db/marshal/IntegerType.java
@@ -20,8 +20,10 @@ package org.apache.cassandra.db.marshal;
 import java.math.BigInteger;
 import java.nio.ByteBuffer;
 
-import org.apache.cassandra.cql.jdbc.JdbcInteger;
 import org.apache.cassandra.cql3.CQL3Type;
+import org.apache.cassandra.type.AbstractSerializer;
+import org.apache.cassandra.type.IntegerSerializer;
+import org.apache.cassandra.type.MarshalException;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 public final class IntegerType extends AbstractType<BigInteger>
@@ -58,12 +60,12 @@ public final class IntegerType extends AbstractType<BigInteger>
 
     public BigInteger compose(ByteBuffer bytes)
     {
-        return JdbcInteger.instance.compose(bytes);
+        return IntegerSerializer.instance.serialize(bytes);
     }
 
     public ByteBuffer decompose(BigInteger value)
     {
-        return JdbcInteger.instance.decompose(value);
+        return IntegerSerializer.instance.deserialize(value);
     }
 
     public int compare(ByteBuffer lhs, ByteBuffer rhs)
@@ -126,7 +128,7 @@ public final class IntegerType extends AbstractType<BigInteger>
 
     public String getString(ByteBuffer bytes)
     {
-        return JdbcInteger.instance.getString(bytes);
+        return IntegerSerializer.instance.getString(bytes);
     }
 
     public ByteBuffer fromString(String source) throws MarshalException
@@ -151,11 +153,17 @@ public final class IntegerType extends AbstractType<BigInteger>
 
     public void validate(ByteBuffer bytes) throws MarshalException
     {
-        // no invalid integers.
+        IntegerSerializer.instance.validate(bytes);
     }
 
     public CQL3Type asCQL3Type()
     {
         return CQL3Type.Native.VARINT;
     }
+
+    @Override
+    public AbstractSerializer<BigInteger> asComposer()
+    {
+        return IntegerSerializer.instance;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/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 c1f2049..dacd81b 100644
--- a/src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java
+++ b/src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java
@@ -20,7 +20,9 @@ package org.apache.cassandra.db.marshal;
 import java.nio.ByteBuffer;
 import java.util.UUID;
 
-import org.apache.cassandra.cql.jdbc.JdbcLexicalUUID;
+import org.apache.cassandra.type.AbstractSerializer;
+import org.apache.cassandra.type.MarshalException;
+import org.apache.cassandra.type.UUIDSerializer;
 import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.cassandra.utils.UUIDGen;
 
@@ -28,16 +30,18 @@ public class LexicalUUIDType extends AbstractType<UUID>
 {
     public static final LexicalUUIDType instance = new LexicalUUIDType();
 
-    LexicalUUIDType() {} // singleton
+    LexicalUUIDType()
+    {
+    } // singleton
 
     public UUID compose(ByteBuffer bytes)
     {
-        return JdbcLexicalUUID.instance.compose(bytes);
+        return UUIDSerializer.instance.serialize(bytes);
     }
 
     public ByteBuffer decompose(UUID value)
     {
-        return JdbcLexicalUUID.instance.decompose(value);
+        return UUIDSerializer.instance.deserialize(value);
     }
 
     public int compare(ByteBuffer o1, ByteBuffer o2)
@@ -56,14 +60,7 @@ public class LexicalUUIDType extends AbstractType<UUID>
 
     public String getString(ByteBuffer bytes)
     {
-        try
-        {
-            return JdbcLexicalUUID.instance.getString(bytes);
-        }
-        catch (org.apache.cassandra.cql.jdbc.MarshalException e)
-        {
-            throw new MarshalException(e.getMessage());
-        }
+        return UUIDSerializer.instance.getString(bytes);
     }
 
     public ByteBuffer fromString(String source) throws MarshalException
@@ -84,8 +81,12 @@ public class LexicalUUIDType extends AbstractType<UUID>
 
     public void validate(ByteBuffer bytes) throws MarshalException
     {
-        if (bytes.remaining() != 16 && bytes.remaining() != 0)
-            throw new MarshalException(String.format("LexicalUUID should be 16 or 0 bytes (%d)", bytes.remaining()));
-        // not sure what the version should be for this.
+        UUIDSerializer.instance.validate(bytes);
+    }
+
+    @Override
+    public AbstractSerializer<UUID> asComposer()
+    {
+        return UUIDSerializer.instance;
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/db/marshal/ListType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/ListType.java b/src/java/org/apache/cassandra/db/marshal/ListType.java
index 32eb13a..49e7319 100644
--- a/src/java/org/apache/cassandra/db/marshal/ListType.java
+++ b/src/java/org/apache/cassandra/db/marshal/ListType.java
@@ -17,13 +17,14 @@
  */
 package org.apache.cassandra.db.marshal;
 
-import java.nio.BufferUnderflowException;
 import java.nio.ByteBuffer;
 import java.util.*;
 
 import org.apache.cassandra.db.Column;
 import org.apache.cassandra.exceptions.ConfigurationException;
 import org.apache.cassandra.exceptions.SyntaxException;
+import org.apache.cassandra.type.AbstractSerializer;
+import org.apache.cassandra.type.ListSerializer;
 import org.apache.cassandra.utils.Pair;
 
 public class ListType<T> extends CollectionType<List<T>>
@@ -32,6 +33,7 @@ public class ListType<T> extends CollectionType<List<T>>
     private static final Map<AbstractType<?>, ListType> instances = new HashMap<AbstractType<?>, ListType>();
 
     public final AbstractType<T> elements;
+    public final ListSerializer<T> composer;
 
     public static ListType<?> getInstance(TypeParser parser) throws ConfigurationException, SyntaxException
     {
@@ -57,6 +59,7 @@ public class ListType<T> extends CollectionType<List<T>>
     {
         super(Kind.LIST);
         this.elements = elements;
+        this.composer = ListSerializer.getInstance(elements.asComposer());
     }
 
     public AbstractType<UUID> nameComparator()
@@ -71,26 +74,7 @@ public class ListType<T> extends CollectionType<List<T>>
 
     public List<T> compose(ByteBuffer bytes)
     {
-        try
-        {
-            ByteBuffer input = bytes.duplicate();
-            int n = getUnsignedShort(input);
-            List<T> l = new ArrayList<T>(n);
-            for (int i = 0; i < n; i++)
-            {
-                int s = getUnsignedShort(input);
-                byte[] data = new byte[s];
-                input.get(data);
-                ByteBuffer databb = ByteBuffer.wrap(data);
-                elements.validate(databb);
-                l.add(elements.compose(databb));
-            }
-            return l;
-        }
-        catch (BufferUnderflowException e)
-        {
-            throw new MarshalException("Not enough bytes to read a list");
-        }
+        return composer.serialize(bytes);
     }
 
     /**
@@ -102,15 +86,12 @@ public class ListType<T> extends CollectionType<List<T>>
      */
     public ByteBuffer decompose(List<T> value)
     {
-        List<ByteBuffer> bbs = new ArrayList<ByteBuffer>(value.size());
-        int size = 0;
-        for (T elt : value)
-        {
-            ByteBuffer bb = elements.decompose(elt);
-            bbs.add(bb);
-            size += 2 + bb.remaining();
-        }
-        return pack(bbs, value.size(), size);
+        return composer.deserialize(value);
+    }
+
+    public AbstractSerializer<List<T>> asComposer()
+    {
+        return composer;
     }
 
     protected void appendToStringBuilder(StringBuilder sb)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/db/marshal/LocalByPartionerType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/LocalByPartionerType.java b/src/java/org/apache/cassandra/db/marshal/LocalByPartionerType.java
index 68b4715..62b5d9f 100644
--- a/src/java/org/apache/cassandra/db/marshal/LocalByPartionerType.java
+++ b/src/java/org/apache/cassandra/db/marshal/LocalByPartionerType.java
@@ -19,6 +19,8 @@ package org.apache.cassandra.db.marshal;
 
 import java.nio.ByteBuffer;
 
+import org.apache.cassandra.type.AbstractSerializer;
+import org.apache.cassandra.type.MarshalException;
 import org.apache.commons.lang.NotImplementedException;
 
 import org.apache.cassandra.db.RowPosition;
@@ -67,4 +69,9 @@ public class LocalByPartionerType<T extends Token> extends AbstractType<ByteBuff
     {
         throw new IllegalStateException("You shouldn't be validating this.");
     }
+
+    public AbstractSerializer<ByteBuffer> asComposer()
+    {
+        throw new UnsupportedOperationException("You can't do this with a local partitioner.");
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/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 71ad36f..45edc2f 100644
--- a/src/java/org/apache/cassandra/db/marshal/LongType.java
+++ b/src/java/org/apache/cassandra/db/marshal/LongType.java
@@ -19,8 +19,10 @@ package org.apache.cassandra.db.marshal;
 
 import java.nio.ByteBuffer;
 
-import org.apache.cassandra.cql.jdbc.JdbcLong;
 import org.apache.cassandra.cql3.CQL3Type;
+import org.apache.cassandra.type.AbstractSerializer;
+import org.apache.cassandra.type.LongSerializer;
+import org.apache.cassandra.type.MarshalException;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 public class LongType extends AbstractType<Long>
@@ -31,12 +33,12 @@ public class LongType extends AbstractType<Long>
 
     public Long compose(ByteBuffer bytes)
     {
-        return JdbcLong.instance.compose(bytes);
+        return LongSerializer.instance.serialize(bytes);
     }
 
     public ByteBuffer decompose(Long value)
     {
-        return JdbcLong.instance.decompose(value);
+        return LongSerializer.instance.deserialize(value);
     }
 
     public int compare(ByteBuffer o1, ByteBuffer o2)
@@ -60,14 +62,7 @@ public class LongType extends AbstractType<Long>
 
     public String getString(ByteBuffer bytes)
     {
-        try
-        {
-            return JdbcLong.instance.getString(bytes);
-        }
-        catch (org.apache.cassandra.cql.jdbc.MarshalException e)
-        {
-            throw new MarshalException(e.getMessage());
-        }
+        return LongSerializer.instance.getString(bytes);
     }
 
     public ByteBuffer fromString(String source) throws MarshalException
@@ -92,12 +87,17 @@ public class LongType extends AbstractType<Long>
 
     public void validate(ByteBuffer bytes) throws MarshalException
     {
-        if (bytes.remaining() != 8 && bytes.remaining() != 0)
-            throw new MarshalException(String.format("Expected 8 or 0 byte long (%d)", bytes.remaining()));
+
     }
 
     public CQL3Type asCQL3Type()
     {
         return CQL3Type.Native.BIGINT;
     }
+
+    @Override
+    public AbstractSerializer<Long> asComposer()
+    {
+        return LongSerializer.instance;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/db/marshal/MapType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/MapType.java b/src/java/org/apache/cassandra/db/marshal/MapType.java
index c7772d7..fc51189 100644
--- a/src/java/org/apache/cassandra/db/marshal/MapType.java
+++ b/src/java/org/apache/cassandra/db/marshal/MapType.java
@@ -24,6 +24,9 @@ import java.util.*;
 import org.apache.cassandra.db.Column;
 import org.apache.cassandra.exceptions.ConfigurationException;
 import org.apache.cassandra.exceptions.SyntaxException;
+import org.apache.cassandra.type.AbstractSerializer;
+import org.apache.cassandra.type.MapSerializer;
+import org.apache.cassandra.type.MarshalException;
 import org.apache.cassandra.utils.Pair;
 
 public class MapType<K, V> extends CollectionType<Map<K, V>>
@@ -33,6 +36,7 @@ public class MapType<K, V> extends CollectionType<Map<K, V>>
 
     public final AbstractType<K> keys;
     public final AbstractType<V> values;
+    private final MapSerializer<K, V> composer;
 
     public static MapType<?, ?> getInstance(TypeParser parser) throws ConfigurationException, SyntaxException
     {
@@ -60,6 +64,7 @@ public class MapType<K, V> extends CollectionType<Map<K, V>>
         super(Kind.MAP);
         this.keys = keys;
         this.values = values;
+        this.composer = MapSerializer.getInstance(keys.asComposer(), values.asComposer());
     }
 
     public AbstractType<K> nameComparator()
@@ -127,13 +132,19 @@ public class MapType<K, V> extends CollectionType<Map<K, V>>
         return pack(bbs, value.size(), size);
     }
 
+    @Override
+    public AbstractSerializer<Map<K, V>> asComposer()
+    {
+        return composer;
+    }
+
     protected void appendToStringBuilder(StringBuilder sb)
     {
         sb.append(getClass().getName()).append(TypeParser.stringifyTypeParameters(Arrays.asList(keys, values)));
     }
 
     /**
-     * Creates the same output than decompose, but from the internal representation.
+     * Creates the same output than deserialize, but from the internal representation.
      */
     public ByteBuffer serialize(List<Pair<ByteBuffer, Column>> columns)
     {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/db/marshal/MarshalException.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/MarshalException.java b/src/java/org/apache/cassandra/db/marshal/MarshalException.java
deleted file mode 100644
index f512b0c..0000000
--- a/src/java/org/apache/cassandra/db/marshal/MarshalException.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.cassandra.db.marshal;
-
-public class MarshalException extends RuntimeException
-{
-    public MarshalException(String message)
-    {
-        super(message);
-    }
-
-    public MarshalException(String message, Throwable cause)
-    {
-        super(message, cause);
-    }
-}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/db/marshal/ReversedType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/ReversedType.java b/src/java/org/apache/cassandra/db/marshal/ReversedType.java
index 9fdecb8..d7816a7 100644
--- a/src/java/org/apache/cassandra/db/marshal/ReversedType.java
+++ b/src/java/org/apache/cassandra/db/marshal/ReversedType.java
@@ -25,6 +25,8 @@ import java.util.List;
 import org.apache.cassandra.cql3.CQL3Type;
 import org.apache.cassandra.exceptions.ConfigurationException;
 import org.apache.cassandra.exceptions.SyntaxException;
+import org.apache.cassandra.type.AbstractSerializer;
+import org.apache.cassandra.type.MarshalException;
 
 public class ReversedType<T> extends AbstractType<T>
 {
@@ -104,6 +106,12 @@ public class ReversedType<T> extends AbstractType<T>
     }
 
     @Override
+    public AbstractSerializer<T> asComposer()
+    {
+        return baseType.asComposer();
+    }
+
+    @Override
     public String toString()
     {
         return getClass().getName() + "(" + baseType + ")";

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/db/marshal/SetType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/SetType.java b/src/java/org/apache/cassandra/db/marshal/SetType.java
index dd90273..89ddc7d 100644
--- a/src/java/org/apache/cassandra/db/marshal/SetType.java
+++ b/src/java/org/apache/cassandra/db/marshal/SetType.java
@@ -17,13 +17,14 @@
  */
 package org.apache.cassandra.db.marshal;
 
-import java.nio.BufferUnderflowException;
 import java.nio.ByteBuffer;
 import java.util.*;
 
 import org.apache.cassandra.db.Column;
 import org.apache.cassandra.exceptions.ConfigurationException;
 import org.apache.cassandra.exceptions.SyntaxException;
+import org.apache.cassandra.type.AbstractSerializer;
+import org.apache.cassandra.type.SetSerializer;
 import org.apache.cassandra.utils.Pair;
 
 public class SetType<T> extends CollectionType<Set<T>>
@@ -32,6 +33,7 @@ public class SetType<T> extends CollectionType<Set<T>>
     private static final Map<AbstractType<?>, SetType> instances = new HashMap<AbstractType<?>, SetType>();
 
     public final AbstractType<T> elements;
+    private final SetSerializer<T> composer;
 
     public static SetType<?> getInstance(TypeParser parser) throws ConfigurationException, SyntaxException
     {
@@ -57,6 +59,7 @@ public class SetType<T> extends CollectionType<Set<T>>
     {
         super(Kind.SET);
         this.elements = elements;
+        this.composer = SetSerializer.getInstance(elements.asComposer());
     }
 
     public AbstractType<T> nameComparator()
@@ -71,46 +74,17 @@ public class SetType<T> extends CollectionType<Set<T>>
 
     public Set<T> compose(ByteBuffer bytes)
     {
-        try
-        {
-            ByteBuffer input = bytes.duplicate();
-            int n = getUnsignedShort(input);
-            Set<T> l = new LinkedHashSet<T>(n);
-            for (int i = 0; i < n; i++)
-            {
-                int s = getUnsignedShort(input);
-                byte[] data = new byte[s];
-                input.get(data);
-                ByteBuffer databb = ByteBuffer.wrap(data);
-                elements.validate(databb);
-                l.add(elements.compose(databb));
-            }
-            return l;
-        }
-        catch (BufferUnderflowException e)
-        {
-            throw new MarshalException("Not enough bytes to read a set");
-        }
+        return composer.serialize(bytes);
     }
 
-    /**
-     * Layout is: {@code <n><s_1><b_1>...<s_n><b_n> }
-     * where:
-     *   n is the number of elements
-     *   s_i is the number of bytes composing the ith element
-     *   b_i is the s_i bytes composing the ith element
-     */
     public ByteBuffer decompose(Set<T> value)
     {
-        List<ByteBuffer> bbs = new ArrayList<ByteBuffer>(value.size());
-        int size = 0;
-        for (T elt : value)
-        {
-            ByteBuffer bb = elements.decompose(elt);
-            bbs.add(bb);
-            size += 2 + bb.remaining();
-        }
-        return pack(bbs, value.size(), size);
+        return composer.deserialize(value);
+    }
+
+    public AbstractSerializer<Set<T>> asComposer()
+    {
+        return composer;
     }
 
     protected void appendToStringBuilder(StringBuilder sb)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/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 a28f6a5..61b02a5 100644
--- a/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java
+++ b/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java
@@ -21,8 +21,10 @@ import java.nio.ByteBuffer;
 import java.util.UUID;
 import java.util.regex.Pattern;
 
-import org.apache.cassandra.cql.jdbc.JdbcTimeUUID;
 import org.apache.cassandra.cql3.CQL3Type;
+import org.apache.cassandra.type.AbstractSerializer;
+import org.apache.cassandra.type.MarshalException;
+import org.apache.cassandra.type.TimeUUIDSerializer;
 import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.cassandra.utils.UUIDGen;
 
@@ -32,16 +34,18 @@ public class TimeUUIDType extends AbstractType<UUID>
 
     static final Pattern regexPattern = Pattern.compile("[A-Fa-f0-9]{8}\\-[A-Fa-f0-9]{4}\\-[A-Fa-f0-9]{4}\\-[A-Fa-f0-9]{4}\\-[A-Fa-f0-9]{12}");
 
-    TimeUUIDType() {} // singleton
+    TimeUUIDType()
+    {
+    } // singleton
 
     public UUID compose(ByteBuffer bytes)
     {
-        return JdbcTimeUUID.instance.compose(bytes);
+        return TimeUUIDSerializer.instance.serialize(bytes);
     }
 
     public ByteBuffer decompose(UUID value)
     {
-        return JdbcTimeUUID.instance.decompose(value);
+        return TimeUUIDSerializer.instance.deserialize(value);
     }
 
     public int compare(ByteBuffer o1, ByteBuffer o2)
@@ -65,40 +69,33 @@ public class TimeUUIDType extends AbstractType<UUID>
         int o1Pos = o1.position();
         int o2Pos = o2.position();
 
-        int d = (o1.get(o1Pos+6) & 0xF) - (o2.get(o2Pos+6) & 0xF);
+        int d = (o1.get(o1Pos + 6) & 0xF) - (o2.get(o2Pos + 6) & 0xF);
         if (d != 0) return d;
 
-        d = (o1.get(o1Pos+7) & 0xFF) - (o2.get(o2Pos+7) & 0xFF);
+        d = (o1.get(o1Pos + 7) & 0xFF) - (o2.get(o2Pos + 7) & 0xFF);
         if (d != 0) return d;
 
-        d = (o1.get(o1Pos+4) & 0xFF) - (o2.get(o2Pos+4) & 0xFF);
+        d = (o1.get(o1Pos + 4) & 0xFF) - (o2.get(o2Pos + 4) & 0xFF);
         if (d != 0) return d;
 
-        d = (o1.get(o1Pos+5) & 0xFF) - (o2.get(o2Pos+5) & 0xFF);
+        d = (o1.get(o1Pos + 5) & 0xFF) - (o2.get(o2Pos + 5) & 0xFF);
         if (d != 0) return d;
 
         d = (o1.get(o1Pos) & 0xFF) - (o2.get(o2Pos) & 0xFF);
         if (d != 0) return d;
 
-        d = (o1.get(o1Pos+1) & 0xFF) - (o2.get(o2Pos+1) & 0xFF);
+        d = (o1.get(o1Pos + 1) & 0xFF) - (o2.get(o2Pos + 1) & 0xFF);
         if (d != 0) return d;
 
-        d = (o1.get(o1Pos+2) & 0xFF) - (o2.get(o2Pos+2) & 0xFF);
+        d = (o1.get(o1Pos + 2) & 0xFF) - (o2.get(o2Pos + 2) & 0xFF);
         if (d != 0) return d;
 
-        return (o1.get(o1Pos+3) & 0xFF) - (o2.get(o2Pos+3) & 0xFF);
+        return (o1.get(o1Pos + 3) & 0xFF) - (o2.get(o2Pos + 3) & 0xFF);
     }
 
     public String getString(ByteBuffer bytes)
     {
-        try
-        {
-            return JdbcTimeUUID.instance.getString(bytes);
-        }
-        catch (org.apache.cassandra.cql.jdbc.MarshalException e)
-        {
-            throw new MarshalException(e.getMessage());
-        }
+        return TimeUUIDSerializer.instance.getString(bytes);
     }
 
     // This accepts dates are valid TimeUUID represensation, which is bogus
@@ -128,8 +125,7 @@ public class TimeUUIDType extends AbstractType<UUID>
 
             if (uuid.version() != 1)
                 throw new MarshalException("TimeUUID supports only version 1 UUIDs");
-        }
-        else
+        } else
         {
             idBytes = ByteBuffer.wrap(UUIDGen.getTimeUUIDBytes(DateType.dateStringToTimestamp(source)));
         }
@@ -161,8 +157,7 @@ public class TimeUUIDType extends AbstractType<UUID>
 
             if (uuid.version() != 1)
                 throw new MarshalException("TimeUUID supports only version 1 UUIDs");
-        }
-        else
+        } else
         {
             throw new MarshalException(String.format("Unknown timeuuid representation: %s", source));
         }
@@ -171,20 +166,18 @@ public class TimeUUIDType extends AbstractType<UUID>
 
     public void validate(ByteBuffer bytes) throws MarshalException
     {
-        if (bytes.remaining() != 16 && bytes.remaining() != 0)
-            throw new MarshalException(String.format("TimeUUID should be 16 or 0 bytes (%d)", bytes.remaining()));
-        ByteBuffer slice = bytes.slice();
-        // version is bits 4-7 of byte 6.
-        if (bytes.remaining() > 0)
-        {
-            slice.position(6);
-            if ((slice.get() & 0xf0) != 0x10)
-                throw new MarshalException("Invalid version for TimeUUID type.");
-        }
+        TimeUUIDSerializer.instance.validate(bytes);
+
     }
 
     public CQL3Type asCQL3Type()
     {
         return CQL3Type.Native.TIMEUUID;
     }
+
+    @Override
+    public AbstractSerializer<UUID> asComposer()
+    {
+        return TimeUUIDSerializer.instance;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/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 56879b1..2663195 100644
--- a/src/java/org/apache/cassandra/db/marshal/UTF8Type.java
+++ b/src/java/org/apache/cassandra/db/marshal/UTF8Type.java
@@ -19,8 +19,10 @@ package org.apache.cassandra.db.marshal;
 
 import java.nio.ByteBuffer;
 
-import org.apache.cassandra.cql.jdbc.JdbcUTF8;
 import org.apache.cassandra.cql3.CQL3Type;
+import org.apache.cassandra.type.AbstractSerializer;
+import org.apache.cassandra.type.MarshalException;
+import org.apache.cassandra.type.UTF8Serializer;
 
 public class UTF8Type extends AbstractType<String>
 {
@@ -30,12 +32,12 @@ public class UTF8Type extends AbstractType<String>
 
     public String compose(ByteBuffer bytes)
     {
-        return JdbcUTF8.instance.compose(bytes);
+        return UTF8Serializer.instance.serialize(bytes);
     }
 
     public ByteBuffer decompose(String value)
     {
-        return JdbcUTF8.instance.decompose(value);
+        return UTF8Serializer.instance.deserialize(value);
     }
 
     public int compare(ByteBuffer o1, ByteBuffer o2)
@@ -45,14 +47,7 @@ public class UTF8Type extends AbstractType<String>
 
     public String getString(ByteBuffer bytes)
     {
-        try
-        {
-            return JdbcUTF8.instance.getString(bytes);
-        }
-        catch (org.apache.cassandra.cql.jdbc.MarshalException e)
-        {
-            throw new MarshalException(e.getMessage());
-        }
+        return UTF8Serializer.instance.getString(bytes);
     }
 
     public ByteBuffer fromString(String source)
@@ -62,126 +57,7 @@ public class UTF8Type extends AbstractType<String>
 
     public void validate(ByteBuffer bytes) throws MarshalException
     {
-        if (!UTF8Validator.validate(bytes))
-            throw new MarshalException("String didn't validate.");
-    }
-
-    static class UTF8Validator
-    {
-        enum State {
-            START,
-            TWO,
-            TWO_80,
-            THREE_a0bf,
-            THREE_80bf_1,
-            THREE_80bf_2,
-            FOUR_90bf,
-            FOUR_80bf_3,
-        };
-
-        // since we're not converting to java strings, we don't need to worry about converting to surrogates.
-        // buf has already been sliced/duplicated.
-        static boolean validate(ByteBuffer buf)
-        {
-            buf = buf.slice();
-            int b = 0;
-            State state = State.START;
-            while (buf.remaining() > 0)
-            {
-                b = buf.get();
-                switch (state)
-                {
-                    case START:
-                        if (b >= 0)
-                        {
-                            // ascii, state stays start.
-                            if (b > 127)
-                                return false;
-                        }
-                        else if ((b >> 5) == -2)
-                        {
-                            // validate first byte of 2-byte char, 0xc2-0xdf
-                            if (b == (byte) 0xc0)
-                                // speical case: modified utf8 null is 0xc080.
-                                state = State.TWO_80;
-                            else if ((b & 0x1e) == 0)
-                                return false;
-                            state = State.TWO;
-                        }
-                        else if ((b >> 4) == -2)
-                        {
-                            // 3 bytes. first byte will be 0xe0 or 0xe1-0xef. handling of second byte will differ.
-                            // so 0xe0,0xa0-0xbf,0x80-0xbf or 0xe1-0xef,0x80-0xbf,0x80-0xbf.
-                            if (b == (byte)0xe0)
-                                state = State.THREE_a0bf;
-                            else
-                                state = State.THREE_80bf_2;
-                            break;
-                        }
-                        else if ((b >> 3) == -2)
-                        {
-                            // 4 bytes. this is where the fun starts.
-                            if (b == (byte)0xf0)
-                                // 0xf0, 0x90-0xbf, 0x80-0xbf, 0x80-0xbf
-                                state = State.FOUR_90bf;
-                            else if (b == (byte)0xf4)
-                                // 0xf4, 0x80-0xbf, 0x80-0xbf, 0x80-0xbf
-                                state = State.FOUR_80bf_3;
-                            else
-                                // 0xf1-0xf3, 0x80-0xbf, 0x80-0xbf, 0x80-0xbf
-                                state = State.FOUR_80bf_3;
-                            break;
-                        }
-                        else
-                            return false; // malformed.
-                        break;
-                    case TWO:
-                        // validate second byte of 2-byte char, 0x80-0xbf
-                        if ((b & 0xc0) != 0x80)
-                            return false;
-                        state = State.START;
-                        break;
-                    case TWO_80:
-                        if (b != (byte)0x80)
-                            return false;
-                        state = State.START;
-                        break;
-                    case THREE_a0bf:
-                        if ((b & 0xe0) == 0x80)
-                            return false;
-                        state = State.THREE_80bf_1;
-                        break;
-                    case THREE_80bf_1:
-                        // expecting 0x80-0xbf
-                        if ((b & 0xc0) != 0x80)
-                            return false;
-                        state = State.START;
-                        break;
-                    case THREE_80bf_2:
-                        // expecting 0x80-bf and then another of the same.
-                        if ((b & 0xc0) != 0x80)
-                            return false;
-                        state = State.THREE_80bf_1;
-                        break;
-                    case FOUR_90bf:
-                        // expecting 0x90-bf. 2nd byte of 4byte sequence. after that it should degrade to 80-bf,80-bf (like 3byte seq).
-                        if ((b & 0x30) == 0)
-                            return false;
-                        state = State.THREE_80bf_2;
-                        break;
-                    case FOUR_80bf_3:
-                        // expecting 0x80-bf 3 times. degenerates to THREE_80bf_2.
-                        if ((b & 0xc0) != 0x80)
-                            return false;
-                        state = State.THREE_80bf_2;
-                        break;
-                    default:
-                        return false; // invalid state.
-                }
-            }
-            // if state != start, we've got underflow. that's an error.
-            return state == State.START;
-        }
+        UTF8Serializer.instance.validate(bytes);
     }
 
     @Override
@@ -196,4 +72,10 @@ public class UTF8Type extends AbstractType<String>
     {
         return CQL3Type.Native.TEXT;
     }
+
+    @Override
+    public AbstractSerializer<String> asComposer()
+    {
+        return UTF8Serializer.instance;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/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 a0193dd..159cab3 100644
--- a/src/java/org/apache/cassandra/db/marshal/UUIDType.java
+++ b/src/java/org/apache/cassandra/db/marshal/UUIDType.java
@@ -22,13 +22,15 @@ import java.nio.ByteBuffer;
 import java.text.ParseException;
 import java.util.UUID;
 
-import org.apache.cassandra.cql.jdbc.JdbcUUID;
 import org.apache.cassandra.cql3.CQL3Type;
+import org.apache.cassandra.type.AbstractSerializer;
+import org.apache.cassandra.type.MarshalException;
+import org.apache.cassandra.type.UUIDSerializer;
 import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.cassandra.utils.UUIDGen;
 import org.apache.commons.lang.time.DateUtils;
 
-import static org.apache.cassandra.cql.jdbc.JdbcDate.iso8601Patterns;
+import static org.apache.cassandra.type.DateSerializer.iso8601Patterns;
 
 /**
  * Compares UUIDs using the following criteria:<br>
@@ -159,32 +161,22 @@ public class UUIDType extends AbstractType<UUID>
     public UUID compose(ByteBuffer bytes)
     {
 
-        return JdbcUUID.instance.compose(bytes);
+        return UUIDSerializer.instance.serialize(bytes);
     }
 
     public void validate(ByteBuffer bytes)
     {
-        if ((bytes.remaining() != 0) && (bytes.remaining() != 16))
-        {
-            throw new MarshalException("UUIDs must be exactly 16 bytes");
-        }
+        UUIDSerializer.instance.validate(bytes);
     }
 
     public String getString(ByteBuffer bytes)
     {
-        try
-        {
-            return JdbcUUID.instance.getString(bytes);
-        }
-        catch (org.apache.cassandra.cql.jdbc.MarshalException e)
-        {
-            throw new MarshalException(e.getMessage());
-        }
+        return UUIDSerializer.instance.getString(bytes);
     }
 
     public ByteBuffer decompose(UUID value)
     {
-        return JdbcUUID.instance.decompose(value);
+        return UUIDSerializer.instance.deserialize(value);
     }
 
     @Override
@@ -209,8 +201,7 @@ public class UUIDType extends AbstractType<UUID>
             {
                 throw new MarshalException(String.format("unable to make UUID from '%s'", source), e);
             }
-        }
-        else if (source.toLowerCase().equals("now"))
+        } else if (source.toLowerCase().equals("now"))
         {
             idBytes = ByteBuffer.wrap(UUIDGen.getTimeUUIDBytes());
         }
@@ -247,4 +238,10 @@ public class UUIDType extends AbstractType<UUID>
     {
         return CQL3Type.Native.UUID;
     }
+
+    @Override
+    public AbstractSerializer<UUID> asComposer()
+    {
+        return UUIDSerializer.instance;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/hadoop/cql3/CqlPagingRecordReader.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/hadoop/cql3/CqlPagingRecordReader.java b/src/java/org/apache/cassandra/hadoop/cql3/CqlPagingRecordReader.java
index 55f67cc..70db75a 100644
--- a/src/java/org/apache/cassandra/hadoop/cql3/CqlPagingRecordReader.java
+++ b/src/java/org/apache/cassandra/hadoop/cql3/CqlPagingRecordReader.java
@@ -414,7 +414,7 @@ public class CqlPagingRecordReader extends RecordReader<Map<String, ByteBuffer>,
             return previousIndex - 1;
         }
 
-        /** compose the prepared query, pair.left is query id, pair.right is query */
+        /** serialize the prepared query, pair.left is query id, pair.right is query */
         private Pair<Integer, String> composeQuery(String columns)
         {
             Pair<Integer, String> clause = whereClause();
@@ -464,7 +464,7 @@ public class CqlPagingRecordReader extends RecordReader<Map<String, ByteBuffer>,
             return result;
         }
 
-        /** compose the where clause */
+        /** serialize the where clause */
         private Pair<Integer, String> whereClause()
         {
             if (partitionKeyString == null)
@@ -488,7 +488,7 @@ public class CqlPagingRecordReader extends RecordReader<Map<String, ByteBuffer>,
                                " WHERE token(" + partitionKeyString + ") = token(" + partitionKeyMarkers + ") " + clause.right);
         }
 
-        /** recursively compose the where clause */
+        /** recursively serialize the where clause */
         private Pair<Integer, String> whereClause(List<BoundColumn> column, int position)
         {
             if (position == column.size() - 1 || column.get(position + 1).value == null)
@@ -509,7 +509,7 @@ public class CqlPagingRecordReader extends RecordReader<Map<String, ByteBuffer>,
             return true;
         }
 
-        /** compose the partition key string in format of <key1>, <key2>, <key3> */
+        /** serialize the partition key string in format of <key1>, <key2>, <key3> */
         private String keyString(List<BoundColumn> columns)
         {
             String result = null;
@@ -519,7 +519,7 @@ public class CqlPagingRecordReader extends RecordReader<Map<String, ByteBuffer>,
             return result == null ? "" : result;
         }
 
-        /** compose the question marks for partition key string in format of ?, ? , ? */
+        /** serialize the question marks for partition key string in format of ?, ? , ? */
         private String partitionKeyMarkers()
         {
             String result = null;
@@ -529,7 +529,7 @@ public class CqlPagingRecordReader extends RecordReader<Map<String, ByteBuffer>,
             return result;
         }
 
-        /** compose the query binding variables, pair.left is query id, pair.right is the binding variables */
+        /** serialize the query binding variables, pair.left is query id, pair.right is the binding variables */
         private Pair<Integer, List<ByteBuffer>> preparedQueryBindValues()
         {
             List<ByteBuffer> values = new LinkedList<ByteBuffer>();
@@ -561,7 +561,7 @@ public class CqlPagingRecordReader extends RecordReader<Map<String, ByteBuffer>,
             }
         }
 
-        /** recursively compose the query binding variables */
+        /** recursively serialize the query binding variables */
         private int preparedQueryBindValues(List<BoundColumn> column, int position, List<ByteBuffer> bindValues)
         {
             if (position == column.size() - 1 || column.get(position + 1).value == null)
@@ -721,7 +721,7 @@ public class CqlPagingRecordReader extends RecordReader<Map<String, ByteBuffer>,
     {
         try
         {
-            // always treat counters like longs, specifically CCT.compose is not what we need
+            // always treat counters like longs, specifically CCT.serialize is not what we need
             if (type != null && type.equals("org.apache.cassandra.db.marshal.CounterColumnType"))
                 return LongType.instance;
             return TypeParser.parse(type);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/hadoop/cql3/CqlRecordWriter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/hadoop/cql3/CqlRecordWriter.java b/src/java/org/apache/cassandra/hadoop/cql3/CqlRecordWriter.java
index 642d8c4..cc8500e 100644
--- a/src/java/org/apache/cassandra/hadoop/cql3/CqlRecordWriter.java
+++ b/src/java/org/apache/cassandra/hadoop/cql3/CqlRecordWriter.java
@@ -356,7 +356,7 @@ final class CqlRecordWriter extends AbstractColumnFamilyRecordWriter<Map<String,
     {
         try
         {
-            // always treat counters like longs, specifically CCT.compose is not what we need
+            // always treat counters like longs, specifically CCT.serialize is not what we need
             if (type != null && type.equals("org.apache.cassandra.db.marshal.CounterColumnType"))
                 return LongType.instance;
             return TypeParser.parse(type);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/io/sstable/SSTableIdentityIterator.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/SSTableIdentityIterator.java b/src/java/org/apache/cassandra/io/sstable/SSTableIdentityIterator.java
index 65164ef..02dedaf 100644
--- a/src/java/org/apache/cassandra/io/sstable/SSTableIdentityIterator.java
+++ b/src/java/org/apache/cassandra/io/sstable/SSTableIdentityIterator.java
@@ -20,13 +20,13 @@ package org.apache.cassandra.io.sstable;
 import java.io.*;
 import java.util.Iterator;
 
+import org.apache.cassandra.type.MarshalException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.apache.cassandra.config.CFMetaData;
 import org.apache.cassandra.db.*;
 import org.apache.cassandra.db.columniterator.OnDiskAtomIterator;
-import org.apache.cassandra.db.marshal.MarshalException;
 import org.apache.cassandra.io.util.RandomAccessReader;
 
 public class SSTableIdentityIterator implements Comparable<SSTableIdentityIterator>, OnDiskAtomIterator

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/thrift/CassandraServer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/thrift/CassandraServer.java b/src/java/org/apache/cassandra/thrift/CassandraServer.java
index 41e04ef..c9cb9eb 100644
--- a/src/java/org/apache/cassandra/thrift/CassandraServer.java
+++ b/src/java/org/apache/cassandra/thrift/CassandraServer.java
@@ -50,7 +50,7 @@ import org.apache.cassandra.db.filter.IDiskAtomFilter;
 import org.apache.cassandra.db.filter.NamesQueryFilter;
 import org.apache.cassandra.db.filter.SliceQueryFilter;
 import org.apache.cassandra.db.marshal.CompositeType;
-import org.apache.cassandra.db.marshal.MarshalException;
+import org.apache.cassandra.type.MarshalException;
 import org.apache.cassandra.db.marshal.TimeUUIDType;
 import org.apache.cassandra.dht.*;
 import org.apache.cassandra.exceptions.*;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/thrift/ThriftValidation.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/thrift/ThriftValidation.java b/src/java/org/apache/cassandra/thrift/ThriftValidation.java
index 6f83243..6f14a37 100644
--- a/src/java/org/apache/cassandra/thrift/ThriftValidation.java
+++ b/src/java/org/apache/cassandra/thrift/ThriftValidation.java
@@ -20,6 +20,7 @@ package org.apache.cassandra.thrift;
 import java.nio.ByteBuffer;
 import java.util.*;
 
+import org.apache.cassandra.type.MarshalException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -31,7 +32,6 @@ import org.apache.cassandra.db.filter.SliceQueryFilter;
 import org.apache.cassandra.db.index.SecondaryIndexManager;
 import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.db.marshal.CompositeType;
-import org.apache.cassandra.db.marshal.MarshalException;
 import org.apache.cassandra.dht.IPartitioner;
 import org.apache.cassandra.dht.Token;
 import org.apache.cassandra.service.StorageService;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/tools/SSTableImport.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/SSTableImport.java b/src/java/org/apache/cassandra/tools/SSTableImport.java
index ecdcdd5..6e032d0 100644
--- a/src/java/org/apache/cassandra/tools/SSTableImport.java
+++ b/src/java/org/apache/cassandra/tools/SSTableImport.java
@@ -28,6 +28,7 @@ import java.util.SortedMap;
 import java.util.TreeMap;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.cassandra.type.MarshalException;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
 import org.apache.commons.cli.Option;
@@ -43,7 +44,6 @@ import org.apache.cassandra.config.Schema;
 import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.db.marshal.BytesType;
 import org.apache.cassandra.db.marshal.CompositeType;
-import org.apache.cassandra.db.marshal.MarshalException;
 import org.apache.cassandra.dht.IPartitioner;
 import org.apache.cassandra.io.sstable.SSTableWriter;
 import org.apache.cassandra.utils.ByteBufferUtil;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/tools/Shuffle.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/Shuffle.java b/src/java/org/apache/cassandra/tools/Shuffle.java
index cb9f2a4..5749a81 100644
--- a/src/java/org/apache/cassandra/tools/Shuffle.java
+++ b/src/java/org/apache/cassandra/tools/Shuffle.java
@@ -43,7 +43,7 @@ import javax.management.MBeanServerConnection;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
-import org.apache.cassandra.cql.jdbc.JdbcDate;
+import org.apache.cassandra.type.DateSerializer;
 import org.apache.cassandra.dht.IPartitioner;
 import org.apache.cassandra.dht.Token;
 import org.apache.cassandra.locator.EndpointSnitchInfoMBean;
@@ -389,7 +389,7 @@ public class Shuffle extends AbstractJmxClient
 
                 ByteBuffer tokenBytes = ByteBuffer.wrap(row.getColumns().get(0).getValue());
                 ByteBuffer requestedAt = ByteBuffer.wrap(row.getColumns().get(1).getValue());
-                Date time = JdbcDate.instance.compose(requestedAt);
+                Date time = DateSerializer.instance.serialize(requestedAt);
                 Token<?> token = partitioner.getTokenFactory().fromByteArray(tokenBytes);
 
                 writeln("%-42s %-15s %s", token.toString(), host, time.toString());

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/type/AbstractSerializer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/type/AbstractSerializer.java b/src/java/org/apache/cassandra/type/AbstractSerializer.java
new file mode 100644
index 0000000..85a0e39
--- /dev/null
+++ b/src/java/org/apache/cassandra/type/AbstractSerializer.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.type;
+
+import java.nio.ByteBuffer;
+
+public abstract class AbstractSerializer<T>
+{
+    public abstract T serialize(ByteBuffer bytes);
+    public abstract ByteBuffer deserialize(T value);
+
+
+    /* validate that the byte array is a valid sequence for the type we are supposed to be comparing */
+    public abstract void validate(ByteBuffer bytes) throws MarshalException;
+
+    public abstract String getString(ByteBuffer bytes);
+    public abstract String toString(T value);
+
+    public abstract Class<T> getType();
+}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/type/AsciiSerializer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/type/AsciiSerializer.java b/src/java/org/apache/cassandra/type/AsciiSerializer.java
new file mode 100644
index 0000000..72a8312
--- /dev/null
+++ b/src/java/org/apache/cassandra/type/AsciiSerializer.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.type;
+
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+
+public class AsciiSerializer extends AbstractSerializer<String>
+{
+    public static final AsciiSerializer instance = new AsciiSerializer();
+    private static final Charset US_ASCII = Charset.forName("US-ASCII");
+
+    @Override
+    public String serialize(ByteBuffer bytes)
+    {
+        return getString(bytes);
+    }
+
+    @Override
+    public ByteBuffer deserialize(String value)
+    {
+        return ByteBufferUtil.bytes(value, US_ASCII);
+    }
+
+    @Override
+    public void validate(ByteBuffer bytes) throws MarshalException
+    {
+        // 0-127
+        for (int i = bytes.position(); i < bytes.limit(); i++)
+        {
+            byte b = bytes.get(i);
+            if (b < 0 || b > 127)
+                throw new MarshalException("Invalid byte for ascii: " + Byte.toString(b));
+        }
+    }
+
+    @Override
+    public String getString(ByteBuffer bytes)
+    {
+        try
+        {
+            return ByteBufferUtil.string(bytes, US_ASCII);
+        }
+        catch (CharacterCodingException e)
+        {
+            throw new MarshalException("Invalid ascii bytes " + ByteBufferUtil.bytesToHex(bytes));
+        }
+    }
+
+    @Override
+    public String toString(String value)
+    {
+        return value;
+    }
+
+    @Override
+    public Class<String> getType()
+    {
+        return String.class;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/type/BooleanSerializer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/type/BooleanSerializer.java b/src/java/org/apache/cassandra/type/BooleanSerializer.java
new file mode 100644
index 0000000..e2d200c
--- /dev/null
+++ b/src/java/org/apache/cassandra/type/BooleanSerializer.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.type;
+
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+import java.nio.ByteBuffer;
+
+public class BooleanSerializer extends AbstractSerializer<Boolean>
+{
+    public static final BooleanSerializer instance = new BooleanSerializer();
+
+    @Override
+    public Boolean serialize(ByteBuffer bytes)
+    {
+        byte value = bytes.get(bytes.position());
+        return value != 0;
+    }
+
+    @Override
+    public ByteBuffer deserialize(Boolean value)
+    {
+        return (value == null) ? ByteBufferUtil.EMPTY_BYTE_BUFFER
+                : value ? ByteBuffer.wrap(new byte[] {1})  // true
+                : ByteBuffer.wrap(new byte[] {0}); // false
+    }
+
+    @Override
+    public void validate(ByteBuffer bytes) throws MarshalException
+    {
+        if (bytes.remaining() != 1 && bytes.remaining() != 0)
+            throw new MarshalException(String.format("Expected 1 or 0 byte value (%d)", bytes.remaining()));
+    }
+
+    @Override
+    public String getString(ByteBuffer bytes)
+    {
+        if (bytes.remaining() == 0)
+        {
+            return Boolean.FALSE.toString();
+        }
+        if (bytes.remaining() != 1)
+        {
+            throw new MarshalException("A boolean is stored in exactly 1 byte: " + bytes.remaining());
+        }
+        byte value = bytes.get(bytes.position());
+
+        return value == 0 ? Boolean.FALSE.toString() : Boolean.TRUE.toString();
+    }
+
+    @Override
+    public String toString(Boolean value)
+    {
+        return value == null ? "" : value.toString();
+    }
+
+    @Override
+    public Class<Boolean> getType()
+    {
+        return Boolean.class;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/type/BytesSerializer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/type/BytesSerializer.java b/src/java/org/apache/cassandra/type/BytesSerializer.java
new file mode 100644
index 0000000..2889739
--- /dev/null
+++ b/src/java/org/apache/cassandra/type/BytesSerializer.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.type;
+
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+import java.nio.ByteBuffer;
+
+public class BytesSerializer extends AbstractSerializer<ByteBuffer>
+{
+    public static final BytesSerializer instance = new BytesSerializer();
+
+    @Override
+    public ByteBuffer serialize(ByteBuffer bytes)
+    {
+        // We make a copy in case the user modifies the input
+        return bytes.duplicate();
+    }
+
+    @Override
+    public ByteBuffer deserialize(ByteBuffer value)
+    {
+        // This is from the DB, so it is not shared with someone else
+        return value;
+    }
+
+    @Override
+    public void validate(ByteBuffer bytes) throws MarshalException
+    {
+        // all bytes are legal.
+    }
+
+    @Override
+    public String getString(ByteBuffer bytes)
+    {
+        return ByteBufferUtil.bytesToHex(bytes);
+    }
+
+    @Override
+    public String toString(ByteBuffer value)
+    {
+        return getString(value);
+    }
+
+    @Override
+    public Class<ByteBuffer> getType()
+    {
+        return ByteBuffer.class;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/type/CollectionSerializer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/type/CollectionSerializer.java b/src/java/org/apache/cassandra/type/CollectionSerializer.java
new file mode 100644
index 0000000..2eb3944
--- /dev/null
+++ b/src/java/org/apache/cassandra/type/CollectionSerializer.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.type;
+
+import java.nio.ByteBuffer;
+import java.util.List;
+
+public abstract class CollectionSerializer<T> extends AbstractSerializer<T>
+{
+    @Override
+    public void validate(ByteBuffer bytes) throws MarshalException
+    {
+        // The collection is not currently being properly validated.
+    }
+
+    public String getString(ByteBuffer bytes)
+    {
+        return BytesSerializer.instance.getString(bytes);
+    }
+
+    // Utilitary method
+    protected static ByteBuffer pack(List<ByteBuffer> buffers, int elements, int size)
+    {
+        ByteBuffer result = ByteBuffer.allocate(2 + size);
+        result.putShort((short)elements);
+        for (ByteBuffer bb : buffers)
+        {
+            result.putShort((short)bb.remaining());
+            result.put(bb.duplicate());
+        }
+        return (ByteBuffer)result.flip();
+    }
+
+    public static ByteBuffer pack(List<ByteBuffer> buffers, int elements)
+    {
+        int size = 0;
+        for (ByteBuffer bb : buffers)
+            size += 2 + bb.remaining();
+        return pack(buffers, elements, size);
+    }
+
+
+    protected static int getUnsignedShort(ByteBuffer bb)
+    {
+        int length = (bb.get() & 0xFF) << 8;
+        return length | (bb.get() & 0xFF);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/type/CounterSerializer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/type/CounterSerializer.java b/src/java/org/apache/cassandra/type/CounterSerializer.java
new file mode 100644
index 0000000..c0625c3
--- /dev/null
+++ b/src/java/org/apache/cassandra/type/CounterSerializer.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.type;
+
+public class CounterSerializer extends LongSerializer
+{
+}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/type/DateSerializer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/type/DateSerializer.java b/src/java/org/apache/cassandra/type/DateSerializer.java
new file mode 100644
index 0000000..4f0186c
--- /dev/null
+++ b/src/java/org/apache/cassandra/type/DateSerializer.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.type;
+
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+import java.nio.ByteBuffer;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class DateSerializer extends AbstractSerializer<Date>
+{
+    public static final String[] iso8601Patterns = new String[] {
+            "yyyy-MM-dd HH:mm",
+            "yyyy-MM-dd HH:mm:ss",
+            "yyyy-MM-dd HH:mmZ",
+            "yyyy-MM-dd HH:mm:ssZ",
+            "yyyy-MM-dd'T'HH:mm",
+            "yyyy-MM-dd'T'HH:mmZ",
+            "yyyy-MM-dd'T'HH:mm:ss",
+            "yyyy-MM-dd'T'HH:mm:ssZ",
+            "yyyy-MM-dd",
+            "yyyy-MM-ddZ"
+    };
+
+    static final String DEFAULT_FORMAT = iso8601Patterns[3];
+
+    static final ThreadLocal<SimpleDateFormat> FORMATTER = new ThreadLocal<SimpleDateFormat>()
+    {
+        protected SimpleDateFormat initialValue()
+        {
+            return new SimpleDateFormat(DEFAULT_FORMAT);
+        }
+    };
+
+    public static final DateSerializer instance = new DateSerializer();
+
+    @Override
+    public Date serialize(ByteBuffer bytes)
+    {
+        return bytes.remaining() > 0
+                ? new Date(ByteBufferUtil.toLong(bytes))
+                : null;
+    }
+
+    @Override
+    public ByteBuffer deserialize(Date value)
+    {
+        return (value == null)
+                ? ByteBufferUtil.EMPTY_BYTE_BUFFER
+                : ByteBufferUtil.bytes(value.getTime());
+    }
+
+    @Override
+    public void validate(ByteBuffer bytes) throws MarshalException
+    {
+        if (bytes.remaining() != 8 && bytes.remaining() != 0)
+            throw new MarshalException(String.format("Expected 8 or 0 byte long for date (%d)", bytes.remaining()));
+    }
+
+    @Override
+    public String getString(ByteBuffer bytes)
+    {
+        if (bytes.remaining() == 0)
+        {
+            return "";
+        }
+        if (bytes.remaining() != 8)
+        {
+            throw new MarshalException("A date is exactly 8 bytes (stored as a long): " + bytes.remaining());
+        }
+
+        // uses ISO-8601 formatted string
+        return FORMATTER.get().format(new Date(ByteBufferUtil.toLong(bytes)));
+    }
+
+    @Override
+    public String toString(Date value)
+    {
+        return FORMATTER.get().format(value);
+    }
+
+    @Override
+    public Class<Date> getType()
+    {
+        return Date.class;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e9c67424/src/java/org/apache/cassandra/type/DecimalSerializer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/type/DecimalSerializer.java b/src/java/org/apache/cassandra/type/DecimalSerializer.java
new file mode 100644
index 0000000..b8ad00b
--- /dev/null
+++ b/src/java/org/apache/cassandra/type/DecimalSerializer.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.type;
+
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+
+public class DecimalSerializer extends AbstractSerializer<BigDecimal>
+{
+    public static final DecimalSerializer instance = new DecimalSerializer();
+
+    @Override
+    public BigDecimal serialize(ByteBuffer bytes)
+    {
+        if (bytes == null)
+            return null;
+
+        // do not consume the contents of the ByteBuffer
+        bytes = bytes.duplicate();
+        int scale = bytes.getInt();
+        byte[] bibytes = new byte[bytes.remaining()];
+        bytes.get(bibytes);
+
+        BigInteger bi = new BigInteger(bibytes);
+        return new BigDecimal(bi, scale);
+    }
+
+    @Override
+    public ByteBuffer deserialize(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);
+    }
+
+    @Override
+    public void validate(ByteBuffer bytes) throws MarshalException
+    {
+        // no useful check for invalid decimals.
+    }
+
+    @Override
+    public String getString(ByteBuffer bytes)
+    {
+        if (bytes.remaining() == 0)
+        {
+            return "";
+        }
+        return serialize(bytes).toPlainString();
+    }
+
+    @Override
+    public String toString(BigDecimal value)
+    {
+        return value == null ? "" : value.toPlainString();
+    }
+
+    @Override
+    public Class<BigDecimal> getType()
+    {
+        return BigDecimal.class;
+    }
+}


Mime
View raw message