Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 073ed20c1 -> cc134fe15


PHOENIX-2368 Call Driver.accept() in Driver.getConnection and return null
if false (Ram)


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/cc134fe1
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/cc134fe1
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/cc134fe1

Branch: refs/heads/4.x-HBase-0.98
Commit: cc134fe151891e88338590baa98030ff5e44bfac
Parents: 073ed20
Author: ramkrishna <ramkrishna.s.vasude...@gmail.com>
Authored: Tue Jan 12 08:16:32 2016 +0530
Committer: ramkrishna <ramkrishna.s.vasude...@gmail.com>
Committed: Tue Jan 12 08:18:47 2016 +0530

----------------------------------------------------------------------
 .../java/org/apache/phoenix/jdbc/PhoenixDriver.java   |  5 ++++-
 .../apache/phoenix/jdbc/PhoenixEmbeddedDriver.java    | 14 +++++++++-----
 .../org/apache/phoenix/jdbc/PhoenixDriverTest.java    | 12 ++++++++++++
 3 files changed, 25 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/cc134fe1/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java 
b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java
index 0f5d4aa..9dafbbf 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java
@@ -183,10 +183,13 @@ public final class PhoenixDriver extends 
PhoenixEmbeddedDriver {
     
     @Override
     public Connection connect(String url, Properties info) throws SQLException 
{
+        if (!acceptsURL(url)) {
+          return null;
+        }
         try {
             closeLock.readLock().lock();
             checkClosed();
-            return super.connect(url, info);
+            return createConnection(url, info);
         } finally {
             closeLock.readLock().unlock();
         }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/cc134fe1/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java 
b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java
index c49bf37..486a6d7 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java
@@ -126,11 +126,15 @@ public abstract class PhoenixEmbeddedDriver implements 
Driver, SQLCloseable {
             return null;
         }
 
-        Properties augmentedInfo = PropertiesUtil.deepCopy(info);
-        augmentedInfo.putAll(getDefaultProps().asMap());
-        ConnectionQueryServices connectionServices = 
getConnectionQueryServices(url, augmentedInfo);
-        PhoenixConnection connection = connectionServices.connect(url, 
augmentedInfo);
-        return connection;
+        return createConnection(url, info);
+    }
+
+    protected final Connection createConnection(String url, Properties info) 
throws SQLException {
+      Properties augmentedInfo = PropertiesUtil.deepCopy(info);
+      augmentedInfo.putAll(getDefaultProps().asMap());
+      ConnectionQueryServices connectionServices = 
getConnectionQueryServices(url, augmentedInfo);
+      PhoenixConnection connection = connectionServices.connect(url, 
augmentedInfo);
+      return connection;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/phoenix/blob/cc134fe1/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixDriverTest.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixDriverTest.java 
b/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixDriverTest.java
index b70ea71..02af191 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixDriverTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixDriverTest.java
@@ -114,4 +114,16 @@ public class PhoenixDriverTest extends 
BaseConnectionlessQueryTest {
         conn.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
         conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
     }
+
+    @Test
+    public void testInvalidURL() throws Exception {
+      Class.forName(PhoenixDriver.class.getName());
+      PhoenixDriver d = (PhoenixDriver) 
DriverManager.getDriver("jdbc:phoenix");
+      d.close();
+      try {
+      DriverManager.getConnection("any text whatever you want to put here");
+      fail("Should have failed due to invalid driver");
+      } catch(Exception e) {
+      }
+    }
 }

Reply via email to