3 new revisions:

Revision: 1654b3cecbbd
Author:   Rick Shaw <wfs...@gmail.com>
Date:     Sat Mar 24 18:43:56 2012
Log:      Provide better support for getMetadata() method by tool clients...
http://code.google.com/a/apache-extras.org/p/cassandra-jdbc/source/detail?r=1654b3cecbbd

Revision: a3b4b0e22060
Author:   Rick Shaw <wfs...@gmail.com>
Date:     Sat Mar 24 18:45:40 2012
Log:      Add a more robust set of ignore file entries
http://code.google.com/a/apache-extras.org/p/cassandra-jdbc/source/detail?r=a3b4b0e22060

Revision: 0ef9c5a9a4af
Author:   Rick Shaw <wfs...@gmail.com>
Date:     Sat Mar 24 18:58:09 2012
Log:      Change C* dependencies to 1.1.0-beta1
http://code.google.com/a/apache-extras.org/p/cassandra-jdbc/source/detail?r=0ef9c5a9a4af

==============================================================================
Revision: 1654b3cecbbd
Author:   Rick Shaw <wfs...@gmail.com>
Date:     Sat Mar 24 18:43:56 2012
Log:      Provide better support for getMetadata() method by tool clients

* Rename the rSetIter iterator to rowIterator.

* Rewrite next() method of CassandraResultSet to simplify and
  abstract out the column initialization routine.

* Initialize the metadata with values from first row to improve
  compatibility with other Relational JDBC implementations.
  NOTE: this approach will fail if all accessed rows are not
        the same.
  NOTE: the row pointer is still left pointing BEFORE the first row.


http://code.google.com/a/apache-extras.org/p/cassandra-jdbc/source/detail?r=1654b3cecbbd

Modified:
 /src/main/java/org/apache/cassandra/cql/jdbc/CassandraResultSet.java
 /src/test/java/org/apache/cassandra/cql/jdbc/JdbcRegressionTest.java

=======================================
--- /src/main/java/org/apache/cassandra/cql/jdbc/CassandraResultSet.java Wed Dec 21 21:16:09 2011 +++ /src/main/java/org/apache/cassandra/cql/jdbc/CassandraResultSet.java Sat Mar 24 18:43:56 2012
@@ -66,9 +66,9 @@
     private final String keyspace;

     /**
-     * The r set iter.
+     * The rows iterator.
      */
-    private Iterator<CqlRow> rSetIter;
+    private Iterator<CqlRow> rowsIterator;

     int rowNumber = 0;
     // the current row key when iterating through results.
@@ -79,11 +79,6 @@
      */
     private List<TypedColumn> values = new ArrayList<TypedColumn>();

-    /**
-     * The value map.
-     */
- private Map<String, TypedColumn> valueMap = new HashMap<String, TypedColumn>();
-
     /**
      * The index map.
      */
@@ -125,10 +120,46 @@
         this.fetchSize = statement.getFetchSize();
         this.schema = resultSet.schema;

-        rSetIter = resultSet.getRowsIterator();
+        rowsIterator = resultSet.getRowsIterator();
+
+        // Initialize to column values from the first row
+ // NOTE: that the first call to next() will HARMLESSLY re-write these values for the columns + // NOTE: the row cursor is not advanced and sits before the first row
+        if (hasMoreRows())
+        {
+            populateColumns();
+            // reset the iterator back to the beginning.
+            rowsIterator = resultSet.getRowsIterator();
+        }
+
         meta = new CResultSetMetaData();
     }
