cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject svn commit: r1164691 - /cassandra/trunk/src/java/org/apache/cassandra/cql/term/
Date Fri, 02 Sep 2011 20:26:32 GMT
Author: eevans
Date: Fri Sep  2 20:26:31 2011
New Revision: 1164691

URL: http://svn.apache.org/viewvc?rev=1164691&view=rev
Log:
create package for CQL term marshaling

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

Added:
    cassandra/trunk/src/java/org/apache/cassandra/cql/term/
    cassandra/trunk/src/java/org/apache/cassandra/cql/term/AbstractTerm.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/term/AbstractUUIDTerm.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/term/AsciiTerm.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/term/BooleanTerm.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/term/BytesTerm.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/term/CounterColumnTerm.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/term/DateTerm.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/term/DoubleTerm.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/term/FloatTerm.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/term/IntegerTerm.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/term/LexicalUUIDTerm.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/term/LongTerm.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/term/MarshalException.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/term/TimeUUIDTerm.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/term/TypesMap.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/term/UTF8Term.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/term/UUIDTerm.java

Added: cassandra/trunk/src/java/org/apache/cassandra/cql/term/AbstractTerm.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/term/AbstractTerm.java?rev=1164691&view=auto
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/term/AbstractTerm.java (added)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/term/AbstractTerm.java Fri Sep  2 20:26:31
2011
@@ -0,0 +1,44 @@
+package org.apache.cassandra.cql.term;
+/*
+ * 
+ * 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.
+ * 
+ */
+
+
+import java.nio.ByteBuffer;
+
+public abstract class AbstractTerm<T>
+{
+    public abstract boolean isCaseSensitive();
+    public abstract int getScale(T obj);
+    public abstract int getPrecision(T obj);
+    public abstract boolean isCurrency();
+    public abstract boolean isSigned();
+    public abstract String toString(T obj);
+    public abstract boolean needsQuotes();
+    public abstract String getString(ByteBuffer bytes);
+    public abstract Class<T> getType();
+    public abstract int getJdbcType();
+    public abstract T compose(ByteBuffer bytes);
+    
+    public boolean isCommutative()
+    {
+        return false;
+    }
+}

Added: cassandra/trunk/src/java/org/apache/cassandra/cql/term/AbstractUUIDTerm.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/term/AbstractUUIDTerm.java?rev=1164691&view=auto
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/term/AbstractUUIDTerm.java (added)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/term/AbstractUUIDTerm.java Fri Sep 
2 20:26:31 2011
@@ -0,0 +1,73 @@
+package org.apache.cassandra.cql.term;
+/*
+ * 
+ * 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.
+ * 
+ */
+
+
+import java.sql.Types;
+import java.util.UUID;
+
+public abstract class AbstractUUIDTerm extends AbstractTerm<UUID>
+{
+    public String toString(UUID obj)
+    {
+        return obj.toString();
+    }
+    
+    public boolean isCaseSensitive()
+    {
+        return false;
+    }
+
+    public int getScale(UUID obj)
+    {
+        return -1;
+    }
+
+    public int getPrecision(UUID obj)
+    {
+        return -1;
+    }
+
+    public boolean isCurrency()
+    {
+        return false;
+    }
+
+    public boolean isSigned()
+    {
+        return false;
+    }
+
+    public boolean needsQuotes()
+    {
+        return false;
+    }
+
+    public Class<UUID> getType()
+    {
+        return UUID.class;
+    }
+
+    public int getJdbcType()
+    {
+        return Types.OTHER;
+    }
+}

