Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

tagging 1.0.3 of Java CQL driver

git-svn-id: https://svn.apache.org/repos/asf/cassandra/tags/drivers@1130850 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit 20635cec24389d83b146af51fa902fcf2d21491b 1 parent 4a1ca8f
Eric Evans authored
Showing with 4,992 additions and 0 deletions.
  1. +761 −0 java/1.0.3/src/org/apache/cassandra/cql/jdbc/AbstractResultSet.java
  2. +560 −0 java/1.0.3/src/org/apache/cassandra/cql/jdbc/CResultSet.java
  3. +658 −0 java/1.0.3/src/org/apache/cassandra/cql/jdbc/CassandraConnection.java
  4. +134 −0 java/1.0.3/src/org/apache/cassandra/cql/jdbc/CassandraDriver.java
  5. +551 −0 java/1.0.3/src/org/apache/cassandra/cql/jdbc/CassandraPreparedStatement.java
  6. +43 −0 java/1.0.3/src/org/apache/cassandra/cql/jdbc/CassandraResultSet.java
  7. +594 −0 java/1.0.3/src/org/apache/cassandra/cql/jdbc/CassandraStatement.java
  8. +131 −0 java/1.0.3/src/org/apache/cassandra/cql/jdbc/ColumnDecoder.java
  9. +202 −0 java/1.0.3/src/org/apache/cassandra/cql/jdbc/Connection.java
  10. +176 −0 java/1.0.3/src/org/apache/cassandra/cql/jdbc/ConnectionPool.java
  11. +39 −0 java/1.0.3/src/org/apache/cassandra/cql/jdbc/DriverResolverException.java
  12. +41 −0 java/1.0.3/src/org/apache/cassandra/cql/jdbc/InvalidUrlException.java
  13. +78 −0 java/1.0.3/src/org/apache/cassandra/cql/jdbc/TypedColumn.java
  14. +66 −0 java/1.0.3/src/org/apache/cassandra/cql/jdbc/Utils.java
  15. +106 −0 java/1.0.3/test/org/apache/cassandra/cql/EmbeddedServiceBase.java
  16. +468 −0 java/1.0.3/test/org/apache/cassandra/cql/JdbcDriverTest.java
  17. +384 −0 java/1.0.3/test/org/apache/cassandra/cql/jdbc/PreparedStatementTest.java