-
+
+    private final boolean hasMoreRows()
+    {
+        return (rowsIterator !=null && rowsIterator.hasNext());
+    }
+
+    private final void populateColumns()
+    {
+        // clear column value tables
+        values.clear();
+        indexMap.clear();
+
+        CqlRow row = rowsIterator.next();
+        curRowKey = row.getKey();
+        List<Column> cols = row.getColumns();
+
+        // loop through the columns
+        for (Column col : cols)
+        {
+            TypedColumn c = createColumn(col);
+            String columnName = c.getNameString();
+            values.add(c);
+ indexMap.put(columnName, values.size()); // one greater than 0 based index of a list
+        }
+    }
+
     public boolean absolute(int arg0) throws SQLException
     {
         throw new SQLFeatureNotSupportedException(NOT_SUPPORTED);
@@ -153,7 +184,7 @@

     private final void checkName(String name) throws SQLException
     {
- if (valueMap.get(name) == null) throw new SQLSyntaxErrorException(String.format(VALID_LABELS, name)); + if (indexMap.get(name) == null) throw new SQLSyntaxErrorException(String.format(VALID_LABELS, name));
     }

     private final void checkNotClosed() throws SQLException
@@ -170,7 +201,7 @@

     public void close() throws SQLException
     {
-        valueMap = null;
+        indexMap = null;
         values = null;
     }

@@ -203,14 +234,14 @@
     public BigDecimal getBigDecimal(String name) throws SQLException
     {
         checkName(name);
-        return getBigDecimal(valueMap.get(name));
+        return getBigDecimal(indexMap.get(name).intValue());
     }

     /** @deprecated */
public BigDecimal getBigDecimal(String name, int scale) throws SQLException
     {
         checkName(name);
-        return (getBigDecimal(valueMap.get(name))).setScale(scale);
+ return (getBigDecimal(indexMap.get(name).intValue())).setScale(scale);
     }

private BigDecimal getBigDecimal(TypedColumn column) throws SQLException
@@ -249,7 +280,7 @@
     public BigInteger getBigInteger(String name) throws SQLException
     {
         checkName(name);
-        return getBigInteger(valueMap.get(name));
+        return getBigInteger(indexMap.get(name).intValue());
     }

private BigInteger getBigInteger(TypedColumn column) throws SQLException
@@ -287,7 +318,7 @@
     public boolean getBoolean(String name) throws SQLException
     {
         checkName(name);
-        return getBoolean(valueMap.get(name));
+        return getBoolean(indexMap.get(name).intValue());
     }

private final Boolean getBoolean(TypedColumn column) throws SQLException
@@ -327,7 +358,7 @@
     public byte getByte(String name) throws SQLException
     {
         checkName(name);
-        return getByte(valueMap.get(name));
+        return getByte(indexMap.get(name).intValue());
     }

     private final Byte getByte(TypedColumn column) throws SQLException
@@ -363,7 +394,7 @@

     public byte[] getBytes(String name) throws SQLException
     {
-        return getBytes(valueMap.get(name));
+        return getBytes(indexMap.get(name).intValue());
     }

     private byte[] getBytes(TypedColumn column) throws SQLException
@@ -385,7 +416,7 @@
     {
         checkName(name);
         checkNotClosed();
-        return valueMap.get(name);
+        return values.get(indexMap.get(name).intValue());
     }

     public int getConcurrency() throws SQLException
@@ -410,7 +441,7 @@
     public Date getDate(String name) throws SQLException
     {
         checkName(name);
-        return getDate(valueMap.get(name));
+        return getDate(indexMap.get(name).intValue());
     }

     public Date getDate(String name, Calendar calendar) throws SQLException
@@ -453,7 +484,7 @@
     public double getDouble(String name) throws SQLException
     {
         checkName(name);
-        return getDouble(valueMap.get(name));
+        return getDouble(indexMap.get(name).intValue());
     }

     private final Double getDouble(TypedColumn column) throws SQLException
@@ -507,7 +538,7 @@
     public float getFloat(String name) throws SQLException
     {
         checkName(name);
-        return getFloat(valueMap.get(name));
+        return getFloat(indexMap.get(name).intValue());
     }

     private final Float getFloat(TypedColumn column) throws SQLException
@@ -555,7 +586,7 @@
     public int getInt(String name) throws SQLException
     {
         checkName(name);
-        return getInt(valueMap.get(name));
+        return getInt(indexMap.get(name).intValue());
     }

     private int getInt(TypedColumn column) throws SQLException
@@ -598,7 +629,7 @@
     public long getLong(String name) throws SQLException
     {
         checkName(name);
-        return getLong(valueMap.get(name));
+        return getLong(indexMap.get(name).intValue());
     }

     private Long getLong(TypedColumn column) throws SQLException
@@ -644,7 +675,7 @@
     public Object getObject(String name) throws SQLException
     {
         checkName(name);
-        return getObject(valueMap.get(name));
+        return getObject(indexMap.get(name).intValue());
     }


@@ -671,7 +702,7 @@
     public RowId getRowId(String name) throws SQLException
     {
         checkName(name);
-        return getRowId(valueMap.get(name));
+        return getRowId(indexMap.get(name).intValue());
     }

     private final RowId getRowId(TypedColumn column) throws SQLException
@@ -691,7 +722,7 @@
     public short getShort(String name) throws SQLException
     {
         checkName(name);
-        return getShort(valueMap.get(name));
+        return getShort(indexMap.get(name).intValue());
     }

     private final Short getShort(TypedColumn column) throws SQLException
@@ -735,7 +766,7 @@
     public String getString(String name) throws SQLException
     {
         checkName(name);
-        return getString(valueMap.get(name));
+        return getString(indexMap.get(name).intValue());
     }

     private String getString(TypedColumn column) throws SQLException
@@ -762,7 +793,7 @@
     public Time getTime(String name) throws SQLException
     {
         checkName(name);
-        return getTime(valueMap.get(name));
+        return getTime(indexMap.get(name).intValue());
     }

     public Time getTime(String name, Calendar calendar) throws SQLException
@@ -812,7 +843,7 @@
     public Timestamp getTimestamp(String name) throws SQLException
     {
         checkName(name);
-        return getTimestamp(valueMap.get(name));
+        return getTimestamp(indexMap.get(name).intValue());
     }

public Timestamp getTimestamp(String name, Calendar calendar) throws SQLException
@@ -889,7 +920,7 @@

     public boolean isClosed() throws SQLException
     {
-        return valueMap == null;
+        return values == null;
     }

     public boolean isFirst() throws SQLException
@@ -901,7 +932,7 @@
     public boolean isLast() throws SQLException
     {
         checkNotClosed();
-        return !rSetIter.hasNext();
+        return !rowsIterator.hasNext();
     }

     public boolean isWrapperFor(Class<?> iface) throws SQLException
@@ -919,26 +950,11 @@

     public synchronized boolean next() throws SQLException
     {
-        if (!values.isEmpty() || !valueMap.isEmpty())
-        {
-            values.clear();
-            valueMap.clear();
-        }
-        if (rSetIter != null && rSetIter.hasNext())
-        {
-            CqlRow row = rSetIter.next();
+        if (hasMoreRows())
+        {
+            populateColumns();
             rowNumber++;
-            curRowKey = row.getKey();
-            List<Column> cols = row.getColumns();
-            for (Column col : cols)
-            {
-                TypedColumn c = createColumn(col);
-                String columnName = c.getNameString();
-                values.add(c);
- indexMap.put(columnName, values.size()); // one greater than 0 based index of a list
-                valueMap.put(columnName, c);
-            }
-            return !(values.isEmpty() || valueMap.isEmpty());
+            return true;
         }
         else
         {
=======================================
--- /src/test/java/org/apache/cassandra/cql/jdbc/JdbcRegressionTest.java Tue Feb 7 13:58:37 2012 +++ /src/test/java/org/apache/cassandra/cql/jdbc/JdbcRegressionTest.java Sat Mar 24 18:43:56 2012
@@ -25,6 +25,8 @@
 import java.sql.DriverManager;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
 import java.sql.Statement;

 import org.apache.cassandra.cql.ConnectionDetails;
@@ -128,5 +130,59 @@
 //        con.close();

     }
-
-}
+    @Test
+    public void testIssue18() throws Exception
+    {
+       Statement statement = con.createStatement();
+
+       String truncate = "TRUNCATE RegressionTest;";
+       statement.execute(truncate);
+
+ String insert1 = "INSERT INTO RegressionTest (keyname,bValue,iValue) VALUES( 'key0',true, 2000);";
+       statement.executeUpdate(insert1);
+
+ String insert2 = "INSERT INTO RegressionTest (keyname,bValue) VALUES( 'key1',false);";
+       statement.executeUpdate(insert2);
+
+
+
+       String select = "SELECT * from RegressionTest;";
+
+       ResultSet result = statement.executeQuery(select);
+
+       ResultSetMetaData metadata = result.getMetaData();
+
+       int colCount = metadata.getColumnCount();
+
+       System.out.println("Before doing a next()");
+       System.out.printf("(%d) ",result.getRow());
+       for (int i = 1; i <= colCount; i++)
+       {
+           System.out.print(showColumn(i,result)+ " ");
+       }
+       System.out.println();
+
+
+       System.out.println("Fetching each row with a next()");
+       while (result.next())
+       {
+           metadata = result.getMetaData();
+           colCount = metadata.getColumnCount();
+           System.out.printf("(%d) ",result.getRow());
+           for (int i = 1; i <= colCount; i++)
+           {
+               System.out.print(showColumn(i,result)+ " ");
+           }
+           System.out.println();
+       }
+    }
+
+
+ private final String showColumn(int index, ResultSet result) throws SQLException
+    {
+        StringBuilder sb = new StringBuilder();
+        sb.append("[").append(index).append("]");
+        sb.append(result.getObject(index));
+        return sb.toString();
+    }
+}

==============================================================================
Revision: a3b4b0e22060
Author:   Rick Shaw <wfs...@gmail.com>
Date:     Sat Mar 24 18:45:40 2012
Log:      Add a more robust set of ignore file entries
http://code.google.com/a/apache-extras.org/p/cassandra-jdbc/source/detail?r=a3b4b0e22060

Modified:
 /.gitignore

=======================================
--- /.gitignore Thu Oct 13 01:56:25 2011
+++ /.gitignore Sat Mar 24 18:45:40 2012
@@ -1,9 +1,36 @@
-*~
-.classpath
+# Eclipse meta-information
 .project
+.classpath
 .settings
+
+# IDEA meeta-information
 .idea
 *.iml
 *.ipr
 *.iws
-target
+
+# Build directory
+target/
+build/
+bin/
+
+# SVN
+.svn
+
+# Gradle files
+.gradle
+
+# Backup files
+*~
+
+# Misc hidden files
+.DS_Store
+
+# class files
+*.class
+
+# create an empty .gitignore file when you want to track an empty
+# directory but want to ignore its content. Example: to keep the
+# "logs" dir do: "touch logs/.gitignore"
+#
+!.gitignore

==============================================================================
Revision: 0ef9c5a9a4af
Author:   Rick Shaw <wfs...@gmail.com>
Date:     Sat Mar 24 18:58:09 2012
Log:      Change C* dependencies to 1.1.0-beta1
http://code.google.com/a/apache-extras.org/p/cassandra-jdbc/source/detail?r=0ef9c5a9a4af

Modified:
 /pom.xml

=======================================
--- /pom.xml    Thu Feb  2 07:47:12 2012
+++ /pom.xml    Sat Mar 24 18:58:09 2012
@@ -70,6 +70,13 @@
       <id>jbellis</id>
       <name>Jonathan Ellis</name>
       <roles>
+        <role>developer</role>
+      </roles>
+    </developer>
+    <developer>
+      <id>rickshaw</id>
+      <name>Rick Shaw</name>
+      <roles>
         <role>developer</role>
       </roles>
     </developer>
@@ -96,9 +103,14 @@

   <dependencies>
     <dependency>
+      <groupId>org.apache.cassandra</groupId>
+      <artifactId>cassandra-clientutil</artifactId>
+      <version>1.1.0-beta1</version>
+    </dependency>
+    <dependency>
       <groupId>org.apache.cassandra</groupId>
       <artifactId>cassandra-thrift</artifactId>
-      <version>1.1-dev-SNAPSHOT</version>
+      <version>1.1.0-beta1</version>
       <exclusions>
         <exclusion>
           <groupId>javax.servlet</groupId>
@@ -111,16 +123,6 @@
       </exclusions>
     </dependency>
     <dependency>
-      <groupId>org.apache.cassandra</groupId>
-      <artifactId>cassandra-clientutil</artifactId>
-      <version>1.1-dev-SNAPSHOT</version>
-    </dependency>
-    <dependency>
-      <groupId>com.google.guava</groupId>
-      <artifactId>guava</artifactId>
-      <version>r08</version>
-    </dependency>
-    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>4.6</version>
@@ -132,11 +134,6 @@
       <version>1.6.1</version>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.apache.thrift</groupId>
-      <artifactId>libthrift</artifactId>
-      <version>0.7.0</version>
-    </dependency>
   </dependencies>

   <build>

Reply via email to