cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdusba...@apache.org
Subject svn commit: r1081543 - in /cassandra/trunk/drivers/java: src/org/apache/cassandra/cql/jdbc/ test/org/apache/cassandra/cql/
Date Mon, 14 Mar 2011 19:46:42 GMT
Author: gdusbabek
Date: Mon Mar 14 19:46:42 2011
New Revision: 1081543

URL: http://svn.apache.org/viewvc?rev=1081543&view=rev
Log:
make RowMetaData typed

Modified:
    cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/CassandraResultSet.java
    cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/RowMetaData.java
    cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/TypedColumn.java
    cassandra/trunk/drivers/java/test/org/apache/cassandra/cql/JdbcDriverTest.java

Modified: cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/CassandraResultSet.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/CassandraResultSet.java?rev=1081543&r1=1081542&r2=1081543&view=diff
==============================================================================
--- cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/CassandraResultSet.java
(original)
+++ cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/CassandraResultSet.java
Mon Mar 14 19:46:42 2011
@@ -55,7 +55,7 @@ import org.apache.cassandra.thrift.CqlRo
 /**
  * The Class CassandraResultSet.
  */
-class CassandraResultSet implements ResultSet
+class CassandraResultSet<N, V> implements ResultSet
 {
     
     /** The r set. */
@@ -72,7 +72,7 @@ class CassandraResultSet implements Resu
     private byte[] curRowKey = null;
     
     /** The values. */
-    private List<TypedColumn> values = new ArrayList<TypedColumn>();
+    private List<TypedColumn<N, V>> values = new ArrayList<TypedColumn<N,
V>>();
     
     /** The value map. */
     private Map<String, Object> valueMap = new WeakHashMap<String, Object>();
@@ -2000,13 +2000,18 @@ class CassandraResultSet implements Resu
         throw new UnsupportedOperationException("method not supported");
     }
 
-    private class CassandraRowMetaData implements RowMetaData
+    private class CassandraRowMetaData<N, V> implements RowMetaData<N, V>
     {
-        private final List<TypedColumn> cols;
+        private final List<TypedColumn<N, V>> cols;
         private final byte[] key;
+        private final Class colClass;
+        private final Class valClass;
         
         private CassandraRowMetaData(CassandraResultSet rs) {
-            cols = new ArrayList<TypedColumn>(rs.values);
+            cols = new ArrayList<TypedColumn<N, V>>(rs.values);
+            assert rs.values.size() > 0;
+            colClass = rs.values.get(0).getClass();
+            valClass = rs.values.get(0).getClass();
             key = curRowKey;
         }
 
@@ -2015,6 +2020,26 @@ class CassandraResultSet implements Resu
             return cols.size();
         }
 