Added: cassandra/trunk/src/java/org/apache/cassandra/cql/term/AsciiTerm.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/term/AsciiTerm.java?rev=1164691&view=auto
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/term/AsciiTerm.java (added)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/term/AsciiTerm.java Fri Sep  2 20:26:31
2011
@@ -0,0 +1,100 @@
+package org.apache.cassandra.cql.term;
+/*
+ * 
+ * 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.
+ * 
+ */
+
+
+import java.nio.ByteBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.sql.Types;
+
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+import com.google.common.base.Charsets;
+
+public class AsciiTerm extends AbstractTerm<String>
+{
+    public static final AsciiTerm instance = new AsciiTerm();
+    
+    AsciiTerm() {}
+    
+    public boolean isCaseSensitive()
+    {
+        return true;
+    }
+
+    public int getScale(String obj)
+    {
+        return -1;
+    }
+
+    public int getPrecision(String obj)
+    {
+        return -1;
+    }
+
+    public boolean isCurrency()
+    {
+        return false;
+    }
+
+    public boolean isSigned()
+    {
+        return false;
+    }
+
+    public String toString(String obj)
+    {
+        return obj;
+    }
+
+    public boolean needsQuotes()
+    {
+        return true;
+    }
+
+    public String getString(ByteBuffer bytes)
+    {
+        try
+        {
+            return ByteBufferUtil.string(bytes, Charsets.US_ASCII);
+        }
+        catch (CharacterCodingException e)
+        {
+            throw new MarshalException("Invalid ascii bytes " + ByteBufferUtil.bytesToHex(bytes));
+        }
+    }
+
+    public Class<String> getType()
+    {
+        return String.class;
+    }
+
+    public int getJdbcType()
+    {
+        return Types.VARCHAR;
+    }
+
+    public String compose(ByteBuffer bytes)
+    {
+        return getString(bytes);
+    }
+
+}

Added: cassandra/trunk/src/java/org/apache/cassandra/cql/term/BooleanTerm.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/term/BooleanTerm.java?rev=1164691&view=auto
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/term/BooleanTerm.java (added)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/term/BooleanTerm.java Fri Sep  2 20:26:31
2011
@@ -0,0 +1,99 @@
+package org.apache.cassandra.cql.term;
+/*
+ * 
+ * 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.
+ * 
+ */
+
+
+import java.nio.ByteBuffer;
+import java.sql.Types;
+
+public class BooleanTerm extends AbstractTerm<Boolean>
+{
+    public static final BooleanTerm instance = new BooleanTerm();
+    
+    BooleanTerm() {}
+    
+    public boolean isCaseSensitive()
+    {
+        return false;
+    }
+
+    public int getScale(Boolean obj)
+    {
+        return -1;
+    }
+
+    public int getPrecision(Boolean obj)
+    {
+        return -1;
+    }
+
+    public boolean isCurrency()
+    {
+        return false;
+    }
+
+    public boolean isSigned()
+    {
+        return false;
+    }
+
+    public String toString(Boolean obj)
+    {
+        return obj.toString();
+    }
+
+    public boolean needsQuotes()
+    {
+        return false;
+    }
+
+    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();
+    }
+
+    public Class<Boolean> getType()
+    {
+        return Boolean.class;
+    }
+
+    public int getJdbcType()
+    {
+        return Types.BOOLEAN;
+    }
+
+    public Boolean compose(ByteBuffer bytes)
+    {
+        byte value = bytes.get(bytes.position());
+        return Boolean.valueOf(value ==0 ? false:true);
+    }
+
+}

