drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ve...@apache.org
Subject [3/3] drill git commit: DRILL-4880: Support JDBC driver registration using ServiceLoader
Date Wed, 12 Oct 2016 22:44:19 GMT
DRILL-4880: Support JDBC driver registration using ServiceLoader

Support loading Drill driver using ServiceLoader. From the user perspective,
it means being able to use the driver without registering it first, like by using
Class.forName("org.apache.drill.jdbc.Driver") for example.

this closes #596

Change-Id: Id26922ee42bef5fbce46ac2bcbb83f1859e9bb48


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

Branch: refs/heads/master
Commit: 09abcc32cc9d6e3de23d3daf633d34fb6183d0f3
Parents: a888ce6
Author: Laurent Goujon <laurent@dremio.com>
Authored: Mon Sep 26 17:14:59 2016 -0700
Committer: vkorukanti <venki@dremio.com>
Committed: Wed Oct 12 13:57:44 2016 -0700

----------------------------------------------------------------------
 exec/jdbc-all/pom.xml                           | 11 +++++++++-
 exec/jdbc/pom.xml                               |  1 +
 .../resources/META-INF/services/java.sql.Driver |  1 +
 .../apache/drill/jdbc/test/JdbcDataTest.java    | 22 +++++++++++++++++++-
 4 files changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/09abcc32/exec/jdbc-all/pom.xml
----------------------------------------------------------------------
diff --git a/exec/jdbc-all/pom.xml b/exec/jdbc-all/pom.xml
index f7dfde2..c8f27d9 100644
--- a/exec/jdbc-all/pom.xml
+++ b/exec/jdbc-all/pom.xml
@@ -388,7 +388,16 @@
                <exclude>**/logback.xml</exclude>
                <exclude>**/LICENSE.txt</exclude>
                <exclude>**/*.java</exclude>
-               <exclude>**/META-INF/**</exclude>
+               <exclude>META-INF/ASL2.0</exclude>
+               <exclude>META-INF/NOTICE.txt</exclude>
+               <exclude>META-INF/drill-module-scan/**</exclude>
+               <exclude>META-INF/jboss-beans.xml</exclude>
+               <exclude>META-INF/license/**</exclude>
+               <exclude>META-INF/maven/**</exclude>
+               <exclude>META-INF/native/**</exclude>
+               <exclude>META-INF/services/com.fasterxml.*</exclude>
+               <exclude>META-INF/services/javax.ws.*</exclude>
+               <exclude>META-INF/**/*.properties</exclude>
                <exclude>**/org.codehaus.commons.compiler.properties</exclude>
                <exclude>**/*.SF</exclude>
                <exclude>**/*.RSA</exclude>

http://git-wip-us.apache.org/repos/asf/drill/blob/09abcc32/exec/jdbc/pom.xml
----------------------------------------------------------------------
diff --git a/exec/jdbc/pom.xml b/exec/jdbc/pom.xml
index 73a61b3..b26ff6a 100644
--- a/exec/jdbc/pom.xml
+++ b/exec/jdbc/pom.xml
@@ -117,6 +117,7 @@
             <exclude>**/donuts-output-data.txt</exclude>
             <exclude>**/*.tbl</exclude>
             <exclude>**/derby.log</exclude>
+            <exclude>src/main/resources/META-INF/services/**</exclude>
           </excludes>
         </configuration>
       </plugin>

http://git-wip-us.apache.org/repos/asf/drill/blob/09abcc32/exec/jdbc/src/main/resources/META-INF/services/java.sql.Driver
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/main/resources/META-INF/services/java.sql.Driver b/exec/jdbc/src/main/resources/META-INF/services/java.sql.Driver
new file mode 100644
index 0000000..e7d99b4
--- /dev/null
+++ b/exec/jdbc/src/main/resources/META-INF/services/java.sql.Driver
@@ -0,0 +1 @@
+org.apache.drill.jdbc.Driver

http://git-wip-us.apache.org/repos/asf/drill/blob/09abcc32/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcDataTest.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcDataTest.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcDataTest.java
index fd5d4f0..05e34c6 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcDataTest.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcDataTest.java
@@ -19,10 +19,14 @@ package org.apache.drill.jdbc.test;
 
 import java.io.IOException;
 import java.sql.Connection;
+import java.sql.Driver;
 import java.sql.DriverManager;
 import java.sql.Statement;
+import java.util.Iterator;
 import java.util.Map;
+import java.util.ServiceLoader;
 
+import org.apache.calcite.rel.core.JoinRelType;
 import org.apache.drill.common.logical.LogicalPlan;
 import org.apache.drill.common.logical.PlanProperties;
 import org.apache.drill.common.logical.StoragePluginConfig;
@@ -37,7 +41,6 @@ import org.apache.drill.common.logical.data.Store;
 import org.apache.drill.common.logical.data.Union;
 import org.apache.drill.jdbc.JdbcTestBase;
 import org.apache.drill.jdbc.test.JdbcAssert.TestDataConnection;
-import org.apache.calcite.rel.core.JoinRelType;
 import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
@@ -80,6 +83,22 @@ public class JdbcDataTest extends JdbcTestBase {
     Class.forName("org.apache.drill.jdbc.Driver");
   }
 
+  /**
+   * Load the driver using ServiceLoader
+   */
+  @Test
+  public void testLoadDriverServiceLoader() {
+    ServiceLoader<Driver> sl = ServiceLoader.load(Driver.class);
+    for(Iterator<Driver> it = sl.iterator(); it.hasNext(); ) {
+      Driver driver = it.next();
+      if (driver instanceof org.apache.drill.jdbc.Driver) {
+        return;
+      }
+    }
+
+    Assert.fail("org.apache.drill.jdbc.Driver not found using ServiceLoader");
+  }
+
   /** Load driver and make a connection. */
   @Test
   public void testConnect() throws Exception {
@@ -92,6 +111,7 @@ public class JdbcDataTest extends JdbcTestBase {
   @Test
   public void testPrepare() throws Exception {
     JdbcAssert.withModel(MODEL, "DONUTS").withConnection(new Function<Connection, Void>()
{
+      @Override
       public Void apply(Connection connection) {
         try {
           final Statement statement = connection.prepareStatement("select * from donuts");


Mime
View raw message