You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by dm...@apache.org on 2016/06/13 11:33:29 UTC

[2/3] ignite git commit: Mysql support broken in 1.6, externalize sql syntax to make it configurable Reviewed and merged by Denis Magda.

Mysql support broken in 1.6, externalize sql syntax to make it configurable
Reviewed and merged by Denis Magda.


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

Branch: refs/heads/master
Commit: 4f8ba17b412af8d32812ffba39e7dc2a2326ecf8
Parents: 320c1aa
Author: Kristian Rosenvold <kr...@gmail.com>
Authored: Mon Jun 13 14:32:20 2016 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Mon Jun 13 14:32:20 2016 +0300

----------------------------------------------------------------------
 .../ipfinder/jdbc/BasicJdbcIpFinderDialect.java | 28 ++++++++
 .../tcp/ipfinder/jdbc/JdbcIpFinderDialect.java  | 28 ++++++++
 .../jdbc/OracleJdbcIpFinderDialect.java         | 28 ++++++++
 .../ipfinder/jdbc/TcpDiscoveryJdbcIpFinder.java | 72 +++++++++++---------
 4 files changed, 122 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/4f8ba17b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/jdbc/BasicJdbcIpFinderDialect.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/jdbc/BasicJdbcIpFinderDialect.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/jdbc/BasicJdbcIpFinderDialect.java