Added: cassandra/trunk/src/java/org/apache/cassandra/cql/term/BytesTerm.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/term/BytesTerm.java?rev=1164691&view=auto
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/term/BytesTerm.java (added)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/term/BytesTerm.java Fri Sep  2 20:26:31
2011
@@ -0,0 +1,90 @@
+package org.apache.cassandra.cql.term;
+/*
+ * 
+ * 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.
+ * 
+ */
+
+
+import java.nio.ByteBuffer;
+import java.sql.Types;
+
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+
+public class BytesTerm extends AbstractTerm<ByteBuffer>
+{
+    public static final BytesTerm instance = new BytesTerm();
+    
+    BytesTerm() {}
+
+    public boolean isCaseSensitive()
+    {
+        return false;
+    }
+
+    public int getScale(ByteBuffer obj)
+    {
+        return -1;
+    }
+
+    public int getPrecision(ByteBuffer obj)
+    {
+        return -1;
+    }
+
+    public boolean isCurrency()
+    {
+        return false;
+    }
+
+    public boolean isSigned()
+    {
+        return false;
+    }
+
+    public String toString(ByteBuffer obj)
+    {
+        return getString(obj);
+    }
+
+    public boolean needsQuotes()
+    {
+        return true;
+    }
+
+    public String getString(ByteBuffer bytes)
+    {
+        return ByteBufferUtil.bytesToHex(bytes);
+    }
+
+    public Class<ByteBuffer> getType()
+    {
+        return ByteBuffer.class;
+    }
+
+    public int getJdbcType()
+    {
+        return Types.BINARY;
+    }
+
+    public ByteBuffer compose(ByteBuffer bytes)
+    {
+        return bytes.duplicate();
+    }
+}

Added: cassandra/trunk/src/java/org/apache/cassandra/cql/term/CounterColumnTerm.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/term/CounterColumnTerm.java?rev=1164691&view=auto
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/term/CounterColumnTerm.java (added)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/term/CounterColumnTerm.java Fri Sep
 2 20:26:31 2011
@@ -0,0 +1,13 @@
+package org.apache.cassandra.cql.term;
+
+public class CounterColumnTerm extends LongTerm
+{
+    public static final CounterColumnTerm instance = new CounterColumnTerm();
+    
+    CounterColumnTerm() {}
+    
+    public boolean isCommutative()
+    {
+        return true;
+    }
+}

Added: cassandra/trunk/src/java/org/apache/cassandra/cql/term/DateTerm.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/term/DateTerm.java?rev=1164691&view=auto
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/term/DateTerm.java (added)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/term/DateTerm.java Fri Sep  2 20:26:31
2011
@@ -0,0 +1,116 @@
+package org.apache.cassandra.cql.term;
+/*
+ * 
+ * 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.
+ * 
+ */
+
+
+import java.nio.ByteBuffer;
+import java.sql.Types;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+public class DateTerm extends AbstractTerm<Date>
+{
+    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 SimpleDateFormat FORMATTER = new SimpleDateFormat(DEFAULT_FORMAT);
+    
+    public static final DateTerm instance = new DateTerm();
+    
+    DateTerm() {}
+    
+    public boolean isCaseSensitive()
+    {
+        return false;
+    }
+
+    public int getScale(Date obj)
+    {
+        return -1;
+    }
+
+    public int getPrecision(Date obj)
+    {
+        return -1;
+    }
+
+    public boolean isCurrency()
+    {
+        return false;
+    }
+
+    public boolean isSigned()
+    {
+        return false;
+    }
+
+    public String toString(Date obj)
+    {
+        return FORMATTER.format(obj);
+    }
+
+    public boolean needsQuotes()
+    {
+        return false;
+    }
+
+    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.format(new Date(bytes.getLong(bytes.position())));
+    }
+
+    public Class<Date> getType()
+    {
+        return Date.class;
+    }
+
+    public int getJdbcType()
+    {
+        return Types.DATE;
+    }
+
+    public Date compose(ByteBuffer bytes)
+    {
+        return new Date(ByteBufferUtil.toLong(bytes));
+    }
+}