View
761 java/1.0.3/src/org/apache/cassandra/cql/jdbc/AbstractResultSet.java
@@ -0,0 +1,761 @@
+package org.apache.cassandra.cql.jdbc;
+/*
+ *
+ * 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.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.sql.*;
+
+/** a class to hold all the unimplemented crap */
+class AbstractResultSet
+{
+ public boolean absolute(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void afterLast() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void beforeFirst() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void cancelRowUpdates() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void clearWarnings() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void deleteRow() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public int findColumn(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public boolean first() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Array getArray(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Array getArray(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public InputStream getAsciiStream(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public InputStream getAsciiStream(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public InputStream getBinaryStream(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public InputStream getBinaryStream(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Blob getBlob(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Blob getBlob(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public byte getByte(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public byte getByte(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Reader getCharacterStream(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Reader getCharacterStream(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Clob getClob(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Clob getClob(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public int getConcurrency() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public String getCursorName() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public int getFetchDirection() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public int getFetchSize() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public int getHoldability() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Ref getRef(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Ref getRef(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public RowId getRowId(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public RowId getRowId(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public SQLXML getSQLXML(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public SQLXML getSQLXML(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public short getShort(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public short getShort(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Statement getStatement() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public URL getURL(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public URL getURL(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public InputStream getUnicodeStream(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public InputStream getUnicodeStream(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public SQLWarning getWarnings() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void insertRow() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void moveToCurrentRow() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void moveToInsertRow() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public boolean previous() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void refreshRow() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public boolean relative(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public boolean rowDeleted() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public boolean rowInserted() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public boolean rowUpdated() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void setFetchDirection(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void setFetchSize(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Reader getNCharacterStream(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Reader getNCharacterStream(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public NClob getNClob(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public NClob getNClob(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public String getNString(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public String getNString(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public BigDecimal getBigDecimal(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public BigDecimal getBigDecimal(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public BigDecimal getBigDecimal(int arg0, int arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public BigDecimal getBigDecimal(String arg0, int arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ //
+ // all the update methods are unsupported, requires a separate statement in Cassandra
+ //
+
+ public void updateArray(int arg0, Array arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateArray(String arg0, Array arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateAsciiStream(int arg0, InputStream arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateAsciiStream(String arg0, InputStream arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateAsciiStream(int arg0, InputStream arg1, int arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateAsciiStream(String arg0, InputStream arg1, int arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateAsciiStream(int arg0, InputStream arg1, long arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateAsciiStream(String arg0, InputStream arg1, long arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateBigDecimal(int arg0, BigDecimal arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateBigDecimal(String arg0, BigDecimal arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateBinaryStream(int arg0, InputStream arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateBinaryStream(String arg0, InputStream arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateBinaryStream(int arg0, InputStream arg1, int arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateBinaryStream(String arg0, InputStream arg1, int arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateBinaryStream(int arg0, InputStream arg1, long arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateBinaryStream(String arg0, InputStream arg1, long arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateBlob(int arg0, Blob arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateBlob(String arg0, Blob arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateBlob(int arg0, InputStream arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateBlob(String arg0, InputStream arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateBlob(int arg0, InputStream arg1, long arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateBlob(String arg0, InputStream arg1, long arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateBoolean(int arg0, boolean arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateBoolean(String arg0, boolean arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateByte(int arg0, byte arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateByte(String arg0, byte arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateBytes(int arg0, byte[] arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateBytes(String arg0, byte[] arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateCharacterStream(int arg0, Reader arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateCharacterStream(String arg0, Reader arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateCharacterStream(int arg0, Reader arg1, int arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateCharacterStream(String arg0, Reader arg1, int arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateCharacterStream(int arg0, Reader arg1, long arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateCharacterStream(String arg0, Reader arg1, long arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateClob(int arg0, Clob arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateClob(String arg0, Clob arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateClob(int arg0, Reader arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateClob(String arg0, Reader arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateClob(int arg0, Reader arg1, long arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateClob(String arg0, Reader arg1, long arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateDate(int arg0, Date arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateDate(String arg0, Date arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateDouble(int arg0, double arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateDouble(String arg0, double arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateFloat(int arg0, float arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateFloat(String arg0, float arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateInt(int arg0, int arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateInt(String arg0, int arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateLong(int arg0, long arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateLong(String arg0, long arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateNCharacterStream(int arg0, Reader arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateNCharacterStream(String arg0, Reader arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateNCharacterStream(int arg0, Reader arg1, long arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateNCharacterStream(String arg0, Reader arg1, long arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateNClob(int arg0, NClob arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateNClob(String arg0, NClob arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateNClob(int arg0, Reader arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateNClob(String arg0, Reader arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateNClob(int arg0, Reader arg1, long arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateNClob(String arg0, Reader arg1, long arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateNString(int arg0, String arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateNString(String arg0, String arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateNull(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateNull(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateObject(int arg0, Object arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateObject(String arg0, Object arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateObject(int arg0, Object arg1, int arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateObject(String arg0, Object arg1, int arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateRef(int arg0, Ref arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateRef(String arg0, Ref arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateRow() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateRowId(int arg0, RowId arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateRowId(String arg0, RowId arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateSQLXML(int arg0, SQLXML arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateSQLXML(String arg0, SQLXML arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateShort(int arg0, short arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateShort(String arg0, short arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateString(int arg0, String arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateString(String arg0, String arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateTime(int arg0, Time arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateTime(String arg0, Time arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateTimestamp(int arg0, Timestamp arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public void updateTimestamp(String arg0, Timestamp arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+}
View
560 java/1.0.3/src/org/apache/cassandra/cql/jdbc/CResultSet.java
@@ -0,0 +1,560 @@
+/*
+ *
+ * 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.cql.jdbc;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.net.URL;
+import java.nio.ByteBuffer;
+import java.sql.*;
+import java.sql.Date;
+import java.util.*;
+
+import org.apache.cassandra.db.marshal.CounterColumnType;
+import org.apache.cassandra.thrift.Column;
+import org.apache.cassandra.thrift.CqlResult;
+import org.apache.cassandra.thrift.CqlRow;
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+public class CResultSet extends AbstractResultSet implements CassandraResultSet
+{
+ private final ColumnDecoder decoder;
+ private final String keyspace;
+ private final String columnFamily;
+
+ /** The r set iter. */
+ private Iterator<CqlRow> rSetIter;
+ int rowNumber = 0;
+
+ // the current row key when iterating through results.
+ private byte[] curRowKey = null;
+
+ /** The values. */
+ private List<TypedColumn> values = new ArrayList<TypedColumn>();
+
+ /** The value map. */
+ private Map<String, TypedColumn> valueMap = new HashMap<String, TypedColumn>();
+
+ private final CResultSetMetaData meta;
+
+ private boolean wasNull;
+
+ /**
+ * Instantiates a new cassandra result set.
+ *
+ * @param resultSet the result set
+ */
+ CResultSet(CqlResult resultSet, ColumnDecoder decoder, String keyspace, String columnFamily)
+ {
+ this.decoder = decoder;
+ this.keyspace = keyspace;
+ this.columnFamily = columnFamily;
+ rSetIter = resultSet.getRowsIterator();
+ meta = new CResultSetMetaData();
+ }
+
+ public byte[] getKey()
+ {
+ return curRowKey;
+ }
+
+ public TypedColumn getColumn(int i)
+ {
+ return values.get(i);
+ }
+
+ public TypedColumn getColumn(String name)
+ {
+ return valueMap.get(name);
+ }
+
+ public void close() throws SQLException
+ {
+ valueMap = null;
+ values = null;
+ }
+
+ private byte[] getBytes(TypedColumn column)
+ {
+ ByteBuffer value = (ByteBuffer) column.getValue();
+ wasNull = value == null;
+ return value == null ? null : ByteBufferUtil.clone(value).array();
+ }
+
+ public byte[] getBytes(int index) throws SQLException
+ {
+ return getBytes(values.get(index - 1));
+ }
+
+ public byte[] getBytes(String name) throws SQLException
+ {
+ return getBytes(valueMap.get(name));
+ }
+
+ public Date getDate(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Date getDate(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Date getDate(int arg0, Calendar arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Date getDate(String arg0, Calendar arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public double getDouble(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public double getDouble(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public float getFloat(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public float getFloat(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public boolean getBoolean(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public boolean getBoolean(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ private BigInteger getBigInteger(TypedColumn column)
+ {
+ BigInteger value = (BigInteger) column.getValue();
+ wasNull = value == null;
+ return value;
+ }
+
+ public BigInteger getBigInteger(int i)
+ {
+ return getBigInteger(values.get(i - 1));
+ }
+
+ public BigInteger getBigInteger(String name)
+ {
+ return getBigInteger(valueMap.get(name));
+ }
+
+ private int getInt(TypedColumn column) throws SQLException
+ {
+ // bit of a hack, this, but asking for getInt seems so common that we should accomodate it
+ if (column.getValue() instanceof BigInteger)
+ {
+ wasNull = false;
+ return getBigInteger(column).intValue();
+ }
+ else if (column.getValue() instanceof Long)
+ {
+ wasNull = false;
+ return getLong(column).intValue();
+ }
+ else if (column.getValue() == null)
+ {
+ wasNull = true;
+ return 0;
+ }
+ throw new SQLException("Non-integer value " + column.getValue());
+ }
+
+ public int getInt(int index) throws SQLException
+ {
+ return getInt(values.get(index - 1));
+ }
+
+ public int getInt(String name) throws SQLException
+ {
+ return getInt(valueMap.get(name));
+ }
+
+ private Long getLong(TypedColumn column)
+ {
+ Long value = (Long) column.getValue();
+ wasNull = value == null;
+ return value == null ? 0 : value;
+ }
+
+ public long getLong(int index) throws SQLException
+ {
+ return getLong(values.get(index - 1));
+ }
+
+ public long getLong(String name) throws SQLException
+ {
+ return getLong(valueMap.get(name));
+ }
+
+ public ResultSetMetaData getMetaData() throws SQLException
+ {
+ return meta;
+ }
+
+ private Object getObject(TypedColumn column)
+ {
+ Object value = column.getValue();
+ wasNull = value == null;
+ return value;
+ }
+
+ public Object getObject(int index) throws SQLException
+ {
+ return getObject(values.get(index - 1));
+ }
+
+ public Object getObject(String name) throws SQLException
+ {
+ return getObject(valueMap.get(name));
+ }
+
+ public Object getObject(int arg0, Map<String, Class<?>> arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Object getObject(String arg0, Map<String, Class<?>> arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public int getRow() throws SQLException
+ {
+ return rowNumber;
+ }
+
+ private String getString(TypedColumn column)
+ {
+ String value = (String) column.getValue();
+ wasNull = value == null;
+ return value == null ? null : value;
+ }
+
+ public String getString(int index) throws SQLException
+ {
+ return getString(values.get(index - 1));
+ }
+
+ public String getString(String name) throws SQLException
+ {
+ return getString(valueMap.get(name));
+ }
+
+ public Time getTime(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Time getTime(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Time getTime(int arg0, Calendar arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Time getTime(String arg0, Calendar arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Timestamp getTimestamp(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Timestamp getTimestamp(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Timestamp getTimestamp(int arg0, Calendar arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public Timestamp getTimestamp(String arg0, Calendar arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public int getType() throws SQLException
+ {
+ return ResultSet.TYPE_FORWARD_ONLY;
+ }
+
+ public boolean isAfterLast() throws SQLException
+ {
+ return rowNumber == Integer.MAX_VALUE;
+ }
+
+ public boolean isBeforeFirst() throws SQLException
+ {
+ return rowNumber == 0;
+ }
+
+ public boolean isClosed() throws SQLException
+ {
+ return valueMap == null;
+ }
+
+ public boolean isFirst() throws SQLException
+ {
+ return rowNumber == 1;
+ }
+
+ public boolean isLast() throws SQLException
+ {
+ return !rSetIter.hasNext();
+ }
+
+ public boolean last() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ public <T> T unwrap(Class<T> iface) throws SQLException
+ {
+ if (iface.equals(CassandraResultSet.class))
+ return (T) this;
+ throw new SQLException("Unsupported unwrap interface: " + iface.getSimpleName());
+ }
+
+ public boolean isWrapperFor(Class<?> iface) throws SQLException
+ {
+ return CassandraResultSet.class.isAssignableFrom(iface);
+ }
+
+ public synchronized boolean next() throws SQLException
+ {
+ if (!values.isEmpty() || !valueMap.isEmpty())
+ {
+ values.clear();
+ valueMap.clear();
+ }
+ if (rSetIter != null && rSetIter.hasNext())
+ {
+ CqlRow row = rSetIter.next();
+ rowNumber++;
+ curRowKey = row.getKey();
+ List<Column> cols = row.getColumns();
+ for (Column col : cols)
+ {
+
+ TypedColumn c = decoder.makeCol(keyspace, columnFamily, col);
+ values.add(c);
+ valueMap.put(decoder.colNameAsString(keyspace, columnFamily, col.name), c);
+ }
+ return !(values.isEmpty() && valueMap.isEmpty());
+ }
+ else
+ {
+ rowNumber = Integer.MAX_VALUE;
+ return false;
+ }
+ }
+
+ public boolean wasNull() throws SQLException
+ {
+ return wasNull;
+ }
+
+ /**
+ * RSMD implementation. The metadata returned refers to the column
+ * values, not the column names.
+ */
+ class CResultSetMetaData implements ResultSetMetaData
+ {
+ private void checkIndex(int i) throws SQLException
+ {
+ if (i >= values.size())
+ throw new SQLException("Invalid column index " + i);
+ }
+
+ public int getColumnCount() throws SQLException
+ {
+ return values.size();
+ }
+
+ public boolean isAutoIncrement(int column) throws SQLException
+ {
+ column--;
+ checkIndex(column);
+ return values.get(column).getValueType() instanceof CounterColumnType; // todo: check Value is correct.
+ }
+
+ public boolean isCaseSensitive(int column) throws SQLException
+ {
+ column--;
+ checkIndex(column);
+ TypedColumn tc = values.get(column);
+ return tc.getValueType().isCaseSensitive();
+ }
+
+ public boolean isSearchable(int column) throws SQLException
+ {
+ return false;
+ }
+
+ public boolean isCurrency(int column) throws SQLException
+ {
+ column--;
+ checkIndex(column);
+ TypedColumn tc = values.get(column);
+ return tc.getValueType().isCurrency();
+ }
+
+ /** absence is the equivalent of null in Cassandra */
+ public int isNullable(int column) throws SQLException
+ {
+ return ResultSetMetaData.columnNullable;
+ }
+
+ public boolean isSigned(int column) throws SQLException
+ {
+ column--;
+ checkIndex(column);
+ TypedColumn tc = values.get(column);
+ return tc.getValueType().isSigned();
+ }
+
+ public int getColumnDisplaySize(int column) throws SQLException
+ {
+ column--;
+ checkIndex(column);
+ return values.get(column).getValueString().length();
+ }
+
+ public String getColumnLabel(int column) throws SQLException
+ {
+ return getColumnName(column);
+ }
+
+ public String getColumnName(int column) throws SQLException
+ {
+ column--;
+ checkIndex(column);
+ return values.get(column).getNameString();
+ }
+
+ public String getSchemaName(int column) throws SQLException
+ {
+ return keyspace;
+ }
+
+ public int getPrecision(int column) throws SQLException
+ {
+ column--;
+ checkIndex(column);
+ TypedColumn col = values.get(column);
+ return col.getValueType().getPrecision(col.getValue());
+ }
+
+ public int getScale(int column) throws SQLException
+ {
+ column--;
+ checkIndex(column);
+ TypedColumn tc = values.get(column);
+ return tc.getValueType().getScale(tc.getValue());
+ }
+
+ public String getTableName(int column) throws SQLException
+ {
+ return columnFamily;
+ }
+
+ public String getCatalogName(int column) throws SQLException
+ {
+ throw new SQLFeatureNotSupportedException("Cassandra has no catalogs");
+ }
+
+ public int getColumnType(int column) throws SQLException
+ {
+ column--;
+ checkIndex(column);
+ return values.get(column).getValueType().getJdbcType();
+ }
+
+ // todo: spec says "database specific type name". this means the abstract type.
+ public String getColumnTypeName(int column) throws SQLException
+ {
+ column--;
+ checkIndex(column);
+ return values.get(column).getValueType().getClass().getSimpleName();
+ }
+
+ public boolean isReadOnly(int column) throws SQLException
+ {
+ return column == 0;
+ }
+
+ public boolean isWritable(int column) throws SQLException
+ {
+ return column > 0;
+ }
+
+ public boolean isDefinitelyWritable(int column) throws SQLException
+ {
+ return isWritable(column);
+ }
+
+ public String getColumnClassName(int column) throws SQLException
+ {
+ column--;
+ checkIndex(column);
+ return values.get(column).getValueType().getType().getName();
+ }
+
+ public <T> T unwrap(Class<T> iface) throws SQLException
+ {
+ throw new SQLException("No wrapping implemented");
+ }
+
+ public boolean isWrapperFor(Class<?> iface) throws SQLException
+ {
+ return false;
+ }
+ }
+}
View
658 java/1.0.3/src/org/apache/cassandra/cql/jdbc/CassandraConnection.java
@@ -0,0 +1,658 @@
+/*
+ *
+ * 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.cql.jdbc;
+
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.CallableStatement;
+import java.sql.Clob;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.NClob;
+import java.sql.PreparedStatement;
+import java.sql.SQLClientInfoException;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.SQLXML;
+import java.sql.Savepoint;
+import java.sql.Statement;
+import java.sql.Struct;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.cassandra.thrift.AuthenticationException;
+import org.apache.cassandra.thrift.AuthorizationException;
+import org.apache.cassandra.thrift.InvalidRequestException;
+import org.apache.cassandra.thrift.SchemaDisagreementException;
+import org.apache.cassandra.thrift.TimedOutException;
+import org.apache.cassandra.thrift.UnavailableException;
+import org.apache.thrift.TException;
+import org.apache.thrift.transport.TTransportException;
+
+/**
+ * Implementation class for {@link Connection}.
+ */
+class CassandraConnection implements Connection
+{
+
+ /** The cassandra con. */
+ private org.apache.cassandra.cql.jdbc.Connection cassandraCon;
+
+ /**
+ * Instantiates a new cassandra connection.
+ *
+ * @param url the url
+ */
+ public CassandraConnection(String url)
+ {
+ try
+ {
+ final int splitIndex = url.indexOf('@');
+ final String usr_pwd = url.substring(0, splitIndex);
+ final String host_port = url.substring(splitIndex + 1);
+ final int usr_colonIdx = usr_pwd.lastIndexOf(':');
+ final int usr_backwardIdx = usr_pwd.indexOf('/');
+ final String userName = usr_pwd.substring(usr_colonIdx + 1, usr_backwardIdx);
+ final String password = usr_pwd.substring(usr_backwardIdx + 1);
+ final int host_colonIdx = host_port.indexOf(':');
+ final String hostName = host_port.substring(0, host_colonIdx);
+ final int host_backwardIdx = host_port.indexOf('/');
+ final String port = host_port.substring(host_colonIdx + 1, host_backwardIdx);
+ final String keyspace = host_port.substring(host_backwardIdx + 1);
+ cassandraCon = new org.apache.cassandra.cql.jdbc.Connection(hostName, Integer.valueOf(port), userName,
+ password);
+ final String useQ = "USE " + keyspace;
+ cassandraCon.execute(useQ);
+ }
+ catch (NumberFormatException e)
+ {
+ throw new DriverResolverException(e.getMessage());
+ }
+ catch (TTransportException e)
+ {
+ throw new DriverResolverException(e.getMessage());
+ }
+ catch (AuthenticationException e)
+ {
+ throw new DriverResolverException(e.getMessage());
+ }
+ catch (AuthorizationException e)
+ {
+ throw new DriverResolverException(e.getMessage());
+ }
+ catch (TException e)
+ {
+ throw new DriverResolverException(e.getMessage());
+ }
+ catch (InvalidRequestException e)
+ {
+ throw new DriverResolverException(e.getMessage());
+ }
+ catch (UnavailableException e)
+ {
+ throw new DriverResolverException(e.getMessage());
+ }
+ catch (TimedOutException e)
+ {
+ throw new DriverResolverException(e.getMessage());
+ }
+ catch (SchemaDisagreementException e)
+ {
+ throw new DriverResolverException("schema does not match across nodes, (try again later).");
+ }
+
+ }
+
+ /**
+ * @param arg0
+ * @return
+ * @throws SQLException
+ */
+ public boolean isWrapperFor(Class<?> arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @param <T>
+ * @param arg0
+ * @return
+ * @throws SQLException
+ */
+ public <T> T unwrap(Class<T> arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+
+ /**
+ * @throws SQLException
+ */
+ public void clearWarnings() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+ /**
+ * On close of connection.
+ *
+ * @throws SQLException the sQL exception
+ */
+ public void close() throws SQLException
+ {
+ if (cassandraCon != null)
+ {
+ cassandraCon.close();
+ }
+ }
+
+
+ /**
+ * @throws SQLException
+ */
+ public void commit() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @param arg0
+ * @param arg1
+ * @return
+ * @throws SQLException
+ */
+ public Array createArrayOf(String arg0, Object[] arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @return
+ * @throws SQLException
+ */
+ public Blob createBlob() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @return
+ * @throws SQLException
+ */
+ public Clob createClob() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @return
+ * @throws SQLException
+ */
+ public NClob createNClob() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @return
+ * @throws SQLException
+ */
+ public SQLXML createSQLXML() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @return
+ * @throws SQLException
+ */
+ public Statement createStatement() throws SQLException
+ {
+ return new CassandraStatement(this.cassandraCon);
+ }
+
+
+ /**
+ * @param arg0
+ * @param arg1
+ * @return
+ * @throws SQLException
+ */
+ public Statement createStatement(int arg0, int arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @param arg0
+ * @param arg1
+ * @param arg2
+ * @return
+ * @throws SQLException
+ */
+ public Statement createStatement(int arg0, int arg1, int arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @param arg0
+ * @param arg1
+ * @return
+ * @throws SQLException
+ */
+ public Struct createStruct(String arg0, Object[] arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @return
+ * @throws SQLException
+ */
+ public boolean getAutoCommit() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @return
+ * @throws SQLException
+ */
+ public String getCatalog() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @return
+ * @throws SQLException
+ */
+ public Properties getClientInfo() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @param arg0
+ * @return
+ * @throws SQLException
+ */
+ public String getClientInfo(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @return
+ * @throws SQLException
+ */
+ public int getHoldability() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @return
+ * @throws SQLException
+ */
+ public DatabaseMetaData getMetaData() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @return
+ * @throws SQLException
+ */
+ public int getTransactionIsolation() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @return
+ * @throws SQLException
+ */
+ public Map<String, Class<?>> getTypeMap() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @return
+ * @throws SQLException
+ */
+ public SQLWarning getWarnings() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @return
+ * @throws SQLException
+ */
+ public boolean isClosed() throws SQLException
+ {
+ return false;
+ }
+
+
+ /**
+ * @return
+ * @throws SQLException
+ */
+ public boolean isReadOnly() throws SQLException
+ {
+ return false;
+ }
+
+
+ /**
+ * @param arg0
+ * @return
+ * @throws SQLException
+ */
+ public boolean isValid(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @param arg0
+ * @return
+ * @throws SQLException
+ */
+ public String nativeSQL(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @param arg0
+ * @return
+ * @throws SQLException
+ */
+ public CallableStatement prepareCall(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @param arg0
+ * @param arg1
+ * @param arg2
+ * @return
+ * @throws SQLException
+ */
+ public CallableStatement prepareCall(String arg0, int arg1, int arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @param arg0
+ * @param arg1
+ * @param arg2
+ * @param arg3
+ * @return
+ * @throws SQLException
+ */
+ public CallableStatement prepareCall(String arg0, int arg1, int arg2, int arg3) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @param sql
+ * @return
+ * @throws SQLException
+ */
+ public PreparedStatement prepareStatement(String sql) throws SQLException
+ {
+ return new CassandraPreparedStatement(this.cassandraCon, sql);
+ }
+
+
+ /**
+ * @param arg0
+ * @param arg1
+ * @return
+ * @throws SQLException
+ */
+ public PreparedStatement prepareStatement(String arg0, int arg1) throws SQLException
+ {
+ return null;
+ }
+
+
+ /**
+ * @param arg0
+ * @param arg1
+ * @return
+ * @throws SQLException
+ */
+ public PreparedStatement prepareStatement(String arg0, int[] arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @param arg0
+ * @param arg1
+ * @return
+ * @throws SQLException
+ */
+ public PreparedStatement prepareStatement(String arg0, String[] arg1) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @param arg0
+ * @param arg1
+ * @param arg2
+ * @return
+ * @throws SQLException
+ */
+ public PreparedStatement prepareStatement(String arg0, int arg1, int arg2) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @param arg0
+ * @param arg1
+ * @param arg2
+ * @param arg3
+ * @return
+ * @throws SQLException
+ */
+ public PreparedStatement prepareStatement(String arg0, int arg1, int arg2, int arg3) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @param arg0
+ * @throws SQLException
+ */
+ public void releaseSavepoint(Savepoint arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+
+ }
+
+
+ /**
+ * @throws SQLException
+ */
+ public void rollback() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+
+ }
+
+
+ /**
+ * @param arg0
+ * @throws SQLException
+ */
+ public void rollback(Savepoint arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+
+ }
+
+
+ /**
+ * @param arg0
+ * @throws SQLException
+ */
+ public void setAutoCommit(boolean arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+
+ }
+
+
+ /**
+ * @param arg0
+ * @throws SQLException
+ */
+ public void setCatalog(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @param arg0
+ * @throws SQLClientInfoException
+ */
+ public void setClientInfo(Properties arg0) throws SQLClientInfoException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @param arg0
+ * @param arg1
+ * @throws SQLClientInfoException
+ */
+ public void setClientInfo(String arg0, String arg1) throws SQLClientInfoException
+ {
+ throw new UnsupportedOperationException("method not supported");
+
+ }
+
+
+ /**
+ * @param arg0
+ * @throws SQLException
+ */
+ public void setHoldability(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @param arg0
+ * @throws SQLException
+ */
+ public void setReadOnly(boolean arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @return
+ * @throws SQLException
+ */
+ public Savepoint setSavepoint() throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @param arg0
+ * @return
+ * @throws SQLException
+ */
+ public Savepoint setSavepoint(String arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @param arg0
+ * @throws SQLException
+ */
+ public void setTransactionIsolation(int arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+
+ /**
+ * @param arg0
+ * @throws SQLException
+ */
+ public void setTypeMap(Map<String, Class<?>> arg0) throws SQLException
+ {
+ throw new UnsupportedOperationException("method not supported");
+ }
+
+}
View
134 java/1.0.3/src/org/apache/cassandra/cql/jdbc/CassandraDriver.java
@@ -0,0 +1,134 @@
+/*
+ *
+ * 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.cql.jdbc;
+
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.DriverPropertyInfo;
+import java.sql.SQLException;
+import java.util.Properties;
+
+/**
+ * The Class CassandraDriver.
+ */
+ public class CassandraDriver implements Driver
+{
+
+ /** The Constant MAJOR_VERSION. */
+ private static final int MAJOR_VERSION = 1;
+
+ /** The Constant MINOR_VERSION. */
+ private static final int MINOR_VERSION = 0;
+
+ /** The ACCEPT s_ url. */
+ private static String ACCEPTS_URL = "jdbc:cassandra";
+
+// private static final Logger logger = LoggerFactory.getLogger(CassandraDriver.class);
+
+ static
+ {
+ // Register the CassandraDriver with DriverManager
+ try
+ {
+ CassandraDriver driverInst = new CassandraDriver();
+ DriverManager.registerDriver(driverInst);
+ }
+ catch (SQLException e)
+ {
+ throw new DriverResolverException(e.getMessage());
+ }
+ }
+
+
+ /**
+ * Method to validate whether provided connection url matches with pattern or not.
+ *
+ * @param url connection url.
+ * @return true, if successful
+ * @throws SQLException the sQL exception
+ */
+ public boolean acceptsURL(String url) throws SQLException
+ {
+ return url.startsWith(ACCEPTS_URL);
+ }
+
+ /**
+ * Method to return connection instance for given connection url and connection props.
+ *
+ * @param url connection url.
+ * @param props connection properties.
+ * @return connection connection instance.
+ * @throws SQLException the sQL exception
+ */
+ public Connection connect(String url, Properties props) throws SQLException
+ {
+ if (acceptsURL(url))
+ {
+ return new CassandraConnection(url);
+ }
+ else
+ {
+ throw new InvalidUrlException("Invalid connection url:" + url + ". should start with jdbc:cassandra");
+ }
+ }
+
+ /**
+ * Returns default major version.
+ * @return MAJOR_VERSION major version.
+ */
+ public int getMajorVersion()
+ {
+ return MAJOR_VERSION;
+ }
+
+ /**
+ * Returns default minor version.
+ * @return MINOR_VERSION minor version.
+ */
+ public int getMinorVersion()
+ {
+ return MINOR_VERSION;
+ }
+
+ /**
+ * Returns default driver property info object.
+ *
+ * @param arg0 the arg0
+ * @param arg1 the arg1
+ * @return driverPropertyInfo
+ * @throws SQLException the sQL exception
+ */
+ public DriverPropertyInfo[] getPropertyInfo(String arg0, Properties arg1) throws SQLException
+ {
+ return new DriverPropertyInfo[0];
+ }
+
+ /**
+ * Returns true, if it is jdbc compliant.
+ * @return value true, if it is jdbc compliant.
+ */
+ public boolean jdbcCompliant()
+ {
+ return false;
+ }
+
+}
View
551 java/1.0.3/src/org/apache/cassandra/cql/jdbc/CassandraPreparedStatement.java
@@ -0,0 +1,551 @@
+package org.apache.cassandra.cql.jdbc;
+/*
+ *
+ * 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 org.apache.cassandra.db.marshal.*;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.net.URL;
+import java.nio.ByteBuffer;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Date;
+import java.sql.NClob;
+import java.sql.ParameterMetaData;
+import java.sql.PreparedStatement;
+import java.sql.Ref;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.RowId;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.sql.SQLXML;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class CassandraPreparedStatement extends CassandraStatement implements PreparedStatement
+{
+// private static final Pattern Parameterizable = Pattern.compile("(SELECT|DELETE|UPDATE)\\s+.*", Pattern.CASE_INSENSITIVE);
+ private static final Pattern Select = Pattern.compile("SELECT[\\s+FIRST\\s+\\d+]?[\\s+REVERSED]?\\s+(.*)WHERE\\s+(.*)", Pattern.CASE_INSENSITIVE);
+ private static final Pattern Update = Pattern.compile("UPDATE\\s+\\w+.*\\s+SET\\s+(.*)\\s+WHERE KEY(.*)", Pattern.CASE_INSENSITIVE);
+ private static final Pattern Delete = Pattern.compile("DELETE\\s+(.*)\\s+FROM\\s+\\w+\\s+WHERE KEY(.*)", Pattern.CASE_INSENSITIVE);
+
+ // current set of bound variables.
+ private final Map<Integer, Object> variables = new HashMap<Integer, Object>();
+
+ // for batching. These are the queries that have been batched and not executed.
+ private final List<String> queries = new ArrayList<String>();
+
+ CassandraPreparedStatement(Connection con, String cql)
+ {
+ super(con, cql);
+ }
+
+ // impl specific methods start here.
+
+ // double quotes strings (in parameters)
+ private static String makeCqlString(String s)
+ {
+ // escape any single-quotes with double single-quotes.
+ return s.replaceAll("\'", "\'\'");
+ }
+
+ // null type means just call param.toString() and quote it (default for keys).
+ private static String applySimpleBindings(String q, AbstractType type, ParameterIterator params) throws SQLException
+ {
+ assert type != null;
+ // we need to keep track of whether or not we are between quotes and ignore any question marks within them
+ // so that they are not substituted.
+ StringBuffer sb = new StringBuffer();
+ boolean between = false;
+ for (char c : q.toCharArray())
+ {
+ if (c == '\'')
+ between = !between;
+ if (between)
+ sb.append(c);
+ else if (c == '?') // !between if we got here.
+ {
+ try
+ {
+ // perform substitution!
+ Object param = params.nextParam();
+ String stringParam = type == null ? param.toString() : type.toString(param);
+ stringParam = makeCqlString(stringParam);
+ if (type == null || type.needsQuotes())
+ stringParam = "'" + stringParam + "'";
+ sb.append(stringParam);
+ }
+ catch (ClassCastException ex)
+ {
+ throw new SQLException("Mismatched types: " + ex.getLocalizedMessage());
+ }
+ }
+ else
+ sb.append(c);
+
+ }
+ return sb.toString();
+ }
+
+ private static String applyDualBindings(String q, AbstractType ltype, AbstractType rtype, ParameterIterator params) throws SQLException
+ {
+ StringBuffer sb = new StringBuffer();
+ boolean between = false;
+ boolean left = true; // we always start on the left-hand side of a statement. we switch state if we reach a comma and we are not between.
+ for (char c : q.toCharArray())
+ {
+ if (c == '\'')
+ between = !between;
+ if (c == '=' && !between)
+ left = false;
+ if (c == ',' && !between)
+ left = true;
+
+ if (c == '?' && !between)
+ {
+ try
+ {
+ Object param = params.nextParam();
+ AbstractType type = left ? ltype : rtype;
+ String stringParam = makeCqlString(type.toString(param));
+ if (type.needsQuotes())
+ stringParam = "'" + stringParam + "'";
+ sb.append(stringParam);
+ }
+ catch (ClassCastException ex)
+ {
+ throw new SQLException("Mismatched types: " + ex.getLocalizedMessage());
+ }
+ }
+ else
+ sb.append(c);
+ }
+ return sb.toString();
+ }
+
+ /** applies current bindings to produce a string that can be sent to the server. */
+ public synchronized String makeCql() throws SQLException
+ {
+ // break cql up
+ Matcher m;
+ m = Delete.matcher(cql);
+ if (m.matches())
+ return makeDelete(m.end(1));
+ m = Update.matcher(cql);
+ if (m.matches())
+ return makeUpdate(m.end(1));
+ m = Select.matcher(cql);
+ if (m.matches())
+ return makeSelect(m.end(1));
+
+ // if we made it this far, cql is not parameterizable. this isn't bad, there is just nothing to be done.
+ return cql;
+ }
+
+ // subs parameters into a delete statement.
+ private String makeDelete(int pivot) throws SQLException
+ {
+ String keyspace = connection.getKeyspace(cql);
+ String columnFamily = connection.getColumnFamily(cql);
+ ParameterIterator params = new ParameterIterator();
+ String left = cql.substring(0, pivot);
+ 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);
+ String right = cql.substring(pivot);
+ AbstractType keyVald = connection.decoder.getKeyValidator(keyspace, columnFamily);
+ if (keyVald == null)
+ throw new SQLException("Could not find key validator for " + keyspace + "." + columnFamily);
+ right = applySimpleBindings(right, keyVald, params);
+ return left + right;
+ }
+
+ // subs parameters into a select statement.
+ private String makeSelect(int pivot) throws SQLException
+ {
+ String keyspace = connection.getKeyspace(cql);
+ String columnFamily = connection.getColumnFamily(cql);
+ ParameterIterator params = new ParameterIterator();
+ String left = cql.substring(0, pivot);
+ 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);
+ String right = cql.substring(pivot);
+ AbstractType keyVald = connection.decoder.getKeyValidator(keyspace, columnFamily);
+ if (keyVald == null)
+ throw new SQLException("Could not find key validator for " + keyspace + "." + columnFamily);
+ right = applySimpleBindings(right, keyVald, params);
+ return left + right;
+ }
+
+ // subs parameters into an update statement.
+ private String makeUpdate(int pivot) throws SQLException
+ {
+ // this one is a little bit different. left contains key=value pairs. we use the comparator for the left side,
+ // the validator for the right side. right side is treated as a key.
+ String keyspace = connection.getKeyspace(cql);
+ String columnFamily = connection.getColumnFamily(cql);
+ ParameterIterator params = new ParameterIterator();
+ String left = cql.substring(0, pivot);
+ 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);
+ if (leftVald == null)
+ throw new SQLException("Could not find validator for " + keyspace + "." + columnFamily);
+ left = applyDualBindings(left, leftComp, leftVald, params);
+ String right = cql.substring(pivot);
+ AbstractType keyVald = connection.decoder.getKeyValidator(keyspace, columnFamily);
+ if (keyVald == null)
+ throw new SQLException("Could not find key validator for " + keyspace + "." + columnFamily);
+ right = applySimpleBindings(right, keyVald, params);
+ return left + right;
+ }
+
+
+
+ // standard API methods follow.
+
+ public void addBatch() throws SQLException
+ {
+ queries.add(makeCql());
+ }
+
+ public synchronized void clearParameters() throws SQLException
+ {
+ variables.clear();
+ }
+
+ public boolean execute() throws SQLException
+ {
+ return this.cql != null && super.execute(makeCql());
+ }
+
+ public ResultSet executeQuery() throws SQLException
+ {
+ return this.cql != null ? super.executeQuery(makeCql()) : null;
+ }
+
+ public int executeUpdate() throws SQLException
+ {
+ String q = makeCql();
+ if (!UpdatePattern.matcher(q).matches())
+ throw new SQLException("Not an update statement.");
+ super.execute(q);
+ // we don't know how many rows were updated.
+ return 0;
+ }
+
+ public ResultSetMetaData getMetaData() throws SQLException
+ {
+ // todo: current impl of RSMD relies on knowing the results. implementing this will require refactoring CRSMD into
+ // two classes: the first will be an implementation whose methods don't rely on knowing the results, the second
+ // will implement the full CRSMD interfae and extend or compose the first.
+ throw new SQLFeatureNotSupportedException("PreparedStatement.getMetaData() hasn't been implemented yet.");
+ }
+
+ public void setByte(int parameterIndex, byte x) throws SQLException
+ {
+ setObject(parameterIndex, new byte[]{x});
+ }
+
+ public void setBytes(int parameterIndex, byte[] x) throws SQLException
+ {
+ setObject(parameterIndex, ByteBuffer.wrap(x));
+ }
+
+ public void setInt(int parameterIndex, int x) throws SQLException
+ {
+ setObject(parameterIndex, new BigInteger(Integer.toString(x)));
+ }
+
+ public void setLong(int parameterIndex, long x) throws SQLException
+ {
+ setObject(parameterIndex, x);