ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject [2/3] incubator-ignite git commit: IGNITE-843: Read JDBC driver class from driver jar file.
Date Fri, 14 Aug 2015 11:30:06 GMT
IGNITE-843: Read JDBC driver class from driver jar file.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/14287f69
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/14287f69
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/14287f69

Branch: refs/heads/ignite-843
Commit: 14287f6963d135afe314586f733217a3b69edd05
Parents: 98cadbf
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Fri Aug 14 18:26:28 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Fri Aug 14 18:26:28 2015 +0700

----------------------------------------------------------------------
 .../handlers/DatabaseMetadataExtractor.java     | 39 ++++++++++++++++++--
 1 file changed, 35 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/14287f69/modules/control-center-agent/src/main/java/org/apache/ignite/agent/handlers/DatabaseMetadataExtractor.java
----------------------------------------------------------------------
diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/handlers/DatabaseMetadataExtractor.java
b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/handlers/DatabaseMetadataExtractor.java
index 8f6f5b2..57f6720 100644
--- a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/handlers/DatabaseMetadataExtractor.java
+++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/handlers/DatabaseMetadataExtractor.java
@@ -22,6 +22,7 @@ import org.apache.ignite.agent.remote.*;
 import org.apache.ignite.schema.parser.*;
 
 import java.io.*;
+import java.net.*;
 import java.sql.*;
 import java.util.*;
 
@@ -68,11 +69,30 @@ public class DatabaseMetadataExtractor {
     }
 
     /**
+     * Wrapper class for later to be transformed to JSON and send to Web Control Center.
+     */
+    private static class JdbcDriver {
+        /** */
+        private final String jdbcDriverClass;
+        /** */
+        private final String jdbcDriverJar;
+
+        /**
+         * @param jdbcDriverClass Optional JDBC driver class.
+         * @param jdbcDriverJar File name of driver jar file.
+         */
+        public JdbcDriver(String jdbcDriverClass, String jdbcDriverJar) {
+            this.jdbcDriverClass = jdbcDriverClass;
+            this.jdbcDriverJar = jdbcDriverJar;
+        }
+    }
+
+    /**
      * @return Drivers in drivers folder
      * @see AgentConfiguration#driversFolder
      */
     @Remote
-    public List<String> availableDrivers() {
+    public List<JdbcDriver> availableDrivers() {
         if (driversFolder == null)
             return Collections.emptyList();
 
@@ -81,11 +101,22 @@ public class DatabaseMetadataExtractor {
         if (list == null)
             return Collections.emptyList();
 
-        List<String> res = new ArrayList<>();
+        List<JdbcDriver> res = new ArrayList<>();
 
         for (String fileName : list) {
-            if (fileName.endsWith(".jar"))
-                res.add(fileName);
+            if (fileName.endsWith(".jar")) {
+                try {
+                    String spec = "jar:file:/" + driversFolder + '/' + fileName + "!/META-INF/services/java.sql.Driver";
+
+                    URL url = new URL(spec.replace('\\', '/'));
+
+                    try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())))
{
+                        res.add(new JdbcDriver(reader.readLine(), fileName));
+                    }
+                } catch (IOException ignored) {
+                    res.add(new JdbcDriver(null, fileName));
+                }
+            }
         }
 
         return res;


Mime
View raw message