Added: cassandra/trunk/src/java/org/apache/cassandra/cql/term/DoubleTerm.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/term/DoubleTerm.java?rev=1164691&view=auto
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/term/DoubleTerm.java (added)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/term/DoubleTerm.java Fri Sep  2 20:26:31
2011
@@ -0,0 +1,98 @@
+package org.apache.cassandra.cql.term;
+/*
+ * 
+ * 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.
+ * 
+ */
+
+
+import java.nio.ByteBuffer;
+import java.sql.Types;
+
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+public class DoubleTerm extends AbstractTerm<Double>
+{
+    public static final DoubleTerm instance = new DoubleTerm();
+    
+    DoubleTerm() {}
+    
+    public boolean isCaseSensitive()
+    {
+        return false;
+    }
+
+    public int getScale(Double obj)
+    {
+        return 300;
+    }
+
+    public int getPrecision(Double obj)
+    {
+        return 15;
+    }
+
+    public boolean isCurrency()
+    {
+        return false;
+    }
+
+    public boolean isSigned()
+    {
+        return true;
+    }
+
+    public String toString(Double obj)
+    {
+        return obj.toString();
+    }
+
+    public boolean needsQuotes()
+    {
+        return false;
+    }
+
+    public String getString(ByteBuffer bytes)
+    {
+        if (bytes.remaining() == 0)
+        {
+            return "";
+        }
+        if (bytes.remaining() != 8)
+        {
+            throw new MarshalException("A double is exactly 8 bytes : "+bytes.remaining());
+        }
+        
+        return ((Double)ByteBufferUtil.toDouble(bytes)).toString();
+    }
+
+    public Class<Double> getType()
+    {
+        return Double.class;
+    }
+
+    public int getJdbcType()
+    {
+        return Types.DOUBLE;
+    }
+
+    public Double compose(ByteBuffer bytes)
+    {
+        return ByteBufferUtil.toDouble(bytes);
+    }
+}

Added: cassandra/trunk/src/java/org/apache/cassandra/cql/term/FloatTerm.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/term/FloatTerm.java?rev=1164691&view=auto
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/term/FloatTerm.java (added)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/term/FloatTerm.java Fri Sep  2 20:26:31
2011
@@ -0,0 +1,98 @@
+package org.apache.cassandra.cql.term;
+/*
+ * 
+ * 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.
+ * 
+ */
+
+
+import java.nio.ByteBuffer;
+import java.sql.Types;
+
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+public class FloatTerm extends AbstractTerm<Float>
+{
+    public static final FloatTerm instance = new FloatTerm();
+    
+    FloatTerm() {}
+    
+    public boolean isCaseSensitive()
+    {
+        return false;
+    }
+
+    public int getScale(Float obj)
+    {
+        return 40;
+    }
+
+    public int getPrecision(Float obj)
+    {
+        return 7;
+    }
+
+    public boolean isCurrency()
+    {
+        return false;
+    }
+
+    public boolean isSigned()
+    {
+        return true;
+    }
+
+    public String toString(Float obj)
+    {
+        return obj.toString();
+    }
+
+    public boolean needsQuotes()
+    {
+        return false;
+    }
+
+    public String getString(ByteBuffer bytes)
+    {
+        if (bytes.remaining() == 0)
+        {
+            return "";
+        }
+        if (bytes.remaining() != 4)
+        {
+            throw new MarshalException("A float is exactly 4 bytes : "+bytes.remaining());
+        }
+        
+        return ((Float)ByteBufferUtil.toFloat(bytes)).toString();
+    }
+
+    public Class<Float> getType()
+    {
+        return Float.class;
+    }
+
+    public int getJdbcType()
+    {
+        return Types.FLOAT;
+    }
+
+    public Float compose(ByteBuffer bytes)
+    {
+        return ByteBufferUtil.toFloat(bytes);
+    }
+}

