Repository: ignite Updated Branches: refs/heads/ignite-zk fcee8c846 -> 1f82a5311
IGNITE-6752: JDBC thin: connection properties refactoring. This closes #2927. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/69acdaaa Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/69acdaaa Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/69acdaaa Branch: refs/heads/ignite-zk Commit: 69acdaaaa3ef8bd5964f881707fc58d84bf8e5b4 Parents: 85027e7 Author: tledkov-gridgain <tled...@gridgain.com> Authored: Mon Nov 13 15:37:02 2017 +0300 Committer: devozerov <voze...@gridgain.com> Committed: Mon Nov 13 15:37:02 2017 +0300 ---------------------------------------------------------------------- .../thin/JdbcThinAutoCloseServerCursorTest.java | 4 +- .../jdbc/thin/JdbcThinConnectionSelfTest.java | 155 ++--- .../org/apache/ignite/IgniteJdbcDriver.java | 29 +- .../org/apache/ignite/IgniteJdbcThinDriver.java | 35 +- .../jdbc/thin/ConnectionProperties.java | 148 +++++ .../jdbc/thin/ConnectionPropertiesImpl.java | 637 +++++++++++++++++++ .../internal/jdbc/thin/JdbcThinConnection.java | 163 +---- .../internal/jdbc/thin/JdbcThinTcpIo.java | 195 ++---- .../internal/jdbc/thin/JdbcThinUtils.java | 79 +-- 9 files changed, 945 insertions(+), 500 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/69acdaaa/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinAutoCloseServerCursorTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinAutoCloseServerCursorTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinAutoCloseServerCursorTest.java index db4ed3f..943ca0e 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinAutoCloseServerCursorTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinAutoCloseServerCursorTest.java @@ -29,7 +29,6 @@ import org.apache.ignite.IgniteCache; import org.apache.ignite.cache.query.annotations.QuerySqlField; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.internal.jdbc.thin.JdbcThinUtils; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder; @@ -51,8 +50,7 @@ public class JdbcThinAutoCloseServerCursorTest extends JdbcThinAbstractSelfTest private static final String CACHE_NAME = "cache"; /** URL. */ - private static final String URL = "jdbc:ignite:thin://127.0.0.1/?" + - JdbcThinUtils.PARAM_AUTO_CLOSE_SERVER_CURSOR + "=true"; + private static final String URL = "jdbc:ignite:thin://127.0.0.1/?autoCloseServerCursor=true"; /** {@inheritDoc} */ @SuppressWarnings("unchecked") http://git-wip-us.apache.org/repos/asf/ignite/blob/69acdaaa/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 7f67136..0cf6ab6 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 @@ -135,9 +135,10 @@ public class JdbcThinConnectionSelfTest extends JdbcThinAbstractSelfTest { assertInvalid("jdbc:ignite:thin://:10000", "Host name is empty"); assertInvalid("jdbc:ignite:thin:// :10000", "Host name is empty"); - assertInvalid("jdbc:ignite:thin://127.0.0.1:-1", "Invalid port"); - assertInvalid("jdbc:ignite:thin://127.0.0.1:0", "Invalid port"); - assertInvalid("jdbc:ignite:thin://127.0.0.1:100000", "Invalid port"); + assertInvalid("jdbc:ignite:thin://127.0.0.1:-1", "Property cannot be lower than 1 [name=port, value=-1]"); + assertInvalid("jdbc:ignite:thin://127.0.0.1:0", "Property cannot be lower than 1 [name=port, value=0]"); + assertInvalid("jdbc:ignite:thin://127.0.0.1:100000", + "Property cannot be upper than 65535 [name=port, value=100000]"); } /** @@ -147,31 +148,31 @@ public class JdbcThinConnectionSelfTest extends JdbcThinAbstractSelfTest { */ public void testSocketBuffers() throws Exception { assertInvalid("jdbc:ignite:thin://127.0.0.1?socketSendBuffer=-1", - "Property cannot be negative [name=" + JdbcThinUtils.PARAM_SOCK_SND_BUF); + "Property cannot be lower than 0 [name=socketSendBuffer, value=-1]"); assertInvalid("jdbc:ignite:thin://127.0.0.1?socketReceiveBuffer=-1", - "Property cannot be negative [name=" + JdbcThinUtils.PARAM_SOCK_RCV_BUF); + "Property cannot be lower than 0 [name=socketReceiveBuffer, value=-1]"); try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1")) { - assertEquals(0, io(conn).socketSendBuffer()); - assertEquals(0, io(conn).socketReceiveBuffer()); + assertEquals(0, io(conn).connectionProperties().getSocketSendBuffer()); + assertEquals(0, io(conn).connectionProperties().getSocketReceiveBuffer()); } // Note that SO_* options are hints, so we check that value is equals to either what we set or to default. try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1?socketSendBuffer=1024")) { - assertEquals(1024, io(conn).socketSendBuffer()); - assertEquals(0, io(conn).socketReceiveBuffer()); + assertEquals(1024, io(conn).connectionProperties().getSocketSendBuffer()); + assertEquals(0, io(conn).connectionProperties().getSocketReceiveBuffer()); } try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1?socketReceiveBuffer=1024")) { - assertEquals(0, io(conn).socketSendBuffer()); - assertEquals(1024, io(conn).socketReceiveBuffer()); + assertEquals(0, io(conn).connectionProperties().getSocketSendBuffer()); + assertEquals(1024, io(conn).connectionProperties().getSocketReceiveBuffer()); } try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1?" + "socketSendBuffer=1024&socketReceiveBuffer=2048")) { - assertEquals(1024, io(conn).socketSendBuffer()); - assertEquals(2048, io(conn).socketReceiveBuffer()); + assertEquals(1024, io(conn).connectionProperties().getSocketSendBuffer()); + assertEquals(2048, io(conn).connectionProperties().getSocketReceiveBuffer()); } } @@ -182,76 +183,76 @@ public class JdbcThinConnectionSelfTest extends JdbcThinAbstractSelfTest { */ public void testSqlHints() throws Exception { try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1")) { - assertFalse(io(conn).distributedJoins()); - assertFalse(io(conn).enforceJoinOrder()); - assertFalse(io(conn).collocated()); - assertFalse(io(conn).replicatedOnly()); - assertFalse(io(conn).lazy()); - assertFalse(io(conn).skipReducerOnUpdate()); + assertFalse(io(conn).connectionProperties().isDistributedJoins()); + assertFalse(io(conn).connectionProperties().isEnforceJoinOrder()); + assertFalse(io(conn).connectionProperties().isCollocated()); + assertFalse(io(conn).connectionProperties().isReplicatedOnly()); + assertFalse(io(conn).connectionProperties().isLazy()); + assertFalse(io(conn).connectionProperties().isSkipReducerOnUpdate()); } try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1?distributedJoins=true")) { - assertTrue(io(conn).distributedJoins()); - assertFalse(io(conn).enforceJoinOrder()); - assertFalse(io(conn).collocated()); - assertFalse(io(conn).replicatedOnly()); - assertFalse(io(conn).lazy()); - assertFalse(io(conn).skipReducerOnUpdate()); + assertTrue(io(conn).connectionProperties().isDistributedJoins()); + assertFalse(io(conn).connectionProperties().isEnforceJoinOrder()); + assertFalse(io(conn).connectionProperties().isCollocated()); + assertFalse(io(conn).connectionProperties().isReplicatedOnly()); + assertFalse(io(conn).connectionProperties().isLazy()); + assertFalse(io(conn).connectionProperties().isSkipReducerOnUpdate()); } try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1?enforceJoinOrder=true")) { - assertFalse(io(conn).distributedJoins()); - assertTrue(io(conn).enforceJoinOrder()); - assertFalse(io(conn).collocated()); - assertFalse(io(conn).replicatedOnly()); - assertFalse(io(conn).lazy()); - assertFalse(io(conn).skipReducerOnUpdate()); + assertFalse(io(conn).connectionProperties().isDistributedJoins()); + assertTrue(io(conn).connectionProperties().isEnforceJoinOrder()); + assertFalse(io(conn).connectionProperties().isCollocated()); + assertFalse(io(conn).connectionProperties().isReplicatedOnly()); + assertFalse(io(conn).connectionProperties().isLazy()); + assertFalse(io(conn).connectionProperties().isSkipReducerOnUpdate()); } try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1?collocated=true")) { - assertFalse(io(conn).distributedJoins()); - assertFalse(io(conn).enforceJoinOrder()); - assertTrue(io(conn).collocated()); - assertFalse(io(conn).replicatedOnly()); - assertFalse(io(conn).lazy()); - assertFalse(io(conn).skipReducerOnUpdate()); + assertFalse(io(conn).connectionProperties().isDistributedJoins()); + assertFalse(io(conn).connectionProperties().isEnforceJoinOrder()); + assertTrue(io(conn).connectionProperties().isCollocated()); + assertFalse(io(conn).connectionProperties().isReplicatedOnly()); + assertFalse(io(conn).connectionProperties().isLazy()); + assertFalse(io(conn).connectionProperties().isSkipReducerOnUpdate()); } try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1?replicatedOnly=true")) { - assertFalse(io(conn).distributedJoins()); - assertFalse(io(conn).enforceJoinOrder()); - assertFalse(io(conn).collocated()); - assertTrue(io(conn).replicatedOnly()); - assertFalse(io(conn).lazy()); - assertFalse(io(conn).skipReducerOnUpdate()); + assertFalse(io(conn).connectionProperties().isDistributedJoins()); + assertFalse(io(conn).connectionProperties().isEnforceJoinOrder()); + assertFalse(io(conn).connectionProperties().isCollocated()); + assertTrue(io(conn).connectionProperties().isReplicatedOnly()); + assertFalse(io(conn).connectionProperties().isLazy()); + assertFalse(io(conn).connectionProperties().isSkipReducerOnUpdate()); } try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1?lazy=true")) { - assertFalse(io(conn).distributedJoins()); - assertFalse(io(conn).enforceJoinOrder()); - assertFalse(io(conn).collocated()); - assertFalse(io(conn).replicatedOnly()); - assertTrue(io(conn).lazy()); - assertFalse(io(conn).skipReducerOnUpdate()); + assertFalse(io(conn).connectionProperties().isDistributedJoins()); + assertFalse(io(conn).connectionProperties().isEnforceJoinOrder()); + assertFalse(io(conn).connectionProperties().isCollocated()); + assertFalse(io(conn).connectionProperties().isReplicatedOnly()); + assertTrue(io(conn).connectionProperties().isLazy()); + assertFalse(io(conn).connectionProperties().isSkipReducerOnUpdate()); } try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1?skipReducerOnUpdate=true")) { - assertFalse(io(conn).distributedJoins()); - assertFalse(io(conn).enforceJoinOrder()); - assertFalse(io(conn).collocated()); - assertFalse(io(conn).replicatedOnly()); - assertFalse(io(conn).lazy()); - assertTrue(io(conn).skipReducerOnUpdate()); + assertFalse(io(conn).connectionProperties().isDistributedJoins()); + assertFalse(io(conn).connectionProperties().isEnforceJoinOrder()); + assertFalse(io(conn).connectionProperties().isCollocated()); + assertFalse(io(conn).connectionProperties().isReplicatedOnly()); + assertFalse(io(conn).connectionProperties().isLazy()); + assertTrue(io(conn).connectionProperties().isSkipReducerOnUpdate()); } try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1?distributedJoins=true&" + "enforceJoinOrder=true&collocated=true&replicatedOnly=true&lazy=true&skipReducerOnUpdate=true")) { - assertTrue(io(conn).distributedJoins()); - assertTrue(io(conn).enforceJoinOrder()); - assertTrue(io(conn).collocated()); - assertTrue(io(conn).replicatedOnly()); - assertTrue(io(conn).lazy()); - assertTrue(io(conn).skipReducerOnUpdate()); + assertTrue(io(conn).connectionProperties().isDistributedJoins()); + assertTrue(io(conn).connectionProperties().isEnforceJoinOrder()); + assertTrue(io(conn).connectionProperties().isCollocated()); + assertTrue(io(conn).connectionProperties().isReplicatedOnly()); + assertTrue(io(conn).connectionProperties().isLazy()); + assertTrue(io(conn).connectionProperties().isSkipReducerOnUpdate()); } } @@ -262,35 +263,35 @@ public class JdbcThinConnectionSelfTest extends JdbcThinAbstractSelfTest { */ public void testTcpNoDelay() throws Exception { assertInvalid("jdbc:ignite:thin://127.0.0.1?tcpNoDelay=0", - "Failed to parse boolean property [name=" + JdbcThinUtils.PARAM_TCP_NO_DELAY); + "Failed to parse boolean property [name=tcpNoDelay, value=0]"); assertInvalid("jdbc:ignite:thin://127.0.0.1?tcpNoDelay=1", - "Failed to parse boolean property [name=" + JdbcThinUtils.PARAM_TCP_NO_DELAY); + "Failed to parse boolean property [name=tcpNoDelay, value=1]"); assertInvalid("jdbc:ignite:thin://127.0.0.1?tcpNoDelay=false1", - "Failed to parse boolean property [name=" + JdbcThinUtils.PARAM_TCP_NO_DELAY); + "Failed to parse boolean property [name=tcpNoDelay, value=false1]"); assertInvalid("jdbc:ignite:thin://127.0.0.1?tcpNoDelay=true1", - "Failed to parse boolean property [name=" + JdbcThinUtils.PARAM_TCP_NO_DELAY); + "Failed to parse boolean property [name=tcpNoDelay, value=true1]"); try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1")) { - assertTrue(io(conn).tcpNoDelay()); + assertTrue(io(conn).connectionProperties().isTcpNoDelay()); } try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1?tcpNoDelay=true")) { - assertTrue(io(conn).tcpNoDelay()); + assertTrue(io(conn).connectionProperties().isTcpNoDelay()); } try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1?tcpNoDelay=True")) { - assertTrue(io(conn).tcpNoDelay()); + assertTrue(io(conn).connectionProperties().isTcpNoDelay()); } try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1?tcpNoDelay=false")) { - assertFalse(io(conn).tcpNoDelay()); + assertFalse(io(conn).connectionProperties().isTcpNoDelay()); } try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1?tcpNoDelay=False")) { - assertFalse(io(conn).tcpNoDelay()); + assertFalse(io(conn).connectionProperties().isTcpNoDelay()); } } @@ -300,9 +301,9 @@ public class JdbcThinConnectionSelfTest extends JdbcThinAbstractSelfTest { * @throws Exception If failed. */ public void testAutoCloseServerCursorProperty() throws Exception { - String url = "jdbc:ignite:thin://127.0.0.1?" + JdbcThinUtils.PARAM_AUTO_CLOSE_SERVER_CURSOR; + String url = "jdbc:ignite:thin://127.0.0.1?autoCloseServerCursor"; - String err = "Failed to parse boolean property [name=" + JdbcThinUtils.PARAM_AUTO_CLOSE_SERVER_CURSOR; + String err = "Failed to parse boolean property [name=autoCloseServerCursor"; assertInvalid(url + "=0", err); assertInvalid(url + "=1", err); @@ -310,23 +311,23 @@ public class JdbcThinConnectionSelfTest extends JdbcThinAbstractSelfTest { assertInvalid(url + "=true1", err); try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1")) { - assertFalse(io(conn).autoCloseServerCursor()); + assertFalse(io(conn).connectionProperties().isAutoCloseServerCursor()); } try (Connection conn = DriverManager.getConnection(url + "=true")) { - assertTrue(io(conn).autoCloseServerCursor()); + assertTrue(io(conn).connectionProperties().isAutoCloseServerCursor()); } try (Connection conn = DriverManager.getConnection(url + "=True")) { - assertTrue(io(conn).autoCloseServerCursor()); + assertTrue(io(conn).connectionProperties().isAutoCloseServerCursor()); } try (Connection conn = DriverManager.getConnection(url + "=false")) { - assertFalse(io(conn).autoCloseServerCursor()); + assertFalse(io(conn).connectionProperties().isAutoCloseServerCursor()); } try (Connection conn = DriverManager.getConnection(url + "=False")) { - assertFalse(io(conn).autoCloseServerCursor()); + assertFalse(io(conn).connectionProperties().isAutoCloseServerCursor()); } } http://git-wip-us.apache.org/repos/asf/ignite/blob/69acdaaa/modules/core/src/main/java/org/apache/ignite/IgniteJdbcDriver.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteJdbcDriver.java b/modules/core/src/main/java/org/apache/ignite/IgniteJdbcDriver.java index ea9b7f8..8195bd4 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgniteJdbcDriver.java +++ b/modules/core/src/main/java/org/apache/ignite/IgniteJdbcDriver.java @@ -30,7 +30,6 @@ import java.util.logging.Logger; import org.apache.ignite.cache.affinity.AffinityKey; import org.apache.ignite.internal.jdbc.JdbcConnection; import org.apache.ignite.internal.jdbc.JdbcDriverPropertyInfo; -import org.apache.ignite.internal.jdbc.thin.JdbcThinUtils; import org.apache.ignite.logger.java.JavaLogger; /** @@ -304,12 +303,6 @@ public class IgniteJdbcDriver implements Driver { /** Collocated parameter name. */ private static final String PARAM_COLLOCATED = "collocated"; - /** Parameter: enforce join order flag. */ - public static final String PARAM_ENFORCE_JOIN_ORDER = "enforceJoinOrder"; - - /** Parameter: lazy query execution flag. */ - public static final String PARAM_LAZY = "lazy"; - /** Distributed joins parameter name. */ private static final String PARAM_DISTRIBUTED_JOINS = "distributedJoins"; @@ -337,6 +330,12 @@ public class IgniteJdbcDriver implements Driver { /** Skip reducer on update property name. */ private static final String PARAM_SKIP_REDUCER_ON_UPDATE = "skipReducerOnUpdate"; + /** Parameter: enforce join order flag (SQL hint). */ + public static final String PARAM_ENFORCE_JOIN_ORDER = "enforceJoinOrder"; + + /** Parameter: replicated only flag (SQL hint). */ + public static final String PARAM_LAZY = "lazy"; + /** Hostname property name. */ public static final String PROP_HOST = PROP_PREFIX + "host"; @@ -358,12 +357,6 @@ public class IgniteJdbcDriver implements Driver { /** Distributed joins property name. */ public static final String PROP_DISTRIBUTED_JOINS = PROP_PREFIX + PARAM_DISTRIBUTED_JOINS; - /** Enforce join order property name. */ - public static final String PROP_ENFORCE_JOIN_ORDER = PROP_PREFIX + PARAM_ENFORCE_JOIN_ORDER; - - /** Lazy query execution property name. */ - public static final String PROP_LAZY = PROP_PREFIX + PARAM_LAZY; - /** Transactions allowed property name. */ public static final String PROP_TX_ALLOWED = PROP_PREFIX + PARAM_TX_ALLOWED; @@ -388,6 +381,12 @@ public class IgniteJdbcDriver implements Driver { /** Skip reducer on update update property name. */ public static final String PROP_SKIP_REDUCER_ON_UPDATE = PROP_PREFIX + PARAM_SKIP_REDUCER_ON_UPDATE; + /** Transactions allowed property name. */ + public static final String PROP_ENFORCE_JOIN_ORDER = PROP_PREFIX + PARAM_ENFORCE_JOIN_ORDER; + + /** Lazy property name. */ + public static final String PROP_LAZY = PROP_PREFIX + PARAM_LAZY; + /** Cache name property name. */ public static final String PROP_CFG = PROP_PREFIX + "cfg"; @@ -457,8 +456,8 @@ public class IgniteJdbcDriver implements Driver { new JdbcDriverPropertyInfo("Local", info.getProperty(PROP_LOCAL), ""), new JdbcDriverPropertyInfo("Collocated", info.getProperty(PROP_COLLOCATED), ""), new JdbcDriverPropertyInfo("Distributed Joins", info.getProperty(PROP_DISTRIBUTED_JOINS), ""), - new JdbcDriverPropertyInfo("Enforce Join Order", info.getProperty(JdbcThinUtils.PROP_ENFORCE_JOIN_ORDER), ""), - new JdbcDriverPropertyInfo("Lazy query execution", info.getProperty(JdbcThinUtils.PROP_LAZY), ""), + new JdbcDriverPropertyInfo("Enforce Join Order", info.getProperty(PROP_ENFORCE_JOIN_ORDER), ""), + new JdbcDriverPropertyInfo("Lazy query execution", info.getProperty(PROP_LAZY), ""), new JdbcDriverPropertyInfo("Transactions Allowed", info.getProperty(PROP_TX_ALLOWED), ""), new JdbcDriverPropertyInfo("Queries with multiple statements allowed", info.getProperty(PROP_MULTIPLE_STMTS), ""), new JdbcDriverPropertyInfo("Skip reducer on update", info.getProperty(PROP_SKIP_REDUCER_ON_UPDATE), "") http://git-wip-us.apache.org/repos/asf/ignite/blob/69acdaaa/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 a313f92..03f126f 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgniteJdbcThinDriver.java +++ b/modules/core/src/main/java/org/apache/ignite/IgniteJdbcThinDriver.java @@ -23,17 +23,17 @@ import java.sql.DriverManager; import java.sql.DriverPropertyInfo; import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; -import java.util.Arrays; -import java.util.List; import java.util.Properties; import java.util.logging.Logger; import org.apache.ignite.cache.affinity.AffinityKey; import org.apache.ignite.internal.IgniteVersionUtils; -import org.apache.ignite.internal.jdbc.JdbcDriverPropertyInfo; +import org.apache.ignite.internal.jdbc.thin.ConnectionPropertiesImpl; import org.apache.ignite.internal.jdbc.thin.JdbcThinConnection; import org.apache.ignite.internal.jdbc.thin.JdbcThinUtils; import org.apache.ignite.internal.util.typedef.F; +import static org.apache.ignite.internal.jdbc.thin.ConnectionPropertiesImpl.PROP_PREFIX; + /** * JDBC driver thin implementation for In-Memory Data Grid. * <p> @@ -130,18 +130,6 @@ import org.apache.ignite.internal.util.typedef.F; */ @SuppressWarnings("JavadocReference") public class IgniteJdbcThinDriver implements Driver { - /* - * Static initializer. - */ - static { - try { - DriverManager.registerDriver(new IgniteJdbcThinDriver()); - } - catch (SQLException e) { - throw new RuntimeException("Failed to register " + IgniteJdbcThinDriver.class.getName(), e); - } - } - /** Major version. */ private static final int MAJOR_VER = IgniteVersionUtils.VER.major(); @@ -167,7 +155,7 @@ public class IgniteJdbcThinDriver implements Driver { String schema = parseUrl(url, props); - return new JdbcThinConnection(url, props, schema); + return new JdbcThinConnection(url, schema, props); } /** {@inheritDoc} */ @@ -179,18 +167,7 @@ public class IgniteJdbcThinDriver implements Driver { @Override public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { parseUrl(url, info); - List<DriverPropertyInfo> props = Arrays.<DriverPropertyInfo>asList( - new JdbcDriverPropertyInfo("Hostname", info.getProperty(JdbcThinUtils.PROP_HOST), ""), - new JdbcDriverPropertyInfo("Port number", info.getProperty(JdbcThinUtils.PROP_PORT), ""), - new JdbcDriverPropertyInfo("Distributed Joins", info.getProperty(JdbcThinUtils.PROP_DISTRIBUTED_JOINS), ""), - new JdbcDriverPropertyInfo("Enforce Join Order", info.getProperty(JdbcThinUtils.PROP_ENFORCE_JOIN_ORDER), ""), - new JdbcDriverPropertyInfo("Collocated", info.getProperty(JdbcThinUtils.PROP_COLLOCATED), ""), - new JdbcDriverPropertyInfo("Replicated only", info.getProperty(JdbcThinUtils.PROP_REPLICATED_ONLY), ""), - new JdbcDriverPropertyInfo("Lazy query execution flag", info.getProperty(JdbcThinUtils.PROP_LAZY),""), - new JdbcDriverPropertyInfo("Skip reducer on update", info.getProperty(JdbcThinUtils.PROP_SKIP_REDUCER_ON_UPDATE),"") - ); - - return props.toArray(new DriverPropertyInfo[0]); + return ConnectionPropertiesImpl.getDriverPropertyInfo(info); } /** {@inheritDoc} */ @@ -285,7 +262,7 @@ public class IgniteJdbcThinDriver implements Driver { if (key.isEmpty() || val.isEmpty()) throw new SQLException("Invalid parameter format (key and value cannot be empty): " + param); - props.setProperty(JdbcThinUtils.PROP_PREFIX + key, val); + props.setProperty(PROP_PREFIX + key, val); } } } http://git-wip-us.apache.org/repos/asf/ignite/blob/69acdaaa/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionProperties.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionProperties.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionProperties.java new file mode 100644 index 0000000..d793484 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionProperties.java @@ -0,0 +1,148 @@ +/* + * 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.internal.jdbc.thin; + +import java.sql.SQLException; + +/** + * Provide access and manipulations with connection JDBC properties. + */ +public interface ConnectionProperties { + /** + * @return Host name or host's IP to connect. + */ + public String getHost(); + + /** + * @param host Host name or host's IP to connect. + */ + public void setHost(String host); + + /** + * @return Port to connect. + */ + public int getPort(); + + /** + * @param port Port to connect. + * @throws SQLException On error. + */ + public void setPort(int port) throws SQLException; + + /** + * @return Distributed joins flag. + */ + public boolean isDistributedJoins(); + + /** + * @param distributedJoins Distributed joins flag. + */ + public void setDistributedJoins(boolean distributedJoins); + + /** + * @return Enforce join order flag. + */ + public boolean isEnforceJoinOrder(); + + /** + * @param enforceJoinOrder Enforce join order flag. + */ + public void setEnforceJoinOrder(boolean enforceJoinOrder); + + /** + * @return Collocated flag. + */ + public boolean isCollocated(); + + /** + * @param collocated Collocated flag. + */ + public void setCollocated(boolean collocated); + + /** + * @return Replicated only flag. + */ + public boolean isReplicatedOnly(); + + /** + * @param replicatedOnly Replicated only flag. + */ + public void setReplicatedOnly(boolean replicatedOnly); + + /** + * @return Auto close server cursors flag. + */ + public boolean isAutoCloseServerCursor(); + + /** + * @param autoCloseServerCursor Auto close server cursors flag. + */ + public void setAutoCloseServerCursor(boolean autoCloseServerCursor); + + /** + * @return Socket send buffer size. + */ + public int getSocketSendBuffer(); + + /** + * @param size Socket send buffer size. + * @throws SQLException On error. + */ + public void setSocketSendBuffer(int size) throws SQLException; + + /** + * @return Socket receive buffer size. + */ + public int getSocketReceiveBuffer(); + + /** + * @param size Socket receive buffer size. + * @throws SQLException On error. + */ + public void setSocketReceiveBuffer(int size) throws SQLException; + + /** + * @return TCP no delay flag. + */ + public boolean isTcpNoDelay(); + + /** + * @param tcpNoDelay TCP no delay flag. + */ + public void setTcpNoDelay(boolean tcpNoDelay); + + /** + * @return Lazy query execution flag. + */ + public boolean isLazy(); + + /** + * @param lazy Lazy query execution flag. + */ + public void setLazy(boolean lazy); + + /** + * @return Skip reducer on update flag. + */ + public boolean isSkipReducerOnUpdate(); + + /** + * @param skipReducerOnUpdate Skip reducer on update flag. + */ + public void setSkipReducerOnUpdate(boolean skipReducerOnUpdate); +} http://git-wip-us.apache.org/repos/asf/ignite/blob/69acdaaa/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionPropertiesImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionPropertiesImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionPropertiesImpl.java new file mode 100644 index 0000000..86ba2fa --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionPropertiesImpl.java @@ -0,0 +1,637 @@ +/* + * 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.internal.jdbc.thin; + +import java.io.Serializable; +import java.sql.DriverPropertyInfo; +import java.sql.SQLException; +import java.util.Properties; +import javax.naming.RefAddr; +import javax.naming.Reference; +import org.apache.ignite.configuration.ClientConnectorConfiguration; +import org.apache.ignite.internal.processors.odbc.SqlStateCode; +import org.apache.ignite.internal.util.typedef.F; + +/** + * Holds JDBC connection properties. + */ +public class ConnectionPropertiesImpl implements ConnectionProperties, Serializable { + /** */ + private static final long serialVersionUID = 0L; + + /** Prefix for property names. */ + public static final String PROP_PREFIX = "ignite.jdbc."; + + /** Host name property. */ + private StringProperty host = new StringProperty( + "host", "Ignite node IP to connect", null, null, true, new PropertyValidator() { + private static final long serialVersionUID = 0L; + + @Override public void validate(String host) throws SQLException { + if (F.isEmpty(host)) + throw new SQLException("Host name is empty", SqlStateCode.CLIENT_CONNECTION_FAILED); + } + }); + + /** Connection port property. */ + private IntegerProperty port = new IntegerProperty( + "port", "Ignite node IP to connect", ClientConnectorConfiguration.DFLT_PORT, false, 1, 0xFFFF); + + /** Distributed joins property. */ + private BooleanProperty distributedJoins = new BooleanProperty( + "distributedJoins", "Enable distributed joins", false, false); + + /** Enforce join order property. */ + private BooleanProperty enforceJoinOrder = new BooleanProperty( + "enforceJoinOrder", "Enable enforce join order", false, false); + + /** Collocated property. */ + private BooleanProperty collocated = new BooleanProperty( + "collocated", "Enable collocated query", false, false); + + /** Replicated only property. */ + private BooleanProperty replicatedOnly = new BooleanProperty( + "replicatedOnly", "Specify if the all queries contain only replicated tables", false, false); + + /** Auto close server cursor property. */ + private BooleanProperty autoCloseServerCursor = new BooleanProperty( + "autoCloseServerCursor", "Enable auto close server cursors when last piece of result set is retrieved. " + + "If the server-side cursor is already closed, you may get an exception when trying to call " + + "`ResultSet.getMetadata()` method.", false, false); + + /** TCP no delay property. */ + private BooleanProperty tcpNoDelay = new BooleanProperty( + "tcpNoDelay", "TCP no delay flag", true, false); + + /** Lazy query execution property. */ + private BooleanProperty lazy = new BooleanProperty( + "lazy", "Enable lazy query execution", false, false); + + /** Socket send buffer size property. */ + private IntegerProperty socketSendBuffer = new IntegerProperty( + "socketSendBuffer", "Socket send buffer size", + 0, false, 0, Integer.MAX_VALUE); + + /** Socket receive buffer size property. */ + private IntegerProperty socketReceiveBuffer = new IntegerProperty( + "socketReceiveBuffer", "Socket send buffer size", + 0, false, 0, Integer.MAX_VALUE); + + /** Executes update queries on ignite server nodes flag. */ + private BooleanProperty skipReducerOnUpdate = new BooleanProperty( + "skipReducerOnUpdate", "Enable execution update queries on ignite server nodes", false, false); + + /** Properties array. */ + private final ConnectionProperty [] propsArray = { + host, port, + distributedJoins, enforceJoinOrder, collocated, replicatedOnly, autoCloseServerCursor, + tcpNoDelay, lazy, socketSendBuffer, socketReceiveBuffer, skipReducerOnUpdate + }; + + /** {@inheritDoc} */ + @Override public String getHost() { + return host.value(); + } + + /** {@inheritDoc} */ + @Override public void setHost(String host) { + this.host.setValue(host); + } + + /** {@inheritDoc} */ + @Override public int getPort() { + return port.value(); + } + + /** {@inheritDoc} */ + @Override public void setPort(int port) throws SQLException { + this.port.setValue(port); + } + + /** {@inheritDoc} */ + @Override public boolean isDistributedJoins() { + return distributedJoins.value(); + } + + /** {@inheritDoc} */ + @Override public void setDistributedJoins(boolean val) { + distributedJoins.setValue(val); + } + + /** {@inheritDoc} */ + @Override public boolean isEnforceJoinOrder() { + return enforceJoinOrder.value(); + } + + /** {@inheritDoc} */ + @Override public void setEnforceJoinOrder(boolean val) { + enforceJoinOrder.setValue(val); + } + + /** {@inheritDoc} */ + @Override public boolean isCollocated() { + return collocated.value(); + } + + /** {@inheritDoc} */ + @Override public void setCollocated(boolean val) { + collocated.setValue(val); + } + + /** {@inheritDoc} */ + @Override public boolean isReplicatedOnly() { + return replicatedOnly.value(); + } + + /** {@inheritDoc} */ + @Override public void setReplicatedOnly(boolean val) { + replicatedOnly.setValue(val); + } + + /** {@inheritDoc} */ + @Override public boolean isAutoCloseServerCursor() { + return autoCloseServerCursor.value(); + } + + /** {@inheritDoc} */ + @Override public void setAutoCloseServerCursor(boolean val) { + autoCloseServerCursor.setValue(val); + } + + /** {@inheritDoc} */ + @Override public int getSocketSendBuffer() { + return socketSendBuffer.value(); + } + + /** {@inheritDoc} */ + @Override public void setSocketSendBuffer(int size) throws SQLException { + socketSendBuffer.setValue(size); + } + + /** {@inheritDoc} */ + @Override public int getSocketReceiveBuffer() { + return socketReceiveBuffer.value(); + } + + /** {@inheritDoc} */ + @Override public void setSocketReceiveBuffer(int size) throws SQLException { + socketReceiveBuffer.setValue(size); + } + + /** {@inheritDoc} */ + @Override public boolean isTcpNoDelay() { + return tcpNoDelay.value(); + } + + /** {@inheritDoc} */ + @Override public void setTcpNoDelay(boolean val) { + tcpNoDelay.setValue(val); + } + + /** {@inheritDoc} */ + @Override public boolean isLazy() { + return lazy.value(); + } + + /** {@inheritDoc} */ + @Override public void setLazy(boolean val) { + lazy.setValue(val); + } + + /** {@inheritDoc} */ + @Override public boolean isSkipReducerOnUpdate() { + return skipReducerOnUpdate.value(); + } + + /** {@inheritDoc} */ + @Override public void setSkipReducerOnUpdate(boolean val) { + skipReducerOnUpdate.setValue(val); + } + + /** + * @param props Environment properties. + * @throws SQLException On error. + */ + void init(Properties props) throws SQLException { + Properties props0 = (Properties)props.clone(); + + for (ConnectionProperty aPropsArray : propsArray) + aPropsArray.init(props0); + } + + /** + * @return Driver's properties info array. + */ + private DriverPropertyInfo[] getDriverPropertyInfo() { + DriverPropertyInfo[] dpis = new DriverPropertyInfo[propsArray.length]; + + for (int i = 0; i < propsArray.length; ++i) + dpis[i] = propsArray[i].getDriverPropertyInfo(); + + return dpis; + } + + /** + * @param props Environment properties. + * @return Driver's properties info array. + * @throws SQLException On error. + */ + public static DriverPropertyInfo[] getDriverPropertyInfo(Properties props) throws SQLException { + ConnectionPropertiesImpl cpi = new ConnectionPropertiesImpl(); + + cpi.init(props); + + return cpi.getDriverPropertyInfo(); + } + + /** + * + */ + private interface PropertyValidator extends Serializable { + /** + * @param val String representation of the property value to validate. + * @throws SQLException On validation fails. + */ + void validate(String val) throws SQLException; + } + + /** + * + */ + private abstract static class ConnectionProperty implements Serializable { + /** */ + private static final long serialVersionUID = 0L; + + /** Name. */ + protected String name; + + /** Property description. */ + protected String desc; + + /** Default value. */ + protected Object dfltVal; + + /** + * An array of possible values if the value may be selected + * from a particular set of values; otherwise null. + */ + protected String [] choices; + + /** Required flag. */ + protected boolean required; + + /** Property validator. */ + protected PropertyValidator validator; + + /** + * @param name Name. + * @param desc Description. + * @param dfltVal Default value. + * @param choices Possible values. + * @param required {@code true} if the property is required. + */ + ConnectionProperty(String name, String desc, Object dfltVal, String[] choices, boolean required) { + this.name = name; + this.desc= desc; + this.dfltVal = dfltVal; + this.choices = choices; + this.required = required; + } + + /** + * @param name Name. + * @param desc Description. + * @param dfltVal Default value. + * @param choices Possible values. + * @param required {@code true} if the property is required. + * @param validator Property validator. + */ + ConnectionProperty(String name, String desc, Object dfltVal, String[] choices, boolean required, + PropertyValidator validator) { + this.name = name; + this.desc= desc; + this.dfltVal = dfltVal; + this.choices = choices; + this.required = required; + this.validator = validator; + } + + /** + * @return Default value. + */ + Object getDfltVal() { + return dfltVal; + } + + /** + * @return Property name. + */ + String getName() { + return name; + } + + /** + * @return Array of possible values if the value may be selected + * from a particular set of values; otherwise null + */ + String[] choices() { + return choices; + } + + /** + * @param props Properties. + * @throws SQLException On error. + */ + void init(Properties props) throws SQLException { + String strVal = props.getProperty(PROP_PREFIX + name); + + if (required && strVal == null) { + throw new SQLException("Property '" + name + "' is required but not defined", + SqlStateCode.CLIENT_CONNECTION_FAILED); + } + + if (validator != null) + validator.validate(strVal); + + props.remove(name); + + init(strVal); + } + + /** + * @param ref Reference object. + * @throws SQLException On error. + */ + void init(Reference ref) throws SQLException { + RefAddr refAddr = ref.get(name); + + if (refAddr != null) { + String str = (String) refAddr.getContent(); + + if (validator != null) + validator.validate(str); + + init(str); + } + } + + /** + * @param str String representation of the + * @throws SQLException on error. + */ + abstract void init(String str) throws SQLException; + + /** + * @return String representation of the property value. + */ + abstract String valueObject(); + + /** + * @return JDBC property info object. + */ + DriverPropertyInfo getDriverPropertyInfo() { + DriverPropertyInfo dpi = new DriverPropertyInfo(name, valueObject()); + + dpi.choices = choices(); + dpi.required = required; + dpi.description = desc; + + return dpi; + } + } + + /** + * + */ + private static class BooleanProperty extends ConnectionProperty { + /** */ + private static final long serialVersionUID = 0L; + + /** Bool choices. */ + private static final String [] boolChoices = new String[] {Boolean.TRUE.toString(), Boolean.FALSE.toString()}; + + /** Value. */ + private boolean val; + + /** + * @param name Name. + * @param desc Description. + * @param dfltVal Default value. + * @param required {@code true} if the property is required. + */ + BooleanProperty(String name, String desc, boolean dfltVal, boolean required) { + super(name, desc, dfltVal, boolChoices, required); + + val = dfltVal; + } + + /** + * @return Property value. + */ + boolean value() { + return val; + } + + /** {@inheritDoc} */ + @Override void init(String str) throws SQLException { + if (str == null) + val = (Boolean)dfltVal; + else { + if (Boolean.TRUE.toString().equalsIgnoreCase(str)) + val = true; + else if (Boolean.FALSE.toString().equalsIgnoreCase(str)) + val = false; + else + throw new SQLException("Failed to parse boolean property [name=" + name + + ", value=" + str + ']', SqlStateCode.CLIENT_CONNECTION_FAILED); + } + } + + /** {@inheritDoc} */ + @Override String valueObject() { + return Boolean.toString(val); + } + + /** + * @param val Property value to set. + */ + void setValue(boolean val) { + this.val = val; + } + } + + /** + * + */ + private abstract static class NumberProperty extends ConnectionProperty { + /** */ + private static final long serialVersionUID = 0L; + + /** Value. */ + protected Number val; + + /** Allowed value range. */ + private Number [] range; + + /** + * @param name Name. + * @param desc Description. + * @param dfltVal Default value. + * @param required {@code true} if the property is required. + * @param min Lower bound of allowed range. + * @param max Upper bound of allowed range. + */ + NumberProperty(String name, String desc, Number dfltVal, boolean required, Number min, Number max) { + super(name, desc, dfltVal, null, required); + + assert dfltVal != null; + + val = dfltVal; + + range = new Number[] {min, max}; + } + + /** {@inheritDoc} */ + @Override void init(String str) throws SQLException { + if (str == null) + val = (int)dfltVal; + else { + try { + setValue(parse(str)); + } catch (NumberFormatException e) { + throw new SQLException("Failed to parse int property [name=" + name + + ", value=" + str + ']', SqlStateCode.CLIENT_CONNECTION_FAILED); + } + } + } + + /** + * @param str String value. + * @return Number value. + * @throws NumberFormatException On parse error. + */ + protected abstract Number parse(String str) throws NumberFormatException; + + /** {@inheritDoc} */ + @Override String valueObject() { + return String.valueOf(val); + } + + /** + * @param val Property value. + * @throws SQLException On error. + */ + void setValue(Number val) throws SQLException { + if (range != null) { + if (val.doubleValue() < range[0].doubleValue()) { + throw new SQLException("Property cannot be lower than " + range[0].toString() + " [name=" + name + + ", value=" + val.toString() + ']', SqlStateCode.CLIENT_CONNECTION_FAILED); + } + + if (val.doubleValue() > range[1].doubleValue()) { + throw new SQLException("Property cannot be upper than " + range[1].toString() + " [name=" + name + + ", value=" + val.toString() + ']', SqlStateCode.CLIENT_CONNECTION_FAILED); + } + } + + this.val = val; + } + } + + /** + * + */ + private static class IntegerProperty extends NumberProperty { + /** */ + private static final long serialVersionUID = 0L; + + /** + * @param name Name. + * @param desc Description. + * @param dfltVal Default value. + * @param required {@code true} if the property is required. + * @param min Lower bound of allowed range. + * @param max Upper bound of allowed range. + */ + IntegerProperty(String name, String desc, Number dfltVal, boolean required, int min, int max) { + super(name, desc, dfltVal, required, min, max); + } + + /** {@inheritDoc} */ + @Override protected Number parse(String str) throws NumberFormatException { + return Integer.parseInt(str); + } + + /** + * @return Property value. + */ + int value() { + return val.intValue(); + } + } + + /** + * + */ + private static class StringProperty extends ConnectionProperty { + /** */ + private static final long serialVersionUID = 0L; + + /** Value */ + private String val; + + /** + * @param name Name. + * @param desc Description. + * @param dfltVal Default value. + * @param choices Possible values. + * @param required {@code true} if the property is required. + * @param validator Property value validator. + */ + StringProperty(String name, String desc, String dfltVal, String [] choices, boolean required, + PropertyValidator validator) { + super(name, desc, dfltVal, choices, required, validator); + + val = dfltVal; + } + + /** + * @param val Property value. + */ + void setValue(String val) { + this.val = val; + } + + /** + * @return Property value. + */ + String value() { + return val; + } + + /** {@inheritDoc} */ + @Override void init(String str) throws SQLException { + val = str; + } + + /** {@inheritDoc} */ + @Override String valueObject() { + return val; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/69acdaaa/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 57b25e1..999c793 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 @@ -51,18 +51,6 @@ import static java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT; import static java.sql.ResultSet.CONCUR_READ_ONLY; import static java.sql.ResultSet.HOLD_CURSORS_OVER_COMMIT; import static java.sql.ResultSet.TYPE_FORWARD_ONLY; -import static org.apache.ignite.internal.jdbc.thin.JdbcThinUtils.PROP_AUTO_CLOSE_SERVER_CURSORS; -import static org.apache.ignite.internal.jdbc.thin.JdbcThinUtils.PROP_COLLOCATED; -import static org.apache.ignite.internal.jdbc.thin.JdbcThinUtils.PROP_DISTRIBUTED_JOINS; -import static org.apache.ignite.internal.jdbc.thin.JdbcThinUtils.PROP_ENFORCE_JOIN_ORDER; -import static org.apache.ignite.internal.jdbc.thin.JdbcThinUtils.PROP_HOST; -import static org.apache.ignite.internal.jdbc.thin.JdbcThinUtils.PROP_LAZY; -import static org.apache.ignite.internal.jdbc.thin.JdbcThinUtils.PROP_PORT; -import static org.apache.ignite.internal.jdbc.thin.JdbcThinUtils.PROP_REPLICATED_ONLY; -import static org.apache.ignite.internal.jdbc.thin.JdbcThinUtils.PROP_SOCK_RCV_BUF; -import static org.apache.ignite.internal.jdbc.thin.JdbcThinUtils.PROP_SOCK_SND_BUF; -import static org.apache.ignite.internal.jdbc.thin.JdbcThinUtils.PROP_TCP_NO_DELAY; -import static org.apache.ignite.internal.jdbc.thin.JdbcThinUtils.PROP_SKIP_REDUCER_ON_UPDATE; /** * JDBC connection implementation. @@ -103,53 +91,42 @@ public class JdbcThinConnection implements Connection { /** Jdbc metadata. Cache the JDBC object on the first access */ private JdbcThinDatabaseMetadata metadata; + /** Connection properties. */ + private ConnectionProperties connProps; + /** * Creates new connection. * * @param url Connection URL. - * @param props Additional properties. * @param schema Schema name. + * @param props Connection properties. * @throws SQLException In case Ignite client failed to start. */ - public JdbcThinConnection(String url, Properties props, String schema) throws SQLException { + public JdbcThinConnection(String url, String schema, Properties props) throws SQLException { assert url != null; - assert props != null; this.url = url; + connProps = new ConnectionPropertiesImpl(); + + ((ConnectionPropertiesImpl)connProps).init(props); + holdability = HOLD_CURSORS_OVER_COMMIT; autoCommit = true; txIsolation = Connection.TRANSACTION_NONE; this.schema = normalizeSchema(schema); - String host = extractHost(props); - int port = extractPort(props); - - boolean distributedJoins = extractBoolean(props, PROP_DISTRIBUTED_JOINS, false); - boolean enforceJoinOrder = extractBoolean(props, PROP_ENFORCE_JOIN_ORDER, false); - boolean collocated = extractBoolean(props, PROP_COLLOCATED, false); - boolean replicatedOnly = extractBoolean(props, PROP_REPLICATED_ONLY, false); - boolean autoCloseServerCursor = extractBoolean(props, PROP_AUTO_CLOSE_SERVER_CURSORS, false); - boolean lazyExec = extractBoolean(props, PROP_LAZY, false); - - int sockSndBuf = extractIntNonNegative(props, PROP_SOCK_SND_BUF, 0); - int sockRcvBuf = extractIntNonNegative(props, PROP_SOCK_RCV_BUF, 0); - - boolean tcpNoDelay = extractBoolean(props, PROP_TCP_NO_DELAY, true); - boolean skipReducerOnUpdate = extractBoolean(props, PROP_SKIP_REDUCER_ON_UPDATE, false); - try { - cliIo = new JdbcThinTcpIo(host, port, distributedJoins, enforceJoinOrder, collocated, replicatedOnly, - autoCloseServerCursor, lazyExec, sockSndBuf, sockRcvBuf, tcpNoDelay, skipReducerOnUpdate); + cliIo = new JdbcThinTcpIo(connProps); cliIo.start(); } catch (Exception e) { cliIo.close(); - throw new SQLException("Failed to connect to Ignite cluster [host=" + host + ", port=" + port + ']', - SqlStateCode.CLIENT_CONNECTION_FAILED, e); + throw new SQLException("Failed to connect to Ignite cluster [host=" + connProps.getHost() + + ", port=" + connProps.getPort() + ']', SqlStateCode.CLIENT_CONNECTION_FAILED, e); } } @@ -653,7 +630,7 @@ public class JdbcThinConnection implements Connection { * @return Auto close server cursors flag. */ boolean autoCloseServerCursor() { - return cliIo.autoCloseServerCursor(); + return connProps.isAutoCloseServerCursor(); } /** @@ -683,120 +660,6 @@ public class JdbcThinConnection implements Connection { } /** - * Extract host. - * - * @param props Properties. - * @return Host. - * @throws SQLException If failed. - */ - private static String extractHost(Properties props) throws SQLException { - String host = props.getProperty(PROP_HOST); - - if (host != null) - host = host.trim(); - - if (F.isEmpty(host)) - throw new SQLException("Host name is empty.", SqlStateCode.CLIENT_CONNECTION_FAILED); - - return host; - } - - /** - * Extract port. - * - * @param props Properties. - * @return Port. - * @throws SQLException If failed. - */ - private static int extractPort(Properties props) throws SQLException { - String portStr = props.getProperty(PROP_PORT); - - if (portStr == null) - return JdbcThinUtils.DFLT_PORT; - - int port; - - try { - port = Integer.parseInt(portStr); - - if (port <= 0 || port > 0xFFFF) - throw new SQLException("Invalid port: " + portStr, SqlStateCode.CLIENT_CONNECTION_FAILED); - } - catch (NumberFormatException e) { - throw new SQLException("Invalid port: " + portStr, SqlStateCode.CLIENT_CONNECTION_FAILED); - } - - return port; - } - - /** - * Extract boolean property. - * - * @param props Properties. - * @param propName Property name. - * @param dfltVal Default value. - * @return Value. - * @throws SQLException If failed. - */ - private static boolean extractBoolean(Properties props, String propName, boolean dfltVal) throws SQLException { - String strVal = props.getProperty(propName); - - if (strVal == null) - return dfltVal; - - if (Boolean.TRUE.toString().equalsIgnoreCase(strVal)) - return true; - else if (Boolean.FALSE.toString().equalsIgnoreCase(strVal)) - return false; - else - throw new SQLException("Failed to parse boolean property [name=" + JdbcThinUtils.trimPrefix(propName) + - ", value=" + strVal + ']', SqlStateCode.CLIENT_CONNECTION_FAILED); - } - - /** - * Extract non-negative int property. - * - * @param props Properties. - * @param propName Property name. - * @param dfltVal Default value. - * @return Value. - * @throws SQLException If failed. - */ - private static int extractIntNonNegative(Properties props, String propName, int dfltVal) throws SQLException { - int res = extractInt(props, propName, dfltVal); - - if (res < 0) - throw new SQLException("Property cannot be negative [name=" + JdbcThinUtils.trimPrefix(propName) + - ", value=" + res + ']', SqlStateCode.CLIENT_CONNECTION_FAILED); - - return res; - } - - /** - * Extract int property. - * - * @param props Properties. - * @param propName Property name. - * @param dfltVal Default value. - * @return Value. - * @throws SQLException If failed. - */ - private static int extractInt(Properties props, String propName, int dfltVal) throws SQLException { - String strVal = props.getProperty(propName); - - if (strVal == null) - return dfltVal; - - try { - return Integer.parseInt(strVal); - } - catch (NumberFormatException e) { - throw new SQLException("Failed to parse int property [name=" + JdbcThinUtils.trimPrefix(propName) + - ", value=" + strVal + ']', SqlStateCode.CLIENT_CONNECTION_FAILED); - } - } - - /** * @return Connection URL. */ public String url() { http://git-wip-us.apache.org/repos/asf/ignite/blob/69acdaaa/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinTcpIo.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinTcpIo.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinTcpIo.java index 0670fb1..4d23934 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinTcpIo.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinTcpIo.java @@ -20,9 +20,27 @@ package org.apache.ignite.internal.jdbc.thin; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.IOException; +import java.io.InputStream; import java.net.InetSocketAddress; +import java.net.MalformedURLException; import java.net.Socket; +import java.net.URL; +import java.security.KeyManagementException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import javax.net.ssl.KeyManager; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactory; +import javax.net.ssl.X509TrustManager; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.binary.BinaryReaderExImpl; import org.apache.ignite.internal.binary.BinaryWriterExImpl; @@ -39,6 +57,7 @@ import org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryMetadataRequest; import org.apache.ignite.internal.processors.odbc.jdbc.JdbcRequest; import org.apache.ignite.internal.processors.odbc.jdbc.JdbcResponse; import org.apache.ignite.internal.util.ipc.loopback.IpcClientTcpEndpoint; +import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteProductVersion; @@ -76,41 +95,8 @@ public class JdbcThinTcpIo { /** Initial output for query close message. */ private static final int QUERY_CLOSE_MSG_SIZE = 9; - /** Host. */ - private final String host; - - /** Port. */ - private final int port; - - /** Distributed joins. */ - private final boolean distributedJoins; - - /** Enforce join order. */ - private final boolean enforceJoinOrder; - - /** Collocated flag. */ - private final boolean collocated; - - /** Replicated only flag. */ - private final boolean replicatedOnly; - - /** Lazy execution query flag. */ - private final boolean lazy; - - /** Flag to automatically close server cursor. */ - private final boolean autoCloseServerCursor; - - /** Executes update queries on server nodes. */ - private final boolean skipReducerOnUpdate; - - /** Socket send buffer. */ - private final int sockSndBuf; - - /** Socket receive buffer. */ - private final int sockRcvBuf; - - /** TCP no delay flag. */ - private final boolean tcpNoDelay; + /** Connection properties. */ + private final ConnectionProperties connProps; /** Endpoint. */ private IpcClientTcpEndpoint endpoint; @@ -130,34 +116,10 @@ public class JdbcThinTcpIo { /** * Constructor. * - * @param host Host. - * @param port Port. - * @param distributedJoins Distributed joins flag. - * @param enforceJoinOrder Enforce join order flag. - * @param collocated Collocated flag. - * @param replicatedOnly Replicated only flag. - * @param autoCloseServerCursor Flag to automatically close server cursors. - * @param lazy Lazy execution query flag. - * @param sockSndBuf Socket send buffer. - * @param sockRcvBuf Socket receive buffer. - * @param tcpNoDelay TCP no delay flag. - * @param skipReducerOnUpdate Executes update queries on ignite server nodes. + * @param connProps Connection properties. */ - JdbcThinTcpIo(String host, int port, boolean distributedJoins, boolean enforceJoinOrder, boolean collocated, - boolean replicatedOnly, boolean autoCloseServerCursor, boolean lazy, int sockSndBuf, int sockRcvBuf, - boolean tcpNoDelay, boolean skipReducerOnUpdate) { - this.host = host; - this.port = port; - this.distributedJoins = distributedJoins; - this.enforceJoinOrder = enforceJoinOrder; - this.collocated = collocated; - this.replicatedOnly = replicatedOnly; - this.autoCloseServerCursor = autoCloseServerCursor; - this.lazy = lazy; - this.sockSndBuf = sockSndBuf; - this.sockRcvBuf = sockRcvBuf; - this.tcpNoDelay = tcpNoDelay; - this.skipReducerOnUpdate = skipReducerOnUpdate; + JdbcThinTcpIo(ConnectionProperties connProps) { + this.connProps = connProps; } /** @@ -167,16 +129,16 @@ public class JdbcThinTcpIo { public void start() throws SQLException, IOException { Socket sock = new Socket(); - if (sockSndBuf != 0) - sock.setSendBufferSize(sockSndBuf); + if (connProps.getSocketSendBuffer() != 0) + sock.setSendBufferSize(connProps.getSocketSendBuffer()); - if (sockRcvBuf != 0) - sock.setReceiveBufferSize(sockRcvBuf); + if (connProps.getSocketReceiveBuffer() != 0) + sock.setReceiveBufferSize(connProps.getSocketReceiveBuffer()); - sock.setTcpNoDelay(tcpNoDelay); + sock.setTcpNoDelay(connProps.isTcpNoDelay()); try { - sock.connect(new InetSocketAddress(host, port)); + sock.connect(new InetSocketAddress(connProps.getHost(), connProps.getPort())); endpoint = new IpcClientTcpEndpoint(sock); @@ -184,8 +146,8 @@ public class JdbcThinTcpIo { in = new BufferedInputStream(endpoint.inputStream()); } catch (IOException | IgniteCheckedException e) { - throw new SQLException("Failed to connect to server [host=" + host + ", port=" + port + ']', - SqlStateCode.CLIENT_CONNECTION_FAILED, e); + throw new SQLException("Failed to connect to server [host=" + connProps.getHost() + + ", port=" + connProps.getPort() + ']', SqlStateCode.CLIENT_CONNECTION_FAILED, e); } handshake(CURRENT_VER); @@ -210,13 +172,13 @@ public class JdbcThinTcpIo { writer.writeByte(ClientListenerNioListener.JDBC_CLIENT); - writer.writeBoolean(distributedJoins); - writer.writeBoolean(enforceJoinOrder); - writer.writeBoolean(collocated); - writer.writeBoolean(replicatedOnly); - writer.writeBoolean(autoCloseServerCursor); - writer.writeBoolean(lazy); - writer.writeBoolean(skipReducerOnUpdate); + writer.writeBoolean(connProps.isDistributedJoins()); + writer.writeBoolean(connProps.isEnforceJoinOrder()); + writer.writeBoolean(connProps.isCollocated()); + writer.writeBoolean(connProps.isReplicatedOnly()); + writer.writeBoolean(connProps.isAutoCloseServerCursor()); + writer.writeBoolean(connProps.isLazy()); + writer.writeBoolean(connProps.isSkipReducerOnUpdate()); send(writer.array()); @@ -280,11 +242,11 @@ public class JdbcThinTcpIo { writer.writeByte(ClientListenerNioListener.JDBC_CLIENT); - writer.writeBoolean(distributedJoins); - writer.writeBoolean(enforceJoinOrder); - writer.writeBoolean(collocated); - writer.writeBoolean(replicatedOnly); - writer.writeBoolean(autoCloseServerCursor); + writer.writeBoolean(connProps.isDistributedJoins()); + writer.writeBoolean(connProps.isEnforceJoinOrder()); + writer.writeBoolean(connProps.isCollocated()); + writer.writeBoolean(connProps.isReplicatedOnly()); + writer.writeBoolean(connProps.isAutoCloseServerCursor()); send(writer.array()); @@ -429,59 +391,10 @@ public class JdbcThinTcpIo { } /** - * @return Distributed joins flag. - */ - public boolean distributedJoins() { - return distributedJoins; - } - - /** - * @return Enforce join order flag. - */ - public boolean enforceJoinOrder() { - return enforceJoinOrder; - } - - /** - * @return Collocated flag. - */ - public boolean collocated() { - return collocated; - } - - /** - * @return Replicated only flag. + * @return Connection properties. */ - public boolean replicatedOnly() { - return replicatedOnly; - } - - /** - * @return Auto close server cursors flag. - */ - public boolean autoCloseServerCursor() { - return autoCloseServerCursor; - } - - /** - * @return Socket send buffer size. - */ - public int socketSendBuffer() { - return sockSndBuf; - } - - /** - * @return Socket receive buffer size. - */ - public int socketReceiveBuffer() { - return sockRcvBuf; - } - - /** - * @return TCP no delay flag. - */ - public boolean tcpNoDelay() { - return tcpNoDelay; + public ConnectionProperties connectionProperties() { + return connProps; } /** @@ -490,18 +403,4 @@ public class JdbcThinTcpIo { IgniteProductVersion igniteVersion() { return igniteVer; } - - /** - * @return Lazy query execution flag. - */ - public boolean lazy() { - return lazy; - } - - /** - * @return Server side update flag. - */ - public boolean skipReducerOnUpdate() { - return skipReducerOnUpdate; - } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/69acdaaa/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinUtils.java index c9bf61c..5f895dd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinUtils.java @@ -17,8 +17,6 @@ package org.apache.ignite.internal.jdbc.thin; -import org.apache.ignite.configuration.ClientConnectorConfiguration; - import java.sql.Time; import java.sql.Timestamp; import java.sql.Types; @@ -37,6 +35,7 @@ import static java.sql.Types.TIME; import static java.sql.Types.TIMESTAMP; import static java.sql.Types.TINYINT; import static java.sql.Types.VARCHAR; +import static org.apache.ignite.internal.jdbc.thin.ConnectionPropertiesImpl.PROP_PREFIX; /** * Utility methods for thin JDBC driver. @@ -45,88 +44,12 @@ public class JdbcThinUtils { /** URL prefix. */ public static final String URL_PREFIX = "jdbc:ignite:thin://"; - /** Prefix for property names. */ - public static final String PROP_PREFIX = "ignite.jdbc."; - /** Port number property name. */ public static final String PROP_PORT = PROP_PREFIX + "port"; /** Hostname property name. */ public static final String PROP_HOST = PROP_PREFIX + "host"; - /** Parameter: distributed joins flag (SQL hint). */ - public static final String PARAM_DISTRIBUTED_JOINS = "distributedJoins"; - - /** Parameter: enforce join order flag (SQL hint). */ - public static final String PARAM_ENFORCE_JOIN_ORDER = "enforceJoinOrder"; - - /** Parameter: collocated flag (SQL hint). */ - public static final String PARAM_COLLOCATED = "collocated"; - - /** Parameter: lazy query execution flag (SQL hint). */ - public static final String PARAM_REPLICATED_ONLY = "replicatedOnly"; - - /** Parameter: replicated only flag (SQL hint). */ - public static final String PARAM_LAZY = "lazy"; - - /** Parameter: socket send buffer. */ - public static final String PARAM_SOCK_SND_BUF = "socketSendBuffer"; - - /** Parameter: socket receive buffer. */ - public static final String PARAM_SOCK_RCV_BUF = "socketReceiveBuffer"; - - /** Parameter: TCP no-delay flag. */ - public static final String PARAM_TCP_NO_DELAY = "tcpNoDelay"; - - /** Parameter: Automatically close server cursor. */ - public static final String PARAM_AUTO_CLOSE_SERVER_CURSOR = "autoCloseServerCursor"; - - /** Parameter: execute update query in distributed mode on ignite server nodes. */ - public static final String PARAM_SKIP_REDUCER_ON_UPDATE = "skipReducerOnUpdate"; - - /** Distributed joins property name. */ - public static final String PROP_DISTRIBUTED_JOINS = PROP_PREFIX + PARAM_DISTRIBUTED_JOINS; - - /** Transactions allowed property name. */ - public static final String PROP_ENFORCE_JOIN_ORDER = PROP_PREFIX + PARAM_ENFORCE_JOIN_ORDER; - - /** Collocated property name. */ - public static final String PROP_COLLOCATED = PROP_PREFIX + PARAM_COLLOCATED; - - /** Lazy property name. */ - public static final String PROP_LAZY = PROP_PREFIX + PARAM_LAZY; - - /** Replicated only property name. */ - public static final String PROP_REPLICATED_ONLY = PROP_PREFIX + PARAM_REPLICATED_ONLY; - - /** Socket send buffer property name. */ - public static final String PROP_SOCK_SND_BUF = PROP_PREFIX + PARAM_SOCK_SND_BUF; - - /** Socket receive buffer property name. */ - public static final String PROP_SOCK_RCV_BUF = PROP_PREFIX + PARAM_SOCK_RCV_BUF; - - /** TCP no delay property name. */ - public static final String PROP_TCP_NO_DELAY = PROP_PREFIX + PARAM_TCP_NO_DELAY; - - /** Automatically close server cursor. */ - public static final String PROP_AUTO_CLOSE_SERVER_CURSORS = PROP_PREFIX + PARAM_AUTO_CLOSE_SERVER_CURSOR; - - /** Executes update queries on ignite server nodes in distributed mode. */ - public static final String PROP_SKIP_REDUCER_ON_UPDATE = PROP_PREFIX + PARAM_SKIP_REDUCER_ON_UPDATE; - - /** Default port. */ - public static final int DFLT_PORT = ClientConnectorConfiguration.DFLT_PORT; - - /** - * Trim prefix from property. - * - * @param prop Property. - * @return Parameter name. - */ - public static String trimPrefix(String prop) { - return prop.substring(PROP_PREFIX.length()); - } - /** * Converts Java class name to type from {@link Types}. *