IGNITE-5339: JDBC thin driver: improved compliance. This closes #2112.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/dbedbba0 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/dbedbba0 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/dbedbba0 Branch: refs/heads/ignite-3478 Commit: dbedbba0617c592958ea1c6eb02274c66a60eb84 Parents: e66b98b Author: devozerov <[email protected]> Authored: Wed Sep 6 17:34:11 2017 +0300 Committer: devozerov <[email protected]> Committed: Wed Sep 6 17:34:11 2017 +0300 ---------------------------------------------------------------------- .../jdbc/suite/IgniteJdbcDriverTestSuite.java | 7 +- .../jdbc/thin/JdbcThinAbstractSelfTest.java | 71 +- .../jdbc/thin/JdbcThinConnectionSelfTest.java | 1393 +++++++++++++++++- .../thin/JdbcThinPreparedStatementSelfTest.java | 267 +++- .../jdbc/thin/JdbcThinResultSetSelfTest.java | 963 +++++++++++- .../jdbc/thin/JdbcThinStatementSelfTest.java | 719 ++++++++- .../internal/jdbc/thin/JdbcThinConnection.java | 96 +- .../jdbc/thin/JdbcThinPreparedStatement.java | 21 +- .../internal/jdbc/thin/JdbcThinResultSet.java | 19 +- .../internal/jdbc/thin/JdbcThinStatement.java | 74 +- 10 files changed, 3553 insertions(+), 77 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/dbedbba0/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 40bfbe3..c2ac6cb 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 @@ -35,6 +35,7 @@ import org.apache.ignite.jdbc.JdbcResultSetSelfTest; import org.apache.ignite.jdbc.JdbcStatementSelfTest; import org.apache.ignite.jdbc.thin.JdbcThinAutoCloseServerCursorTest; import org.apache.ignite.jdbc.thin.JdbcThinBatchSelfTest; +import org.apache.ignite.jdbc.thin.JdbcThinComplexDmlDdlSelfTest; import org.apache.ignite.jdbc.thin.JdbcThinComplexQuerySelfTest; import org.apache.ignite.jdbc.thin.JdbcThinConnectionSelfTest; import org.apache.ignite.jdbc.thin.JdbcThinDeleteStatementSelfTest; @@ -54,7 +55,6 @@ import org.apache.ignite.jdbc.thin.JdbcThinPreparedStatementSelfTest; import org.apache.ignite.jdbc.thin.JdbcThinResultSetSelfTest; import org.apache.ignite.jdbc.thin.JdbcThinStatementSelfTest; import org.apache.ignite.jdbc.thin.JdbcThinUpdateStatementSelfTest; -import org.apache.ignite.jdbc.thin.JdbcThinComplexDmlDdlSelfTest; /** * JDBC driver test suite. @@ -116,10 +116,11 @@ public class IgniteJdbcDriverTestSuite extends TestSuite { // New thin JDBC suite.addTest(new TestSuite(JdbcThinConnectionSelfTest.class)); - suite.addTest(new TestSuite(JdbcThinStatementSelfTest.class)); + suite.addTest(new TestSuite(JdbcThinPreparedStatementSelfTest.class)); suite.addTest(new TestSuite(JdbcThinResultSetSelfTest.class)); + + suite.addTest(new TestSuite(JdbcThinStatementSelfTest.class)); suite.addTest(new TestSuite(JdbcThinComplexQuerySelfTest.class)); - suite.addTest(new TestSuite(JdbcThinPreparedStatementSelfTest.class)); suite.addTest(new TestSuite(JdbcThinNoDefaultSchemaTest.class)); suite.addTest(new TestSuite(JdbcThinEmptyCacheSelfTest.class)); suite.addTest(new TestSuite(JdbcThinMetadataSelfTest.class)); http://git-wip-us.apache.org/repos/asf/ignite/blob/dbedbba0/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinAbstractSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinAbstractSelfTest.java index 6655ed8..1c38df2 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinAbstractSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinAbstractSelfTest.java @@ -17,11 +17,80 @@ package org.apache.ignite.jdbc.thin; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.util.concurrent.Callable; +import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; /** * Connection test. */ +@SuppressWarnings("ThrowableNotThrown") public class JdbcThinAbstractSelfTest extends GridCommonAbstractTest { - // No-op. + /** + * @param r Runnable to check support. + */ + protected void checkNotSupported(final RunnableX r) { + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + r.run(); + + return null; + } + }, SQLFeatureNotSupportedException.class, null); + } + + /** + * @param r Runnable to check on closed connection. + */ + protected void checkConnectionClosed(final RunnableX r) { + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + r.run(); + + return null; + } + }, SQLException.class, "Connection is closed"); + } + + /** + * @param r Runnable to check on closed statement. + */ + protected void checkStatementClosed(final RunnableX r) { + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + r.run(); + + return null; + } + }, SQLException.class, "Statement is closed"); + } + + /** + * @param r Runnable to check on closed result set. + */ + protected void checkResultSetClosed(final RunnableX r) { + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + r.run(); + + return null; + } + }, SQLException.class, "Result set is closed"); + } + + /** + * Runnable that can throw an exception. + */ + interface RunnableX { + /** + * @throws Exception On error. + */ + void run() throws Exception; + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/dbedbba0/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 2306a2b..9bf6282 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 @@ -17,6 +17,22 @@ package org.apache.ignite.jdbc.thin; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLClientInfoException; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.sql.SQLWarning; +import java.sql.Savepoint; +import java.sql.Statement; +import java.util.HashMap; +import java.util.Properties; +import java.util.concurrent.Callable; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.binary.BinaryMarshaller; @@ -29,19 +45,31 @@ import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; import org.apache.ignite.testframework.GridTestUtils; import org.jetbrains.annotations.NotNull; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.concurrent.Callable; +import static java.sql.Connection.TRANSACTION_NONE; +import static java.sql.Connection.TRANSACTION_READ_COMMITTED; +import static java.sql.Connection.TRANSACTION_READ_UNCOMMITTED; +import static java.sql.Connection.TRANSACTION_REPEATABLE_READ; +import static java.sql.Connection.TRANSACTION_SERIALIZABLE; +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 java.sql.Statement.NO_GENERATED_KEYS; +import static java.sql.Statement.RETURN_GENERATED_KEYS; /** * Connection test. */ +@SuppressWarnings("ThrowableNotThrown") public class JdbcThinConnectionSelfTest extends JdbcThinAbstractSelfTest { /** IP finder. */ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + /** */ + private static final String URL = "jdbc:ignite:thin://127.0.0.1"; + /** {@inheritDoc} */ + @SuppressWarnings("deprecation") @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); @@ -364,4 +392,1361 @@ public class JdbcThinConnectionSelfTest extends JdbcThinAbstractSelfTest { } }, SQLException.class, "Invalid timeout"); } + + /** + * @throws Exception If failed. + */ + public void testCreateStatement() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + try (Statement stmt = conn.createStatement()) { + assertNotNull(stmt); + + stmt.close(); + + conn.close(); + + // Exception when called on closed connection + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.createStatement(); + } + }); + } + } + } + + /** + * @throws Exception If failed. + */ + public void testCreateStatement2() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + int [] rsTypes = new int[] + {TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_SCROLL_SENSITIVE}; + + int [] rsConcurs = new int[] + {CONCUR_READ_ONLY, ResultSet.CONCUR_UPDATABLE}; + + DatabaseMetaData meta = conn.getMetaData(); + + for (final int type : rsTypes) { + for (final int concur : rsConcurs) { + if (meta.supportsResultSetConcurrency(type, concur)) { + assert type == TYPE_FORWARD_ONLY; + assert concur == CONCUR_READ_ONLY; + + try (Statement stmt = conn.createStatement(type, concur)) { + assertNotNull(stmt); + + assertEquals(type, stmt.getResultSetType()); + assertEquals(concur, stmt.getResultSetConcurrency()); + } + + continue; + } + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.createStatement(type, concur); + } + }, + SQLFeatureNotSupportedException.class, + null + ); + } + } + + conn.close(); + + // Exception when called on closed connection + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.createStatement(TYPE_FORWARD_ONLY, + CONCUR_READ_ONLY); + } + }); + } + } + + /** + * @throws Exception If failed. + */ + public void testCreateStatement3() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + int [] rsTypes = new int[] + {TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_SCROLL_SENSITIVE}; + + int [] rsConcurs = new int[] + {CONCUR_READ_ONLY, ResultSet.CONCUR_UPDATABLE}; + + int [] rsHoldabilities = new int[] + {HOLD_CURSORS_OVER_COMMIT, CLOSE_CURSORS_AT_COMMIT}; + + DatabaseMetaData meta = conn.getMetaData(); + + for (final int type : rsTypes) { + for (final int concur : rsConcurs) { + for (final int holdabililty : rsHoldabilities) { + if (meta.supportsResultSetConcurrency(type, concur)) { + assert type == TYPE_FORWARD_ONLY; + assert concur == CONCUR_READ_ONLY; + + try (Statement stmt = conn.createStatement(type, concur, holdabililty)) { + assertNotNull(stmt); + + assertEquals(type, stmt.getResultSetType()); + assertEquals(concur, stmt.getResultSetConcurrency()); + assertEquals(holdabililty, stmt.getResultSetHoldability()); + } + + continue; + } + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.createStatement(type, concur, holdabililty); + } + }, + SQLFeatureNotSupportedException.class, + null + ); + } + } + } + + conn.close(); + + // Exception when called on closed connection + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.createStatement(TYPE_FORWARD_ONLY, + CONCUR_READ_ONLY, HOLD_CURSORS_OVER_COMMIT); + } + }); + } + } + + /** + * @throws Exception If failed. + */ + public void testPrepareStatement() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + // null query text + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.prepareStatement(null); + } + }, + SQLException.class, + "SQL string cannot be null" + ); + + final String sqlText = "select * from test where param = ?"; + + try (PreparedStatement prepared = conn.prepareStatement(sqlText)) { + assertNotNull(prepared); + } + + conn.close(); + + // Exception when called on closed connection + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.prepareStatement(sqlText); + } + }); + } + } + + /** + * @throws Exception If failed. + */ + public void testPrepareStatement3() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + final String sqlText = "select * from test where param = ?"; + + int [] rsTypes = new int[] + {TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_SCROLL_SENSITIVE}; + + int [] rsConcurs = new int[] + {CONCUR_READ_ONLY, ResultSet.CONCUR_UPDATABLE}; + + DatabaseMetaData meta = conn.getMetaData(); + + for (final int type : rsTypes) { + for (final int concur : rsConcurs) { + if (meta.supportsResultSetConcurrency(type, concur)) { + assert type == TYPE_FORWARD_ONLY; + assert concur == CONCUR_READ_ONLY; + + // null query text + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.prepareStatement(null, type, concur); + } + }, + SQLException.class, + "SQL string cannot be null" + ); + + continue; + } + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.prepareStatement(sqlText, type, concur); + } + }, + SQLFeatureNotSupportedException.class, + null + ); + } + } + + conn.close(); + + // Exception when called on closed connection + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.prepareStatement(sqlText, TYPE_FORWARD_ONLY, CONCUR_READ_ONLY); + } + }); + + conn.close(); + } + } + + /** + * @throws Exception If failed. + */ + public void testPrepareStatement4() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + final String sqlText = "select * from test where param = ?"; + + int [] rsTypes = new int[] + {TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_SCROLL_SENSITIVE}; + + int [] rsConcurs = new int[] + {CONCUR_READ_ONLY, ResultSet.CONCUR_UPDATABLE}; + + int [] rsHoldabilities = new int[] + {HOLD_CURSORS_OVER_COMMIT, CLOSE_CURSORS_AT_COMMIT}; + + DatabaseMetaData meta = conn.getMetaData(); + + for (final int type : rsTypes) { + for (final int concur : rsConcurs) { + for (final int holdabililty : rsHoldabilities) { + if (meta.supportsResultSetConcurrency(type, concur)) { + assert type == TYPE_FORWARD_ONLY; + assert concur == CONCUR_READ_ONLY; + + // null query text + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.prepareStatement(null, type, concur, holdabililty); + } + }, + SQLException.class, + "SQL string cannot be null" + ); + + continue; + } + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.prepareStatement(sqlText, type, concur, holdabililty); + } + }, + SQLFeatureNotSupportedException.class, + null + ); + } + } + } + + conn.close(); + + // Exception when called on closed connection + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.prepareStatement(sqlText, TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, HOLD_CURSORS_OVER_COMMIT); + } + }); + + conn.close(); + } + } + + /** + * @throws Exception If failed. + */ + public void testPrepareStatementAutoGeneratedKeysUnsupported() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + final String sqlText = "insert into test (val) values (?)"; + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.prepareStatement(sqlText, RETURN_GENERATED_KEYS); + } + }, + SQLFeatureNotSupportedException.class, + "Auto generated keys are not supported." + ); + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.prepareStatement(sqlText, NO_GENERATED_KEYS); + } + }, + SQLFeatureNotSupportedException.class, + "Auto generated keys are not supported." + ); + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.prepareStatement(sqlText, new int[] {1}); + } + }, + SQLFeatureNotSupportedException.class, + "Auto generated keys are not supported." + ); + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.prepareStatement(sqlText, new String[] {"ID"}); + } + }, + SQLFeatureNotSupportedException.class, + "Auto generated keys are not supported." + ); + } + } + + /** + * @throws Exception If failed. + */ + public void testPrepareCallUnsupported() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + final String sqlText = "exec test()"; + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.prepareCall(sqlText); + } + }, + SQLFeatureNotSupportedException.class, + "Callable functions are not supported." + ); + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.prepareCall(sqlText, TYPE_FORWARD_ONLY, CONCUR_READ_ONLY); + } + }, + SQLFeatureNotSupportedException.class, + "Callable functions are not supported." + ); + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.prepareCall(sqlText, TYPE_FORWARD_ONLY, + CONCUR_READ_ONLY, HOLD_CURSORS_OVER_COMMIT); + } + }, + SQLFeatureNotSupportedException.class, + "Callable functions are not supported." + ); + } + } + + /** + * @throws Exception If failed. + */ + public void testNativeSql() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + // null query text + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.nativeSQL(null); + } + }, + SQLException.class, + "SQL string cannot be null" + ); + + final String sqlText = "select * from test"; + + assertEquals(sqlText, conn.nativeSQL(sqlText)); + + conn.close(); + + // Exception when called on closed connection + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.nativeSQL(sqlText); + } + }); + } + } + + /** + * @throws Exception If failed. + */ + public void testGetSetAutoCommit() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + assertTrue(conn.getAutoCommit()); + + conn.setAutoCommit(false); + + assertFalse(conn.getAutoCommit()); + + conn.setAutoCommit(true); + + assertTrue(conn.getAutoCommit()); + + conn.close(); + + // Exception when called on closed connection + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.setAutoCommit(true); + } + }); + } + } + + /** + * @throws Exception If failed. + */ + public void testCommit() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + assert !conn.getMetaData().supportsTransactions(); + + // Should not be called in auto-commit mode + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + conn.commit(); + + return null; + } + }, + SQLException.class, + "Transaction cannot be committed explicitly in auto-commit mode" + ); + + conn.setAutoCommit(false); + + conn.commit(); + + conn.close(); + + // Exception when called on closed connection + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.commit(); + } + }); + } + } + + /** + * @throws Exception If failed. + */ + public void testRollback() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + assert !conn.getMetaData().supportsTransactions(); + + // Should not be called in auto-commit mode + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + conn.rollback(); + + return null; + } + }, + SQLException.class, + "Transaction cannot rollback in auto-commit mode" + ); + + conn.setAutoCommit(false); + + conn.rollback(); + + conn.close(); + + // Exception when called on closed connection + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.rollback(); + } + }); + } + } + + /** + * @throws Exception If failed. + */ + public void testGetMetaData() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + DatabaseMetaData meta = conn.getMetaData(); + + assertNotNull(meta); + + conn.close(); + + // Exception when called on closed connection + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.getMetaData(); + } + }); + } + } + + /** + * @throws Exception If failed. + */ + public void testGetSetReadOnly() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + conn.close(); + + // Exception when called on closed connection + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.setReadOnly(true); + } + }); + + // Exception when called on closed connection + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.isReadOnly(); + } + }); + } + } + + /** + * @throws Exception If failed. + */ + public void testGetSetCatalog() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + assert !conn.getMetaData().supportsCatalogsInDataManipulation(); + + assertNull(conn.getCatalog()); + + conn.setCatalog("catalog"); + + assertEquals(null, conn.getCatalog()); + + conn.close(); + + // Exception when called on closed connection + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.setCatalog(""); + } + }); + + // Exception when called on closed connection + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.getCatalog(); + } + }); + } + } + + /** + * @throws Exception If failed. + */ + public void testGetSetTransactionIsolation() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + assert !conn.getMetaData().supportsTransactions(); + + // Invalid parameter value + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + conn.setTransactionIsolation(-1); + + return null; + } + }, + SQLException.class, + "Invalid transaction isolation level" + ); + + // default level + assertEquals(TRANSACTION_NONE, conn.getTransactionIsolation()); + + int[] levels = { + TRANSACTION_READ_UNCOMMITTED, TRANSACTION_READ_COMMITTED, + TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE}; + + for (int level : levels) { + conn.setTransactionIsolation(level); + assertEquals(level, conn.getTransactionIsolation()); + } + + conn.close(); + + // Exception when called on closed connection + + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.getTransactionIsolation(); + } + }); + + // Exception when called on closed connection + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.setTransactionIsolation(TRANSACTION_SERIALIZABLE); + } + }); + } + } + + /** + * @throws Exception If failed. + */ + public void testClearGetWarnings() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + SQLWarning warn = conn.getWarnings(); + + assertNull(warn); + + conn.clearWarnings(); + + warn = conn.getWarnings(); + + assertNull(warn); + + conn.close(); + + // Exception when called on closed connection + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.getWarnings(); + } + }); + + + // Exception when called on closed connection + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.clearWarnings(); + } + }); + } + } + + /** + * @throws Exception If failed. + */ + public void testGetSetTypeMap() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.getTypeMap(); + } + }, + SQLFeatureNotSupportedException.class, + "Types mapping is not supported" + ); + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + conn.setTypeMap(new HashMap<String, Class<?>>()); + + return null; + } + }, + SQLFeatureNotSupportedException.class, + "Types mapping is not supported" + ); + + conn.close(); + + // Exception when called on closed connection + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.getTypeMap(); + } + }, + SQLException.class, + "Connection is closed" + ); + + // Exception when called on closed connection + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + conn.setTypeMap(new HashMap<String, Class<?>>()); + + return null; + } + }, + SQLException.class, + "Connection is closed" + ); + } + } + + /** + * @throws Exception If failed. + */ + public void testGetSetHoldability() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + // default value + assertEquals(conn.getMetaData().getResultSetHoldability(), conn.getHoldability()); + + assertEquals(HOLD_CURSORS_OVER_COMMIT, conn.getHoldability()); + + conn.setHoldability(CLOSE_CURSORS_AT_COMMIT); + + assertEquals(CLOSE_CURSORS_AT_COMMIT, conn.getHoldability()); + + // Invalid constant + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + conn.setHoldability(-1); + + return null; + } + }, + SQLException.class, + "Invalid result set holdability value" + ); + + conn.close(); + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.getHoldability(); + } + }, + SQLException.class, + "Connection is closed" + ); + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + conn.setHoldability(HOLD_CURSORS_OVER_COMMIT); + + return null; + } + }, + SQLException.class, + "Connection is closed" + ); + } + } + + /** + * @throws Exception If failed. + */ + public void testSetSavepoint() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + assert !conn.getMetaData().supportsSavepoints(); + + // Disallowed in auto-commit mode + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + conn.setSavepoint(); + + return null; + } + }, + SQLException.class, + "Savepoint cannot be set in auto-commit mode" + ); + + conn.setAutoCommit(false); + + // Unsupported + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + conn.setSavepoint(); + } + }); + + conn.close(); + + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.setSavepoint(); + } + }); + } + } + + /** + * @throws Exception If failed. + */ + public void testSetSavepointName() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + assert !conn.getMetaData().supportsSavepoints(); + + // Invalid arg + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + conn.setSavepoint(null); + + return null; + } + }, + SQLException.class, + "Savepoint name cannot be null" + ); + + final String name = "savepoint"; + + // Disallowed in auto-commit mode + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + conn.setSavepoint(name); + + return null; + } + }, + SQLException.class, + "Savepoint cannot be set in auto-commit mode" + ); + + conn.setAutoCommit(false); + + // Unsupported + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + conn.setSavepoint(name); + } + }); + + conn.close(); + + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.setSavepoint(name); + } + }); + } + } + + /** + * @throws Exception If failed. + */ + public void testRollbackSavePoint() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + assert !conn.getMetaData().supportsSavepoints(); + + // Invalid arg + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + conn.rollback(null); + + return null; + } + }, + SQLException.class, + "Invalid savepoint" + ); + + final Savepoint savepoint = getFakeSavepoint(); + + // Disallowed in auto-commit mode + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + conn.rollback(savepoint); + + return null; + } + }, + SQLException.class, + "Auto-commit mode" + ); + + conn.setAutoCommit(false); + + // Unsupported + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + conn.rollback(savepoint); + } + }); + + conn.close(); + + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.rollback(savepoint); + } + }); + } + } + + /** + * @throws Exception If failed. + */ + public void testReleaseSavepoint() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + assert !conn.getMetaData().supportsSavepoints(); + + // Invalid arg + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + conn.releaseSavepoint(null); + + return null; + } + }, + SQLException.class, + "Savepoint cannot be null" + ); + + final Savepoint savepoint = getFakeSavepoint(); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + conn.releaseSavepoint(savepoint); + } + }); + + conn.close(); + + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.releaseSavepoint(savepoint); + } + }); + } + } + + /** + * @throws Exception If failed. + */ + public void testCreateClob() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + // Unsupported + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.createClob(); + } + }, + SQLFeatureNotSupportedException.class, + "SQL-specific types are not supported" + ); + + conn.close(); + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.createClob(); + } + }, + SQLException.class, + "Connection is closed" + ); + } + } + + /** + * @throws Exception If failed. + */ + public void testCreateBlob() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + // Unsupported + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.createBlob(); + } + }, + SQLFeatureNotSupportedException.class, + "SQL-specific types are not supported" + ); + + conn.close(); + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.createBlob(); + } + }, + SQLException.class, + "Connection is closed" + ); + } + } + + /** + * @throws Exception If failed. + */ + public void testCreateNClob() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + // Unsupported + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.createNClob(); + } + }, + SQLFeatureNotSupportedException.class, + "SQL-specific types are not supported" + ); + + conn.close(); + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.createNClob(); + } + }, + SQLException.class, + "Connection is closed" + ); + } + } + + /** + * @throws Exception If failed. + */ + public void testCreateSQLXML() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + // Unsupported + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.createSQLXML(); + } + }, + SQLFeatureNotSupportedException.class, + "SQL-specific types are not supported" + ); + + conn.close(); + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.createSQLXML(); + } + }, + SQLException.class, + "Connection is closed" + ); + } + } + + /** + * @throws Exception If failed. + */ + public void testGetSetClientInfoPair() throws Exception { +// fail("https://issues.apache.org/jira/browse/IGNITE-5425"); + + try (Connection conn = DriverManager.getConnection(URL)) { + final String name = "ApplicationName"; + final String val = "SelfTest"; + + assertNull(conn.getWarnings()); + + conn.setClientInfo(name, val); + + assertNull(conn.getClientInfo(val)); + + conn.close(); + + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.getClientInfo(name); + } + }); + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + conn.setClientInfo(name, val); + + return null; + } + }, SQLClientInfoException.class, "Connection is closed"); + } + } + + /** + * @throws Exception If failed. + */ + public void testGetSetClientInfoProperties() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + final String name = "ApplicationName"; + final String val = "SelfTest"; + + final Properties props = new Properties(); + props.setProperty(name, val); + + conn.setClientInfo(props); + + Properties propsResult = conn.getClientInfo(); + + assertNotNull(propsResult); + + assertTrue(propsResult.isEmpty()); + + conn.close(); + + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.getClientInfo(); + } + }); + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + conn.setClientInfo(props); + + return null; + } + }, SQLClientInfoException.class, "Connection is closed"); + } + } + + /** + * @throws Exception If failed. + */ + public void testCreateArrayOf() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + final String typeName = "varchar"; + + final String[] elements = new String[] {"apple", "pear"}; + + // Invalid typename + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + conn.createArrayOf(null, null); + + return null; + } + }, + SQLException.class, + "Type name cannot be null" + ); + + // Unsupported + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + conn.createArrayOf(typeName, elements); + } + }); + + conn.close(); + + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.createArrayOf(typeName, elements); + } + }); + } + } + + /** + * @throws Exception If failed. + */ + public void testCreateStruct() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + // Invalid typename + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + return conn.createStruct(null, null); + } + }, + SQLException.class, + "Type name cannot be null" + ); + + final String typeName = "employee"; + + final Object[] attrs = new Object[] {100, "Tom"}; + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + conn.createStruct(typeName, attrs); + } + }); + + conn.close(); + + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.createStruct(typeName, attrs); + } + }); + } + } + + /** + * @throws Exception If failed. + */ + public void testGetSetSchema() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + assertEquals("PUBLIC", conn.getSchema()); + + final String schema = "test"; + + conn.setSchema(schema); + + assertEquals(schema, conn.getSchema()); + + conn.close(); + + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.setSchema(schema); + } + }); + + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.getSchema(); + } + }); + } + } + + /** + * @throws Exception If failed. + */ + public void testAbort() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + //Invalid executor + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + conn.abort(null); + + return null; + } + }, + SQLException.class, + "Executor cannot be null" + ); + + final Executor executor = Executors.newFixedThreadPool(1); + + conn.abort(executor); + + assertTrue(conn.isClosed()); + } + } + + /** + * @throws Exception If failed. + */ + public void testGetSetNetworkTimeout() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + // default + assertEquals(0, conn.getNetworkTimeout()); + + final Executor executor = Executors.newFixedThreadPool(1); + + final int timeout = 1000; + + //Invalid executor + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + conn.setNetworkTimeout(null, timeout); + + return null; + } + }, + SQLException.class, + "Executor cannot be null" + ); + + //Invalid timeout + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + conn.setNetworkTimeout(executor, -1); + + return null; + } + }, + SQLException.class, + "Network timeout cannot be negative" + ); + + conn.setNetworkTimeout(executor, timeout); + + assertEquals(timeout, conn.getNetworkTimeout()); + + conn.close(); + + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.getNetworkTimeout(); + } + }); + + checkConnectionClosed(new RunnableX() { + @Override public void run() throws Exception { + conn.setNetworkTimeout(executor, timeout); + } + }); + } + } + + /** + * @return Savepoint. + */ + private Savepoint getFakeSavepoint() { + return new Savepoint() { + @Override public int getSavepointId() throws SQLException { + return 100; + } + + @Override public String getSavepointName() { + return "savepoint"; + } + }; + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/dbedbba0/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinPreparedStatementSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinPreparedStatementSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinPreparedStatementSelfTest.java index 841a0af..64aafd3 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinPreparedStatementSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinPreparedStatementSelfTest.java @@ -17,16 +17,23 @@ package org.apache.ignite.jdbc.thin; +import java.io.InputStream; +import java.io.Reader; import java.io.Serializable; import java.math.BigDecimal; import java.net.URL; +import java.sql.Blob; +import java.sql.Clob; import java.sql.Connection; import java.sql.DriverManager; +import java.sql.NClob; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Statement; import java.sql.Time; import java.sql.Timestamp; +import java.sql.Types; import java.util.Date; import java.util.concurrent.Callable; import org.apache.ignite.IgniteCache; @@ -57,6 +64,7 @@ import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; /** * Prepared statement test. */ +@SuppressWarnings("ThrowableNotThrown") public class JdbcThinPreparedStatementSelfTest extends JdbcThinAbstractSelfTest { /** IP finder. */ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); @@ -206,7 +214,7 @@ public class JdbcThinPreparedStatementSelfTest extends JdbcThinAbstractSelfTest GridTestUtils.assertThrowsAnyCause(log, new Callable<Void>() { @Override public Void call() throws Exception { - stmt.executeQuery(SQL_PART); + stmt.executeQuery("select 1"); return null; } @@ -214,11 +222,43 @@ public class JdbcThinPreparedStatementSelfTest extends JdbcThinAbstractSelfTest GridTestUtils.assertThrowsAnyCause(log, new Callable<Void>() { @Override public Void call() throws Exception { - stmt.execute(SQL_PART); + stmt.execute("select 1"); return null; } }, SQLException.class, "The method 'execute(String)' is called on PreparedStatement instance."); + + GridTestUtils.assertThrowsAnyCause(log, new Callable<Void>() { + @Override public Void call() throws Exception { + stmt.execute("select 1", Statement.NO_GENERATED_KEYS); + + return null; + } + }, SQLException.class, "The method 'execute(String)' is called on PreparedStatement instance."); + + GridTestUtils.assertThrowsAnyCause(log, new Callable<Void>() { + @Override public Void call() throws Exception { + stmt.executeUpdate("select 1", Statement.NO_GENERATED_KEYS); + + return null; + } + }, SQLException.class, "The method 'executeUpdate(String, int)' is called on PreparedStatement instance."); + + GridTestUtils.assertThrowsAnyCause(log, new Callable<Void>() { + @Override public Void call() throws Exception { + stmt.executeUpdate("select 1", new int[] {1}); + + return null; + } + }, SQLException.class, "The method 'executeUpdate(String, int[])' is called on PreparedStatement instance."); + + GridTestUtils.assertThrowsAnyCause(log, new Callable<Void>() { + @Override public Void call() throws Exception { + stmt.executeUpdate("select 1 as a", new String[]{"a"}); + + return null; + } + }, SQLException.class, "The method 'executeUpdate(String, String[])' is called on PreparedStatement instance."); } /** @@ -729,12 +769,233 @@ public class JdbcThinPreparedStatementSelfTest extends JdbcThinAbstractSelfTest } /** + * @throws Exception If failed. + */ + public void testClearParameter() throws Exception { + stmt = conn.prepareStatement(SQL_PART + " where boolVal is not distinct from ?"); + + stmt.setString(1, ""); + stmt.setLong(2, 1L); + stmt.setInt(5, 1); + + stmt.clearParameters(); + + stmt.setBoolean(1, true); + + ResultSet rs = stmt.executeQuery(); + + boolean hasNext = rs.next(); + + assert hasNext; + + assert rs.getInt("id") == 1; + } + + /** + * @throws Exception If failed. + */ + public void testNotSupportedTypes() throws Exception { + stmt = conn.prepareStatement(""); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setArray(1, null); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setAsciiStream(1, null); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setAsciiStream(1, null, 0); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setAsciiStream(1, null, 0L); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setBinaryStream(1, null); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setBinaryStream(1, null, 0); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setBinaryStream(1, null, 0L); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setBlob(1, (Blob)null); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setBlob(1, (InputStream)null); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setBlob(1, null, 0L); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setCharacterStream(1, null); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setCharacterStream(1, null, 0); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setCharacterStream(1, null, 0L); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setClob(1, (Clob)null); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setClob(1, (Reader)null); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setClob(1, null, 0L); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setNCharacterStream(1, null); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setNCharacterStream(1, null, 0L); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setNClob(1, (NClob)null); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setNClob(1, (Reader)null); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setNClob(1, null, 0L); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setNString(1, ""); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setRowId(1, null); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setRef(1, null); + } + }); + + checkNotSupported(new RunnableX() { + @Override public void run() throws Exception { + stmt.setSQLXML(1, null); + } + }); + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + stmt.setURL(1, new URL("http://test")); + + return null; + } + }, + SQLException.class, "Parameter type is unsupported"); + + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + stmt.setObject(1, new TestObject(0)); + + return null; + } + }, + SQLException.class, "Parameter type is unsupported"); + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + stmt.setObject(1, new TestObject(0), Types.JAVA_OBJECT); + + return null; + } + }, + SQLException.class, "Parameter type is unsupported"); + + GridTestUtils.assertThrows(log, + new Callable<Object>() { + @Override public Object call() throws Exception { + stmt.setObject(1, new TestObject(0), Types.JAVA_OBJECT, 0); + + return null; + } + }, + SQLException.class, "Parameter type is unsupported"); + } + + /** * Test object. */ @SuppressWarnings("UnusedDeclaration") private static class TestObject implements Serializable { /** */ - @QuerySqlField(index = false) + @QuerySqlField private final int id; /** */