Added: cassandra/trunk/src/java/org/apache/cassandra/cql/term/IntegerTerm.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/term/IntegerTerm.java?rev=1164691&view=auto
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/term/IntegerTerm.java (added)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/term/IntegerTerm.java Fri Sep  2 20:26:31
2011
@@ -0,0 +1,95 @@
+package org.apache.cassandra.cql.term;
+/*
+ * 
+ * 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.
+ * 
+ */
+
+
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+import java.sql.Types;
+
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+public class IntegerTerm extends AbstractTerm<BigInteger>
+{
+    public static final IntegerTerm instance = new IntegerTerm();
+    
+    IntegerTerm() {}
+    
+    public boolean isCaseSensitive()
+    {
+        return false;
+    }
+
+    public int getScale(BigInteger obj)
+    {
+        return 0;
+    }
+
+    public int getPrecision(BigInteger obj)
+    {
+        return obj.toString().length();
+    }
+
+    public boolean isCurrency()
+    {
+        return false;
+    }
+
+    public boolean isSigned()
+    {
+        return true;
+    }
+
+    public String toString(BigInteger obj)
+    {
+        return obj.toString();
+    }
+
+    public boolean needsQuotes()
+    {
+        return false;
+    }
+
+    public String getString(ByteBuffer bytes)
+    {
+        if (bytes == null)
+            return "null";
+        if (bytes.remaining() == 0)
+            return "empty";
+
+        return new BigInteger(ByteBufferUtil.getArray(bytes)).toString(10);
+    }
+
+    public Class<BigInteger> getType()
+    {
+        return BigInteger.class;
+    }
+
+    public int getJdbcType()
+    {
+        return Types.BIGINT;
+    }
+
+    public BigInteger compose(ByteBuffer bytes)
+    {
+        return new BigInteger(ByteBufferUtil.getArray(bytes));
+    }
+}

Added: cassandra/trunk/src/java/org/apache/cassandra/cql/term/LexicalUUIDTerm.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/term/LexicalUUIDTerm.java?rev=1164691&view=auto
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/term/LexicalUUIDTerm.java (added)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/term/LexicalUUIDTerm.java Fri Sep  2
20:26:31 2011
@@ -0,0 +1,53 @@
+package org.apache.cassandra.cql.term;
+/*
+ * 
+ * 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.
+ * 
+ */
+
+
+import java.nio.ByteBuffer;
+import java.util.UUID;
+
+import org.apache.cassandra.utils.UUIDGen;
+
+public class LexicalUUIDTerm extends AbstractUUIDTerm
+{
+    public static final LexicalUUIDTerm instance = new LexicalUUIDTerm();
+    
+    public LexicalUUIDTerm() {}
+    
+    public String getString(ByteBuffer bytes)
+    {
+        if (bytes.remaining() == 0)
+        {
+            return "";
+        }
+        if (bytes.remaining() != 16)
+        {
+            throw new MarshalException("UUIDs must be exactly 16 bytes");
+        }
+        return UUIDGen.getUUID(bytes).toString();
+    }
+
+    public UUID compose(ByteBuffer bytes)
+    {
+        return UUIDGen.getUUID(bytes);
+    }
+
+}

Added: cassandra/trunk/src/java/org/apache/cassandra/cql/term/LongTerm.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/term/LongTerm.java?rev=1164691&view=auto
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/term/LongTerm.java (added)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/term/LongTerm.java Fri Sep  2 20:26:31
2011
@@ -0,0 +1,98 @@
+package org.apache.cassandra.cql.term;
+/*
+ * 
+ * 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.
+ * 
+ */
+
+
+import java.nio.ByteBuffer;
+import java.sql.Types;
+
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+public class LongTerm extends AbstractTerm<Long>
+{
+    public static final LongTerm instance = new LongTerm();
+    
+    LongTerm() {}
+    
+    public boolean isCaseSensitive()
+    {
+        return false;
+    }
+
+    public int getScale(Long obj)
+    {
+        return 0;
+    }
+
+    public int getPrecision(Long obj)
+    {
+        return obj.toString().length();
+    }
+
+    public boolean isCurrency()
+    {
+        return false;
+    }
+
+    public boolean isSigned()
+    {
+        return true;
+    }
+
+    public String toString(Long obj)
+    {
+        return obj.toString();
+    }
+
+    public boolean needsQuotes()
+    {
+        return false;
+    }
+
+    public String getString(ByteBuffer bytes)
+    {
+        if (bytes.remaining() == 0)
+        {
+            return "";
+        }
+        if (bytes.remaining() != 8)
+        {
+            throw new MarshalException("A long is exactly 8 bytes: "+bytes.remaining());
+        }
+        
+        return String.valueOf(bytes.getLong(bytes.position()));
+    }
+
+    public Class<Long> getType()
+    {
+        return Long.class;
+    }
+
+    public int getJdbcType()
+    {
+        return Types.INTEGER;
+    }
+
+    public Long compose(ByteBuffer bytes)
+    {
+        return ByteBufferUtil.toLong(bytes);
+    }
+}

