You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by yz...@apache.org on 2017/10/13 17:43:01 UTC
[16/50] [abbrv] ignite git commit: IGNITE-6457: JDBC thin driver: now
schema in URL string is case-insensitive by default. This closes #2712.
IGNITE-6457: JDBC thin driver: now schema in URL string is case-insensitive by default. This closes #2712.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/931320f6
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/931320f6
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/931320f6
Branch: refs/heads/ignite-2.1.5-p1
Commit: 931320f6ded6f927931c6dca2b9ed6795632365c
Parents: 3847b47
Author: tledkov-gridgain <tl...@gridgain.com>
Authored: Thu Sep 21 14:40:13 2017 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Thu Sep 21 14:41:30 2017 +0300
----------------------------------------------------------------------
.../jdbc/suite/IgniteJdbcDriverTestSuite.java | 2 +
.../jdbc/thin/JdbcThinConnectionSelfTest.java | 6 +-
.../jdbc/thin/JdbcThinNoDefaultSchemaTest.java | 6 +-
.../jdbc/thin/JdbcThinSchemaCaseTest.java | 129 +++++++++++++++++++
.../org/apache/ignite/IgniteJdbcThinDriver.java | 1 -
.../internal/jdbc/thin/JdbcThinConnection.java | 23 +++-
6 files changed, 159 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/931320f6/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java
index 3d3ef27..0bd86b3 100644
--- a/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java
+++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java
@@ -53,6 +53,7 @@ import org.apache.ignite.jdbc.thin.JdbcThinMissingLongArrayResultsTest;
import org.apache.ignite.jdbc.thin.JdbcThinNoDefaultSchemaTest;
import org.apache.ignite.jdbc.thin.JdbcThinPreparedStatementSelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinResultSetSelfTest;
+import org.apache.ignite.jdbc.thin.JdbcThinSchemaCaseTest;
import org.apache.ignite.jdbc.thin.JdbcThinStatementSelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinUpdateStatementSelfTest;
@@ -122,6 +123,7 @@ public class IgniteJdbcDriverTestSuite extends TestSuite {
suite.addTest(new TestSuite(JdbcThinStatementSelfTest.class));
suite.addTest(new TestSuite(JdbcThinComplexQuerySelfTest.class));
suite.addTest(new TestSuite(JdbcThinNoDefaultSchemaTest.class));
+ suite.addTest(new TestSuite(JdbcThinSchemaCaseTest.class));
suite.addTest(new TestSuite(JdbcThinEmptyCacheSelfTest.class));
suite.addTest(new TestSuite(JdbcThinMetadataSelfTest.class));
suite.addTest(new TestSuite(JdbcThinErrorsSelfTest.class));
http://git-wip-us.apache.org/repos/asf/ignite/blob/931320f6/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinConnectionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinConnectionSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinConnectionSelfTest.java
index 95068c5..17ce686 100644
--- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinConnectionSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinConnectionSelfTest.java
@@ -324,15 +324,15 @@ public class JdbcThinConnectionSelfTest extends JdbcThinAbstractSelfTest {
"Invalid URL format (only schema name is allowed in URL path parameter 'host:port[/schemaName]')" );
try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1/public")) {
- assertEquals("Invalid schema", "public", conn.getSchema());
+ assertEquals("Invalid schema", "PUBLIC", conn.getSchema());
}
- try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1/" + DEFAULT_CACHE_NAME)) {
+ try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1/\"" + DEFAULT_CACHE_NAME + '"')) {
assertEquals("Invalid schema", DEFAULT_CACHE_NAME, conn.getSchema());
}
try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1/_not_exist_schema_")) {
- assertEquals("Invalid schema", "_not_exist_schema_", conn.getSchema());
+ assertEquals("Invalid schema", "_NOT_EXIST_SCHEMA_", conn.getSchema());
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/931320f6/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinNoDefaultSchemaTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinNoDefaultSchemaTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinNoDefaultSchemaTest.java
index 65ebf9a..cab28f4 100644
--- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinNoDefaultSchemaTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinNoDefaultSchemaTest.java
@@ -161,7 +161,7 @@ public class JdbcThinNoDefaultSchemaTest extends JdbcThinAbstractSelfTest {
* @throws Exception If failed.
*/
public void testSchemaInUrl() throws Exception {
- try(Connection conn = DriverManager.getConnection(URL + "/cache1")) {
+ try(Connection conn = DriverManager.getConnection(URL + "/\"cache1\"")) {
Statement stmt = conn.createStatement();
stmt.execute("select t._key, t._val from Integer t");
@@ -172,7 +172,7 @@ public class JdbcThinNoDefaultSchemaTest extends JdbcThinAbstractSelfTest {
assertEquals(rs.getInt(2), rs.getInt(1) * 2);
}
- try(Connection conn = DriverManager.getConnection(URL + "/cache2")) {
+ try(Connection conn = DriverManager.getConnection(URL + "/\"cache2\"")) {
Statement stmt = conn.createStatement();
stmt.execute("select t._key, t._val from Integer t");
@@ -188,7 +188,7 @@ public class JdbcThinNoDefaultSchemaTest extends JdbcThinAbstractSelfTest {
* @throws Exception If failed.
*/
public void testSchemaInUrlAndInQuery() throws Exception {
- try(Connection conn = DriverManager.getConnection(URL + "/cache2")) {
+ try(Connection conn = DriverManager.getConnection(URL + "/\"cache2\"")) {
Statement stmt = conn.createStatement();
stmt.execute("select t._key, t._val, v._val " +
http://git-wip-us.apache.org/repos/asf/ignite/blob/931320f6/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinSchemaCaseTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinSchemaCaseTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinSchemaCaseTest.java
new file mode 100644
index 0000000..11416e5
--- /dev/null
+++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinSchemaCaseTest.java
@@ -0,0 +1,129 @@
+/*
+ * 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.jdbc.thin;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.concurrent.Callable;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ *
+ */
+public class JdbcThinSchemaCaseTest extends JdbcThinAbstractSelfTest {
+ /** IP finder. */
+ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /** URL. */
+ private static final String URL = "jdbc:ignite:thin://127.0.0.1";
+
+ /** Grid count. */
+ private static final int GRID_CNT = 2;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+ cfg.setCacheConfiguration(
+ cacheConfiguration("test0", "test0"),
+ cacheConfiguration("test1", "tEst1"),
+ cacheConfiguration("test2", "\"TestCase\""));
+
+ TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+ disco.setIpFinder(IP_FINDER);
+
+ cfg.setDiscoverySpi(disco);
+
+ return cfg;
+ }
+
+ /**
+ * @param name Cache name.
+ * @param schema Schema name.
+ * @return Cache configuration.
+ * @throws Exception In case of error.
+ */
+ @SuppressWarnings("unchecked")
+ private CacheConfiguration cacheConfiguration(@NotNull String name, @NotNull String schema) throws Exception {
+ CacheConfiguration cfg = defaultCacheConfiguration();
+
+ cfg.setIndexedTypes(Integer.class, Integer.class);
+
+ cfg.setName(name);
+
+ cfg.setSqlSchema(schema);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ startGridsMultiThreaded(GRID_CNT);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @SuppressWarnings({"EmptyTryBlock", "unused"})
+ public void testSchemaName() throws Exception {
+ checkSchemaConnection("test0");
+ checkSchemaConnection("test1");
+ checkSchemaConnection("\"TestCase\"");
+ checkSchemaConnection("\"TEST0\"");
+ checkSchemaConnection("\"TEST1\"");
+
+ GridTestUtils.assertThrows(log, new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ checkSchemaConnection("TestCase");
+
+ return null;
+ }
+ }, SQLException.class, null);
+ }
+
+ /**
+ * @param schema Schema name.
+ * @throws SQLException If failed.
+ */
+ void checkSchemaConnection(String schema) throws SQLException {
+ try (Connection conn = DriverManager.getConnection(URL + '/' + schema)) {
+ Statement stmt = conn.createStatement();
+
+ assertNotNull(stmt);
+ assertFalse(stmt.isClosed());
+
+ stmt.execute("select t._key, t._val from Integer t");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/931320f6/modules/core/src/main/java/org/apache/ignite/IgniteJdbcThinDriver.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteJdbcThinDriver.java b/modules/core/src/main/java/org/apache/ignite/IgniteJdbcThinDriver.java
index 423223c..8085ed4 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteJdbcThinDriver.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteJdbcThinDriver.java
@@ -26,7 +26,6 @@ import java.sql.SQLFeatureNotSupportedException;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
-import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.ignite.cache.affinity.AffinityKey;
import org.apache.ignite.internal.IgniteVersionUtils;
http://git-wip-us.apache.org/repos/asf/ignite/blob/931320f6/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java
index 511eba0..d804750 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java
@@ -43,6 +43,7 @@ import org.apache.ignite.internal.processors.odbc.SqlStateCode;
import org.apache.ignite.internal.processors.odbc.jdbc.JdbcRequest;
import org.apache.ignite.internal.processors.odbc.jdbc.JdbcResponse;
import org.apache.ignite.internal.processors.odbc.jdbc.JdbcResult;
+import org.apache.ignite.internal.processors.query.QueryUtils;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.lang.IgniteProductVersion;
@@ -119,7 +120,7 @@ public class JdbcThinConnection implements Connection {
autoCommit = true;
txIsolation = Connection.TRANSACTION_NONE;
- this.schema = schema == null ? "PUBLIC" : schema;
+ this.schema = normalizeSchema(schema);
String host = extractHost(props);
int port = extractPort(props);
@@ -799,4 +800,24 @@ public class JdbcThinConnection implements Connection {
public String url() {
return url;
}
+
+ /**
+ * Normalize schema name. If it is quoted - unquote and leave as is, otherwise - convert to upper case.
+ *
+ * @param schemaName Schema name.
+ * @return Normalized schema name.
+ */
+ private static String normalizeSchema(String schemaName) {
+ if (F.isEmpty(schemaName))
+ return QueryUtils.DFLT_SCHEMA;
+
+ String res;
+
+ if (schemaName.startsWith("\"") && schemaName.endsWith("\""))
+ res = schemaName.substring(1, schemaName.length() - 1);
+ else
+ res = schemaName.toUpperCase();
+
+ return res;
+ }
}
\ No newline at end of file