+        public N getColumnName(int index)
+        {
+            return cols.get(index).getName();
+        }
+
+        public V getColumnValue(int index)
+        {
+            return cols.get(index).getValue();
+        }
+
+        public Class getColumnNameClass()
+        {
+            return colClass;
+        }
+
+        public Class getColumnValueClass()
+        {
+            return valClass;
+        }
+
         public TypedColumn getColumn(int index)
         {
             return cols.get(index);

Modified: cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/RowMetaData.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/RowMetaData.java?rev=1081543&r1=1081542&r2=1081543&view=diff
==============================================================================
--- cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/RowMetaData.java (original)
+++ cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/RowMetaData.java Mon Mar
14 19:46:42 2011
@@ -8,13 +8,20 @@ package org.apache.cassandra.cql.jdbc;
  * methods for both column names and values a la ResultSetMetaData.  If we did want that,
I recommend an optional
  * method in AbstractType called getSqlType() or something like that.
  */
-public interface RowMetaData
+public interface RowMetaData<N, V>
 {
     /** number of columns in a row of data */
     public int getColumnCount();
     
-    /** column name and value */
-    public TypedColumn getColumn(int index);
+    /** get typed column name */
+    public N getColumnName(int index);
+    
+    /** get typed column value */
+    public V getColumnValue(int index);
+    
+    public Class<N> getColumnNameClass();
+    
+    public Class<V> getColumnValueClass();
     
     /** key */
     public byte[] getKey(); // todo: update when typed keys are available.

Modified: cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/TypedColumn.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/TypedColumn.java?rev=1081543&r1=1081542&r2=1081543&view=diff
==============================================================================
--- cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/TypedColumn.java (original)
+++ cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/TypedColumn.java Mon Mar
14 19:46:42 2011
@@ -1,6 +1,6 @@
 package org.apache.cassandra.cql.jdbc;
 
-public class TypedColumn<N, V>
+class TypedColumn<N, V>
 {
     public final N name;
     public final V value;

Modified: cassandra/trunk/drivers/java/test/org/apache/cassandra/cql/JdbcDriverTest.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/drivers/java/test/org/apache/cassandra/cql/JdbcDriverTest.java?rev=1081543&r1=1081542&r2=1081543&view=diff
==============================================================================
--- cassandra/trunk/drivers/java/test/org/apache/cassandra/cql/JdbcDriverTest.java (original)
+++ cassandra/trunk/drivers/java/test/org/apache/cassandra/cql/JdbcDriverTest.java Mon Mar
14 19:46:42 2011
@@ -80,12 +80,12 @@ public class JdbcDriverTest extends Embe
         assert rs.next();
         assert rs.getInt("1") == 111;
         assert rs.getInt("2") == 222;
-        RowMetaData rd = rs.unwrap(RowMetaData.class);
+        RowMetaData<BigInteger, BigInteger> rd = rs.unwrap(RowMetaData.class);
         assert rd.getColumnCount() == 2;
-        assert rd.getColumn(0).getName().equals(new BigInteger("1"));
-        assert rd.getColumn(0).getValue().equals(new BigInteger("111"));
-        assert rd.getColumn(1).getName().equals(new BigInteger("2"));
-        assert rd.getColumn(1).getValue().equals(new BigInteger("222"));
+        assert rd.getColumnName(0).equals(new BigInteger("1"));
+        assert rd.getColumnValue(0).equals(new BigInteger("111"));
+        assert rd.getColumnName(1).equals(new BigInteger("2"));
+        assert rd.getColumnValue(1).equals(new BigInteger("222"));
     }
     
     @Test
@@ -97,16 +97,16 @@ public class JdbcDriverTest extends Embe
         assert rs.next();
         assert rs.getLong("1") == 111;
         assert rs.getLong("2") == 222;
-        RowMetaData rd = rs.unwrap(RowMetaData.class);
+        RowMetaData<Long, Long> rd = rs.unwrap(RowMetaData.class);
         assert rd.getColumnCount() == 2;
-        assert rd.getColumn(0).getName().equals(new Long("1"));
-        assert rd.getColumn(0).getValue().equals(new Long("111"));
-        assert rd.getColumn(1).getName().equals(new Long("2"));
-        assert rd.getColumn(1).getValue().equals(new Long("222"));
-        assert (Long)rd.getColumn(0).getName() == 1L;
-        assert (Long)rd.getColumn(0).getValue() == 111L;
-        assert (Long)rd.getColumn(1).getName() == 2L;
-        assert (Long)rd.getColumn(1).getValue() == 222L;
+        assert rd.getColumnName(0).equals(new Long("1"));
+        assert rd.getColumnValue(0).equals(new Long("111"));
+        assert rd.getColumnName(1).equals(new Long("2"));
+        assert rd.getColumnValue(1).equals(new Long("222"));
+        assert rd.getColumnName(0) == 1L;
+        assert rd.getColumnValue(0) == 111L;
+        assert rd.getColumnName(1) == 2L;
+        assert rd.getColumnValue(1) == 222L;
     }
     
     @Test
@@ -122,12 +122,12 @@ public class JdbcDriverTest extends Embe
             assert rs.next();
             assert rs.getString("a").equals("aa");
             assert rs.getString("b").equals("bb");
-            RowMetaData rd = rs.unwrap(RowMetaData.class);
+            RowMetaData<String, String> rd = rs.unwrap(RowMetaData.class);
             assert rd.getColumnCount() == 2;
-            assert rd.getColumn(0).getName().equals("a");
-            assert rd.getColumn(0).getValue().equals("aa");
-            assert rd.getColumn(1).getName().equals("b");
-            assert rd.getColumn(1).getValue().equals("bb");
+            assert rd.getColumnName(0).equals("a");
+            assert rd.getColumnValue(0).equals("aa");
+            assert rd.getColumnName(1).equals("b");
+            assert rd.getColumnValue(1).equals("bb");
         }
     }
     
@@ -154,11 +154,11 @@ public class JdbcDriverTest extends Embe
         assert Arrays.equals(bb, rs.getBytes(1));
         assert Arrays.equals(aa, rs.getBytes(FBUtilities.bytesToHex(a)));
         assert Arrays.equals(bb, rs.getBytes(FBUtilities.bytesToHex(b)));
-        RowMetaData rd = rs.unwrap(RowMetaData.class);
-        assert rd.getColumn(0).getName().equals(ByteBuffer.wrap(a));
-        assert rd.getColumn(1).getName().equals(ByteBuffer.wrap(b));
-        assert rd.getColumn(0).getValue().equals(ByteBuffer.wrap(aa));
-        assert rd.getColumn(1).getValue().equals(ByteBuffer.wrap(bb));
+        RowMetaData<ByteBuffer, ByteBuffer> rd = rs.unwrap(RowMetaData.class);
+        assert rd.getColumnName(0).equals(ByteBuffer.wrap(a));
+        assert rd.getColumnName(1).equals(ByteBuffer.wrap(b));
+        assert rd.getColumnValue(0).equals(ByteBuffer.wrap(aa));
+        assert rd.getColumnValue(1).equals(ByteBuffer.wrap(bb));
     }
     
     /** Method to test statement. */



Mime
View raw message