Added: cassandra/trunk/src/java/org/apache/cassandra/cql/term/MarshalException.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/term/MarshalException.java?rev=1164691&view=auto
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/term/MarshalException.java (added)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/term/MarshalException.java Fri Sep 
2 20:26:31 2011
@@ -0,0 +1,35 @@
+package org.apache.cassandra.cql.term;
+/*
+ * 
+ * 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.
+ * 
+ */
+
+
+public class MarshalException extends RuntimeException
+{
+    public MarshalException(String message)
+    {
+        super(message);
+    }
+
+    public MarshalException(String message, Throwable cause)
+    {
+        super(message, cause);
+    }
+}

Added: cassandra/trunk/src/java/org/apache/cassandra/cql/term/TimeUUIDTerm.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/term/TimeUUIDTerm.java?rev=1164691&view=auto
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/term/TimeUUIDTerm.java (added)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/term/TimeUUIDTerm.java Fri Sep  2 20:26:31
2011
@@ -0,0 +1,57 @@
+package org.apache.cassandra.cql.term;
+/*
+ * 
+ * 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.
+ * 
+ */
+
+
+import java.nio.ByteBuffer;
+import java.util.UUID;
+
+import org.apache.cassandra.utils.UUIDGen;
+
+public class TimeUUIDTerm extends AbstractUUIDTerm
+{
+    public static final TimeUUIDTerm instance = new TimeUUIDTerm();
+    
+    TimeUUIDTerm() {}
+    
+    public String getString(ByteBuffer bytes)
+    {
+        if (bytes.remaining() == 0)
+        {
+            return "";
+        }
+        if (bytes.remaining() != 16)
+        {
+            throw new MarshalException("UUIDs must be exactly 16 bytes");
+        }
+        UUID uuid = UUIDGen.getUUID(bytes);
+        if (uuid.version() != 1)
+        {
+            throw new MarshalException("TimeUUID only makes sense with version 1 UUIDs");
+        }
+        return uuid.toString();
+    }
+
+    public UUID compose(ByteBuffer bytes)
+    {
+        return UUIDGen.getUUID(bytes);
+    }
+}

Added: cassandra/trunk/src/java/org/apache/cassandra/cql/term/TypesMap.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/term/TypesMap.java?rev=1164691&view=auto
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/term/TypesMap.java (added)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/term/TypesMap.java Fri Sep  2 20:26:31
2011
@@ -0,0 +1,33 @@
+package org.apache.cassandra.cql.term;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class TypesMap
+{
+    private final static Map<String, AbstractTerm<?>> termMap = new HashMap<String,
AbstractTerm<?>>();
+    
+    static
+    {
+        termMap.put("org.apache.cassandra.db.marshal.AsciiType", AsciiTerm.instance);
+        termMap.put("org.apache.cassandra.db.marshal.BooleanType", BooleanTerm.instance);
+        termMap.put("org.apache.cassandra.db.marshal.BytesType", BytesTerm.instance);
+        termMap.put("org.apache.cassandra.db.marshal.ColumnCounterType", CounterColumnTerm.instance);
+        termMap.put("org.apache.cassandra.db.marshal.DateType", DateTerm.instance);
+        termMap.put("org.apache.cassandra.db.marshal.DoubleType", DoubleTerm.instance);
+        termMap.put("org.apache.cassandra.db.marshal.FloatType", FloatTerm.instance);
+        termMap.put("org.apache.cassandra.db.marshal.IntegerType", IntegerTerm.instance);
+        termMap.put("org.apache.cassandra.db.marshal.LexicalUUIDType", LexicalUUIDTerm.instance);
+        termMap.put("org.apache.cassandra.db.marshal.LongType", LongTerm.instance);
+        termMap.put("org.apache.cassandra.db.marshal.TimeUUIDType", TimeUUIDTerm.instance);
+        termMap.put("org.apache.cassandra.db.marshal.UTF8Type", UTF8Term.instance);
+        termMap.put("org.apache.cassandra.db.marshal.UUIDType", UUIDTerm.instance);
+    }
+    
+    public static AbstractTerm<?> getTermForComparator(String comparator) {
+        // If not fully qualified, assume it's the short name for a built-in.
+        if ((comparator != null) && (!comparator.contains(".")))
+            return termMap.get("org.apache.cassandra.db." + comparator);
+        return termMap.get(comparator);
+    }
+}

