cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cassandra-jdbc.apache-extras....@codespot.com
Subject [cassandra-jdbc] push by wfs...@gmail.com - Added version support to CassandraDataSource... on 2012-07-02 03:27 GMT
Date Mon, 02 Jul 2012 03:27:46 GMT
Revision: 1987674439de
Author:   David Alves <dalves@datastax.com>
Date:     Sun Jul  1 20:22:16 2012
Log:      Added version support to CassandraDataSource

  o added a getter for the connectionParameter property to
CassandraConnection
  o support for cql version to CassandraDataSource
  o added Apache header to CassandraDataSource (wfs)
  o added a test case to DataSourceTest
http://code.google.com/a/apache-extras.org/p/cassandra-jdbc/source/detail?r=1987674439de

Modified:
  /src/main/java/org/apache/cassandra/cql/jdbc/CassandraConnection.java
  /src/main/java/org/apache/cassandra/cql/jdbc/CassandraDataSource.java
  /src/test/java/org/apache/cassandra/cql/jdbc/DataSourceTest.java

=======================================
--- /src/main/java/org/apache/cassandra/cql/jdbc/CassandraConnection.java	 
Tue Feb  7 13:58:37 2012
+++ /src/main/java/org/apache/cassandra/cql/jdbc/CassandraConnection.java	 
Sun Jul  1 20:22:16 2012
@@ -216,6 +216,11 @@
          checkNotClosed();
          return autoCommit;
      }
