cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1100886 - in /cassandra/branches/cassandra-0.8/drivers/java/src/org/apache/cassandra/cql/jdbc: CResultSet.java CassandraPreparedStatement.java ColumnDecoder.java
Date Mon, 09 May 2011 04:44:44 GMT
Author: jbellis
Date: Mon May  9 04:44:44 2011
New Revision: 1100886

URL: http://svn.apache.org/viewvc?rev=1100886&view=rev
Log:
break out ColumnDecoder getNameType, getValueType
patch by jbellis

Modified:
    cassandra/branches/cassandra-0.8/drivers/java/src/org/apache/cassandra/cql/jdbc/CResultSet.java
    cassandra/branches/cassandra-0.8/drivers/java/src/org/apache/cassandra/cql/jdbc/CassandraPreparedStatement.java
    cassandra/branches/cassandra-0.8/drivers/java/src/org/apache/cassandra/cql/jdbc/ColumnDecoder.java

Modified: cassandra/branches/cassandra-0.8/drivers/java/src/org/apache/cassandra/cql/jdbc/CResultSet.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/drivers/java/src/org/apache/cassandra/cql/jdbc/CResultSet.java?rev=1100886&r1=1100885&r2=1100886&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/drivers/java/src/org/apache/cassandra/cql/jdbc/CResultSet.java
(original)
+++ cassandra/branches/cassandra-0.8/drivers/java/src/org/apache/cassandra/cql/jdbc/CResultSet.java
Mon May  9 04:44:44 2011
@@ -375,7 +375,7 @@ public class CResultSet extends Abstract
 
                 TypedColumn c = decoder.makeCol(keyspace, columnFamily, col);
                 values.add(c);
-                valueMap.put(decoder.colNameAsString(keyspace, columnFamily, col.getName()),
c);
+                valueMap.put(decoder.colNameAsString(keyspace, columnFamily, col.name), c);
             }
             return !(values.isEmpty() && valueMap.isEmpty());
         } 

Modified: cassandra/branches/cassandra-0.8/drivers/java/src/org/apache/cassandra/cql/jdbc/CassandraPreparedStatement.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/drivers/java/src/org/apache/cassandra/cql/jdbc/CassandraPreparedStatement.java?rev=1100886&r1=1100885&r2=1100886&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/drivers/java/src/org/apache/cassandra/cql/jdbc/CassandraPreparedStatement.java
(original)
+++ cassandra/branches/cassandra-0.8/drivers/java/src/org/apache/cassandra/cql/jdbc/CassandraPreparedStatement.java
Mon May  9 04:44:44 2011
@@ -180,7 +180,7 @@ public class CassandraPreparedStatement 
         String columnFamily = connection.getColumnFamily(cql);
         ParameterIterator params = new ParameterIterator();
         String left = cql.substring(0, pivot);
-        AbstractType leftType = connection.decoder.getComparator(keyspace, columnFamily,
ColumnDecoder.Specifier.Comparator, null);
+        AbstractType leftType = connection.decoder.getComparator(keyspace, columnFamily);
         if (leftType == null)
             throw new SQLException("Could not find comparator for " + keyspace + "." + columnFamily);
         left = applySimpleBindings(left, leftType, params);
@@ -199,7 +199,7 @@ public class CassandraPreparedStatement 
         String columnFamily = connection.getColumnFamily(cql);
         ParameterIterator params = new ParameterIterator();
         String left = cql.substring(0, pivot);
-        AbstractType leftType = connection.decoder.getComparator(keyspace, columnFamily,
ColumnDecoder.Specifier.Comparator, null);
+        AbstractType leftType = connection.decoder.getComparator(keyspace, columnFamily);
         if (leftType == null)
             throw new SQLException("Could not find comparator for " + keyspace + "." + columnFamily);
         left = applySimpleBindings(left, leftType, params);
@@ -220,10 +220,10 @@ public class CassandraPreparedStatement 
         String columnFamily = connection.getColumnFamily(cql);
         ParameterIterator params = new ParameterIterator();
         String left = cql.substring(0, pivot);
-        AbstractType leftComp = connection.decoder.getComparator(keyspace, columnFamily,
ColumnDecoder.Specifier.Comparator, null);
+        AbstractType leftComp = connection.decoder.getComparator(keyspace, columnFamily);
         if (leftComp == null)
             throw new SQLException("Could not find comparator for " + keyspace + "." + columnFamily);
-        AbstractType leftVald = connection.decoder.getComparator(keyspace, columnFamily,
ColumnDecoder.Specifier.Validator, null);
+        AbstractType leftVald = connection.decoder.getComparator(keyspace, columnFamily);
         if (leftVald == null)
             throw new SQLException("Could not find validator for " + keyspace + "." + columnFamily);
         left = applyDualBindings(left, leftComp, leftVald, params);