Added: cassandra/trunk/src/java/org/apache/cassandra/cql/term/UTF8Term.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/term/UTF8Term.java?rev=1164691&view=auto
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/term/UTF8Term.java (added)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/term/UTF8Term.java Fri Sep  2 20:26:31
2011
@@ -0,0 +1,97 @@
+package org.apache.cassandra.cql.term;
+/*
+ * 
+ * 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.
+ * 
+ */
+
+
+import java.nio.ByteBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.sql.Types;
+
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+public class UTF8Term extends AbstractTerm<String>
+{
+    public static final UTF8Term instance = new UTF8Term();
+    
+    public UTF8Term() {}
+    
+    public boolean isCaseSensitive()
+    {
+        return true;
+    }
+
+    public int getScale(String obj)
+    {
+        return -1;
+    }
+
+    public int getPrecision(String obj)
+    {
+        return -1;
+    }
+
+    public boolean isCurrency()
+    {
+        return false;
+    }
+
+    public boolean isSigned()
+    {
+        return false;
+    }
+
+    public String toString(String obj)
+    {
+        return obj;
+    }
+
+    public boolean needsQuotes()
+    {
+        return true;
+    }
+
+    public String getString(ByteBuffer bytes)
+    {
+        try
+        {
+            return ByteBufferUtil.string(bytes);
+        }
+        catch (CharacterCodingException e)
+        {
+            throw new MarshalException("invalid UTF8 bytes " + ByteBufferUtil.bytesToHex(bytes));
+        }
+    }
+
+    public Class<String> getType()
+    {
+        return String.class;
+    }
+
+    public int getJdbcType()
+    {
+        return Types.VARCHAR;
+    }
+
+    public String compose(ByteBuffer bytes)
+    {
+        return getString(bytes);
+    }
+}

Added: cassandra/trunk/src/java/org/apache/cassandra/cql/term/UUIDTerm.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/term/UUIDTerm.java?rev=1164691&view=auto
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/term/UUIDTerm.java (added)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/term/UUIDTerm.java Fri Sep  2 20:26:31
2011
@@ -0,0 +1,54 @@
+package org.apache.cassandra.cql.term;
+/*
+ * 
+ * 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.
+ * 
+ */
+
+
+import java.nio.ByteBuffer;
+import java.util.UUID;
+
+public class UUIDTerm extends AbstractUUIDTerm
+{
+    public static final UUIDTerm instance = new UUIDTerm();
+    
+    UUIDTerm() {}
+    
+    public UUID compose(ByteBuffer bytes)
+    {
+        bytes = bytes.slice();
+        if (bytes.remaining() < 16)
+            return new UUID(0, 0);
+        return new UUID(bytes.getLong(), bytes.getLong());
+    }
+
+    public String getString(ByteBuffer bytes)
+    {
+        if (bytes.remaining() == 0)
+        {
+            return "";
+        }
+        if (bytes.remaining() != 16)
+        {
+            throw new MarshalException("UUIDs must be exactly 16 bytes");
+        }
+        
+        return compose(bytes).toString();
+    }
+}



Mime
View raw message