+
+    public Properties getConnectionProps()
+    {
+        return connectionProps;
+    }

      public String getCatalog() throws SQLException
      {
=======================================
--- /src/main/java/org/apache/cassandra/cql/jdbc/CassandraDataSource.java	 
Thu Oct 13 00:45:22 2011
+++ /src/main/java/org/apache/cassandra/cql/jdbc/CassandraDataSource.java	 
Sun Jul  1 20:22:16 2012
@@ -1,14 +1,35 @@
+/*
+ *
+ * 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 static org.apache.cassandra.cql.jdbc.Utils.HOST_REQUIRED;
-import static org.apache.cassandra.cql.jdbc.Utils.NO_INTERFACE;
  import static org.apache.cassandra.cql.jdbc.Utils.NOT_SUPPORTED;
+import static org.apache.cassandra.cql.jdbc.Utils.NO_INTERFACE;
  import static org.apache.cassandra.cql.jdbc.Utils.PROTOCOL;
-import static org.apache.cassandra.cql.jdbc.Utils.TAG_SERVER_NAME;
+import static org.apache.cassandra.cql.jdbc.Utils.TAG_CQL_VERSION;
  import static org.apache.cassandra.cql.jdbc.Utils.TAG_DATABASE_NAME;
  import static org.apache.cassandra.cql.jdbc.Utils.TAG_PASSWORD;
  import static org.apache.cassandra.cql.jdbc.Utils.TAG_PORT_NUMBER;
+import static org.apache.cassandra.cql.jdbc.Utils.TAG_SERVER_NAME;
  import static org.apache.cassandra.cql.jdbc.Utils.TAG_USER;
  import static org.apache.cassandra.cql.jdbc.Utils.createSubName;

@@ -18,8 +39,8 @@
  import java.sql.SQLException;
  import java.sql.SQLFeatureNotSupportedException;
  import java.sql.SQLNonTransientConnectionException;
-import java.util.logging.Logger;
  import java.util.Properties;
+import java.util.logging.Logger;

  import javax.sql.DataSource;

@@ -50,10 +71,13 @@

      protected String password;

-    public CassandraDataSource(String host, int port, String keyspace,  
String user, String password)
+    protected String version = null;
+
+    public CassandraDataSource(String host, int port, String keyspace,  
String user, String password, String version)
      {
          if (host != null) setServerName(host);
          if (port != -1) setPortNumber(port);
+        if (version != null) setVersion(version);
          setDatabaseName(keyspace);
          setUser(user);
          setPassword(password);
@@ -73,6 +97,16 @@
      {
          this.serverName = serverName;
      }
+
+    public String getVersion()
+    {
+        return version;
+    }
+
+    public void setVersion(String version)
+    {
+        this.version = version;
+    }

      public int getPortNumber()
      {
@@ -132,6 +166,7 @@
          if (this.databaseName!=null) props.setProperty(TAG_DATABASE_NAME,  
this.databaseName);
          if (user!=null) props.setProperty(TAG_USER, user);
          if (password!=null) props.setProperty(TAG_PASSWORD, password);
+        if (this.version != null) props.setProperty(TAG_CQL_VERSION,  
version);

          String url = PROTOCOL+createSubName(props);
          return DriverManager.getConnection(url, props);
=======================================
--- /src/test/java/org/apache/cassandra/cql/jdbc/DataSourceTest.java	Tue  
Feb  7 13:58:37 2012
+++ /src/test/java/org/apache/cassandra/cql/jdbc/DataSourceTest.java	Sun  
Jul  1 20:22:16 2012
@@ -20,9 +20,11 @@
   */
  package org.apache.cassandra.cql.jdbc;

-import static org.junit.Assert.*;
-
-import java.io.PrintWriter;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
  import java.sql.DriverManager;
  import java.sql.SQLFeatureNotSupportedException;
  import java.sql.Statement;
@@ -41,6 +43,7 @@
      private static final String KEYSPACE = "TestKS";
      private static final String USER = "JohnDoe";
      private static final String PASSWORD = "secret";
+    private static final String VERSION = "2.0.0";

      private static java.sql.Connection con = null;

@@ -73,14 +76,15 @@
      @Test
      public void testConstructor() throws Exception
      {
-        CassandraDataSource cds = new  
CassandraDataSource(HOST,PORT,KEYSPACE,USER,PASSWORD);
+        CassandraDataSource cds = new  
CassandraDataSource(HOST,PORT,KEYSPACE,USER,PASSWORD,VERSION);
          assertEquals(HOST,cds.getServerName());
          assertEquals(PORT,cds.getPortNumber());
          assertEquals(KEYSPACE,cds.getDatabaseName());
          assertEquals(USER,cds.getUser());
          assertEquals(PASSWORD,cds.getPassword());
-
-        DataSource ds = new  
CassandraDataSource(HOST,PORT,KEYSPACE,USER,PASSWORD);
+        assertEquals(VERSION, cds.getVersion());
+
+        DataSource ds = new  
CassandraDataSource(HOST,PORT,KEYSPACE,USER,PASSWORD,VERSION);
          assertNotNull(ds);

          // null username and password
@@ -93,6 +97,7 @@
          cnx = ds.getConnection();
          assertFalse(cnx.isClosed());
          ds.setLoginTimeout(5);
+        assertEquals("2.0.0", ((CassandraConnection)  
cnx).getConnectionProps().get(Utils.TAG_CQL_VERSION));
          assertEquals(5, ds.getLoginTimeout());
      }

@@ -100,7 +105,7 @@
      @Test
      public void testIsWrapperFor() throws Exception
      {
-        DataSource ds = new  
CassandraDataSource(HOST,PORT,KEYSPACE,USER,PASSWORD);
+        DataSource ds = new  
CassandraDataSource(HOST,PORT,KEYSPACE,USER,PASSWORD,VERSION);

          boolean isIt = false;

@@ -116,7 +121,7 @@
      @Test(expected=SQLFeatureNotSupportedException.class)
      public void testUnwrap() throws Exception
      {
-        DataSource ds = new  
CassandraDataSource(HOST,PORT,KEYSPACE,USER,PASSWORD);
+        DataSource ds = new  
CassandraDataSource(HOST,PORT,KEYSPACE,USER,PASSWORD,VERSION);

          // it is a wrapper for DataSource
          DataSource newds = ds.unwrap(DataSource.class);

Mime
View raw message