new file mode 100644
index 0000000..9a626c2
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/jdbc/BasicJdbcIpFinderDialect.java
@@ -0,0 +1,28 @@
+/*
+ * 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.ignite.spi.discovery.tcp.ipfinder.jdbc;
+
+/**
+ * Basic JDBC dialect to use along with {@link TcpDiscoveryJdbcIpFinder}.
+ */
+public class BasicJdbcIpFinderDialect implements JdbcIpFinderDialect {
+    /** {@inheritDoc} */
+    @Override public String tableName() {
+        return "tbl_addrs";
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/4f8ba17b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/jdbc/JdbcIpFinderDialect.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/jdbc/JdbcIpFinderDialect.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/jdbc/JdbcIpFinderDialect.java
new file mode 100644
index 0000000..099d172
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/jdbc/JdbcIpFinderDialect.java
@@ -0,0 +1,28 @@
+/*
+ * 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.ignite.spi.discovery.tcp.ipfinder.jdbc;
+
+/**
+ * SQL dialect to use with {@link TcpDiscoveryJdbcIpFinder}.
+ */
+public interface JdbcIpFinderDialect {
+	/**
+	 * Gets table name in a valid form to use as IP addresses
+	 * @return Table name.
+	 */
+	public String tableName();
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/4f8ba17b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/jdbc/OracleJdbcIpFinderDialect.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/jdbc/OracleJdbcIpFinderDialect.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/jdbc/OracleJdbcIpFinderDialect.java
new file mode 100644
index 0000000..dce506c
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/jdbc/OracleJdbcIpFinderDialect.java
@@ -0,0 +1,28 @@
+/*
+ * 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.ignite.spi.discovery.tcp.ipfinder.jdbc;
+
+/**
+ * Oracle JDBC dialect to use along with {@link TcpDiscoveryJdbcIpFinder}.
+ */
+public class OracleJdbcIpFinderDialect implements JdbcIpFinderDialect {
+    /** {@inheritDoc} */
+    @Override public String tableName() {
+        return "\"TBL_ADDRS\"";
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/4f8ba17b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/jdbc/TcpDiscoveryJdbcIpFinder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/jdbc/TcpDiscoveryJdbcIpFinder.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/jdbc/TcpDiscoveryJdbcIpFinder.java
index 24802f5..a16f238 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/jdbc/TcpDiscoveryJdbcIpFinder.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/jdbc/TcpDiscoveryJdbcIpFinder.java
@@ -59,31 +59,6 @@ import static java.sql.Connection.TRANSACTION_READ_COMMITTED;
  * The database will contain 1 table which will hold IP addresses.
  */
 public class TcpDiscoveryJdbcIpFinder extends TcpDiscoveryIpFinderAdapter {
-    /** Name of the address table, in upper case.  Mostly table names are not case-sensitive
-     * but databases such as Oracle require table names in upper-case when looking them up in the metadata. */
-    public static final String ADDRS_TABLE_NAME = "TBL_ADDRS";
-    
-    /** Query to get addresses. */
-    public static final String GET_ADDRS_QRY = "select hostname, port from \"" + ADDRS_TABLE_NAME
-            + "\"";
-
-    /** Query to register address. */
-    public static final String REG_ADDR_QRY = "insert into \"" + ADDRS_TABLE_NAME
-            + "\" values (?, ?)";
-
-    /** Query to unregister address. */
-    public static final String UNREG_ADDR_QRY = "delete from \"" + ADDRS_TABLE_NAME
-            + "\" where hostname = ? and port = ?";
-
-    /** Query to create addresses table. */
-    public static final String CREATE_ADDRS_TABLE_QRY =
-        "create table \"" + ADDRS_TABLE_NAME + "\" (" +
-        "hostname VARCHAR(1024), " +
-        "port INT)";
-
-    /** Query to check database validity. */
-    public static final String CHK_QRY = "select count(*) from \"" + ADDRS_TABLE_NAME + "\"";
-
     /** Grid logger. */
     @LoggerResource
     private IgniteLogger log;
@@ -102,13 +77,42 @@ public class TcpDiscoveryJdbcIpFinder extends TcpDiscoveryIpFinderAdapter {
     @GridToStringExclude
     private final CountDownLatch initLatch = new CountDownLatch(1);
 
+    /** Table name. */
+    private final String addrTableName;
+
+    /** Query to get addresses. */
+    private final String getAddrsQry;
+
+    /** Query to register address. */
+    private final String regAddrQry;
+
+    /** Query to unregister address. */
+    private final String unregAddrQry;
+
+    /** Query to create addresses table. */
+    private final String createAddrsTableQry;
+
+    /** Query to check database validity. */
+    private final String chkQry;
+
     /**
      * Constructor.
      */
     public TcpDiscoveryJdbcIpFinder() {
-        setShared(true);
+		this(new BasicJdbcIpFinderDialect());
     }
 
+	public TcpDiscoveryJdbcIpFinder(JdbcIpFinderDialect jdbcDialect) {
+		setShared(true);
+
+        this.addrTableName = jdbcDialect.tableName();
+        this.getAddrsQry = "select hostname, port from " + addrTableName;
+        this.regAddrQry = "insert into " + addrTableName + " values (?, ?)";
+        this.unregAddrQry = "delete from " + addrTableName + " where hostname = ? and port = ?";
+        this.createAddrsTableQry = "create table " + addrTableName + " (hostname VARCHAR(1024), port INT)";
+        this.chkQry = "select count(*) from " + addrTableName;
+	}
+
     /** {@inheritDoc} */
     @Override public Collection<InetSocketAddress> getRegisteredAddresses() throws IgniteSpiException {
         init();
@@ -124,7 +128,7 @@ public class TcpDiscoveryJdbcIpFinder extends TcpDiscoveryIpFinderAdapter {
 
             conn.setTransactionIsolation(TRANSACTION_READ_COMMITTED);
 
-            stmt = conn.prepareStatement(GET_ADDRS_QRY);
+            stmt = conn.prepareStatement(getAddrsQry);
 
             rs = stmt.executeQuery();
 
@@ -166,8 +170,8 @@ public class TcpDiscoveryJdbcIpFinder extends TcpDiscoveryIpFinderAdapter {
 
             conn.setTransactionIsolation(TRANSACTION_READ_COMMITTED);
 
-            stmtUnreg = conn.prepareStatement(UNREG_ADDR_QRY);
-            stmtReg = conn.prepareStatement(REG_ADDR_QRY);
+            stmtUnreg = conn.prepareStatement(unregAddrQry);
+            stmtReg = conn.prepareStatement(regAddrQry);
 
             for (InetSocketAddress addr : addrs) {
                 stmtUnreg.setString(1, addr.getAddress().getHostAddress());
@@ -225,7 +229,7 @@ public class TcpDiscoveryJdbcIpFinder extends TcpDiscoveryIpFinderAdapter {
 
             conn.setTransactionIsolation(TRANSACTION_READ_COMMITTED);
 
-            stmt = conn.prepareStatement(UNREG_ADDR_QRY);
+            stmt = conn.prepareStatement(unregAddrQry);
 
             for (InetSocketAddress addr : addrs) {
                 stmt.setString(1, addr.getAddress().getHostAddress());
@@ -313,12 +317,12 @@ public class TcpDiscoveryJdbcIpFinder extends TcpDiscoveryIpFinderAdapter {
                 // in the create statement which will check and create atomically.
                 // However not all databases support it, for example Oracle,
                 // so we do not use it.
-                try (ResultSet tables = dbm.getTables(null, null, ADDRS_TABLE_NAME, null)) {
+                try (ResultSet tables = dbm.getTables(null, null, addrTableName, null)) {
                     if (!tables.next()) {
                         // Table does not exist
                         // Create tbl_addrs.
                         try (Statement stmt = conn.createStatement()) {
-                            stmt.executeUpdate(CREATE_ADDRS_TABLE_QRY);
+                            stmt.executeUpdate(createAddrsTableQry);
 
                             conn.commit();
                         }
@@ -332,7 +336,7 @@ public class TcpDiscoveryJdbcIpFinder extends TcpDiscoveryIpFinderAdapter {
                             // exception, so the safest way to determine if this
                             // exception is to be ignored is to test again to
                             // see if the table has been created.
-                            try (ResultSet tablesAgain = dbm.getTables(null, null, ADDRS_TABLE_NAME, null)) {
+                            try (ResultSet tablesAgain = dbm.getTables(null, null, addrTableName, null)) {
                                 if (!tablesAgain.next())
                                     throw e;
                             }
@@ -388,7 +392,7 @@ public class TcpDiscoveryJdbcIpFinder extends TcpDiscoveryIpFinderAdapter {
             // Check if tbl_addrs exists and database initialized properly.
             stmt = conn.createStatement();
 
-            stmt.execute(CHK_QRY);
+            stmt.execute(chkQry);
         }
         catch (SQLException e) {
             throw new IgniteSpiException("IP finder has not been properly initialized.", e);