Modified: cassandra/branches/cassandra-0.8/drivers/java/src/org/apache/cassandra/cql/jdbc/ColumnDecoder.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/drivers/java/src/org/apache/cassandra/cql/jdbc/ColumnDecoder.java?rev=1100886&r1=1100885&r2=1100886&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/drivers/java/src/org/apache/cassandra/cql/jdbc/ColumnDecoder.java
(original)
+++ cassandra/branches/cassandra-0.8/drivers/java/src/org/apache/cassandra/cql/jdbc/ColumnDecoder.java
Mon May  9 04:44:44 2011
@@ -22,6 +22,7 @@ package org.apache.cassandra.cql.jdbc;
 
 
 import org.apache.cassandra.config.CFMetaData;
+import org.apache.cassandra.config.ColumnDefinition;
 import org.apache.cassandra.config.ConfigurationException;
 import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.thrift.*;
@@ -43,15 +44,7 @@ class ColumnDecoder
 {
     private static final Logger logger = LoggerFactory.getLogger(ColumnDecoder.class);
 
-    // basically denotes column or value.
-    enum Specifier
-    {
-        Comparator,
-        Validator,
-        ColumnSpecific
-    }
-
-    private Map<String, CFMetaData> metadata = new HashMap<String, CFMetaData>();
+    private final Map<String, CFMetaData> metadata = new HashMap<String, CFMetaData>();
 
     /**
      * is specific per set of keyspace definitions.
@@ -78,67 +71,42 @@ class ColumnDecoder
         }
     }
 
-    /**
-     * @param keyspace     ALWAYS specify
-     * @param columnFamily ALWAYS specify
-     * @param specifier    ALWAYS specify
-     * @param def          avoids additional map lookup if specified. null is ok though.
-     * @return
-     */
-    AbstractType getComparator(String keyspace, String columnFamily, Specifier specifier,
CFMetaData def)
+    AbstractType getComparator(String keyspace, String columnFamily)
     {
-        return getComparator(keyspace, columnFamily, null, specifier, def);
+        return metadata.get(String.format("%s.%s", keyspace, columnFamily)).comparator;
     }
 
-    // same as above, but can get column-specific validators.
-    AbstractType getComparator(String keyspace, String columnFamily, byte[] column, Specifier
specifier, CFMetaData def)
+    AbstractType getNameType(String keyspace, String columnFamily, ByteBuffer name)
     {
-        if (def == null)
-            def = metadata.get(String.format("%s.%s", keyspace, columnFamily));
-        if (def == null)
-            // no point in proceeding. these values are bad.
-            throw new AssertionError();
-        switch (specifier)
-        {
-            case ColumnSpecific:
-                return def.getValueValidator(ByteBuffer.wrap(column));
-            case Validator:
-                return def.getDefaultValidator();
-            case Comparator:
-                return def.comparator;
-            default:
-                throw new AssertionError();
-        }
+
+        CFMetaData md = metadata.get(String.format("%s.%s", keyspace, columnFamily));
+        return md.comparator;
     }
 
-    /**
-     * uses the AbstractType to map a column name to a string.
-     *
-     * @param keyspace
-     * @param columnFamily
-     * @param name
-     * @return
-     */
-    public String colNameAsString(String keyspace, String columnFamily, byte[] name)
+    AbstractType getValueType(String keyspace, String columnFamily, ByteBuffer name)
     {
-        AbstractType comparator = getComparator(keyspace, columnFamily, Specifier.Comparator,
null);
-        return comparator.getString(ByteBuffer.wrap(name));
+        CFMetaData md = metadata.get(String.format("%s.%s", keyspace, columnFamily));
+        ColumnDefinition cd = md.getColumnDefinition(name);
+        return cd == null ? md.getDefaultValidator() : cd.getValidator();
     }
 
-    /**
-     * constructs a typed column
-     */
-    public TypedColumn makeCol(String keyspace, String columnFamily, Column column)
+    public AbstractType getKeyValidator(String keyspace, String columnFamily)
     {
-        CFMetaData cfDef = metadata.get(String.format("%s.%s", keyspace, columnFamily));
-        AbstractType comparator = getComparator(keyspace, columnFamily, Specifier.Comparator,
cfDef);
-        AbstractType validator = getComparator(keyspace, columnFamily, column.getName(),
Specifier.ColumnSpecific, null);
-        return new TypedColumn(column, comparator, validator);
+        return metadata.get(String.format("%s.%s", keyspace, columnFamily)).getKeyValidator();
     }
 
-    public AbstractType getKeyValidator(String keyspace, String columnFamily)
+    /** uses the AbstractType to map a column name to a string. */
+    public String colNameAsString(String keyspace, String columnFamily, ByteBuffer name)
+    {
+        AbstractType comparator = getNameType(keyspace, columnFamily, name);
+        return comparator.getString(name);
+    }
+
+    /** constructs a typed column */
+    public TypedColumn makeCol(String keyspace, String columnFamily, Column column)
     {
-        CFMetaData def = metadata.get(String.format("%s.%s", keyspace, columnFamily));
-        return def.getKeyValidator();
+        return new TypedColumn(column,
+                               getNameType(keyspace, columnFamily, column.name),
+                               getValueType(keyspace, columnFamily, column.name));
     }
 }



Mime
View raw message