Search in sources :

Example 46 with RunnableX

use of org.apache.ignite.testframework.GridTestUtils.RunnableX in project ignite by apache.

the class JdbcThinConnectionSelfTest method testCreateStatement3.

/**
 * @throws Exception If failed.
 */
@Test
public void testCreateStatement3() throws Exception {
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
        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;
                    }
                    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 runx() throws Exception {
                conn.createStatement(TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, HOLD_CURSORS_OVER_COMMIT);
            }
        });
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) Connection(java.sql.Connection) JdbcThinConnection(org.apache.ignite.internal.jdbc.thin.JdbcThinConnection) DatabaseMetaData(java.sql.DatabaseMetaData) Savepoint(java.sql.Savepoint) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SQLClientInfoException(java.sql.SQLClientInfoException) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 47 with RunnableX

use of org.apache.ignite.testframework.GridTestUtils.RunnableX in project ignite by apache.

the class JdbcThinConnectionSelfTest method testReleaseSavepoint.

/**
 * @throws Exception If failed.
 */
@Test
public void testReleaseSavepoint() throws Exception {
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
        assert !conn.getMetaData().supportsSavepoints();
        // Invalid arg
        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 runx() throws Exception {
                conn.releaseSavepoint(savepoint);
            }
        });
        conn.close();
        checkConnectionClosed(new RunnableX() {

            @Override
            public void runx() throws Exception {
                conn.releaseSavepoint(savepoint);
            }
        });
    }
}
Also used : RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) Connection(java.sql.Connection) JdbcThinConnection(org.apache.ignite.internal.jdbc.thin.JdbcThinConnection) Savepoint(java.sql.Savepoint) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SQLClientInfoException(java.sql.SQLClientInfoException) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 48 with RunnableX

use of org.apache.ignite.testframework.GridTestUtils.RunnableX in project ignite by apache.

the class JdbcThinConnectionSelfTest method testSetSavepointName.

/**
 * @throws Exception If failed.
 */
@Test
public void testSetSavepointName() throws Exception {
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
        assert !conn.getMetaData().supportsSavepoints();
        // Invalid arg
        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
        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.close();
        checkConnectionClosed(new RunnableX() {

            @Override
            public void runx() throws Exception {
                conn.setSavepoint(name);
            }
        });
    }
}
Also used : RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) Connection(java.sql.Connection) JdbcThinConnection(org.apache.ignite.internal.jdbc.thin.JdbcThinConnection) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SQLClientInfoException(java.sql.SQLClientInfoException) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 49 with RunnableX

use of org.apache.ignite.testframework.GridTestUtils.RunnableX in project ignite by apache.

the class JdbcThinStatementSelfTest method testCursorName.

/**
 * @throws Exception If failed.
 */
@org.junit.Test
public void testCursorName() throws Exception {
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            stmt.setCursorName("test");
        }
    });
    stmt.close();
    checkStatementClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            stmt.setCursorName("test");
        }
    });
}
Also used : RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLException(java.sql.SQLException)

Example 50 with RunnableX

use of org.apache.ignite.testframework.GridTestUtils.RunnableX in project ignite by apache.

the class JdbcThinStatementSelfTest method testGetMoreResultsKeepCurrent.

/**
 * @throws Exception If failed.
 */
@org.junit.Test
public void testGetMoreResultsKeepCurrent() throws Exception {
    assertFalse(stmt.getMoreResults(Statement.CLOSE_CURRENT_RESULT));
    assertFalse(stmt.getMoreResults(Statement.KEEP_CURRENT_RESULT));
    assertFalse(stmt.getMoreResults(Statement.CLOSE_ALL_RESULTS));
    stmt.execute("select 1; ");
    ResultSet rs = stmt.getResultSet();
    assertFalse(stmt.getMoreResults(Statement.KEEP_CURRENT_RESULT));
    assertFalse(rs.isClosed());
    stmt.close();
    checkStatementClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            stmt.getMoreResults(Statement.KEEP_CURRENT_RESULT);
        }
    });
}
Also used : RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) ResultSet(java.sql.ResultSet) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLException(java.sql.SQLException)

Aggregations

RunnableX (org.apache.ignite.testframework.GridTestUtils.RunnableX)126 SQLException (java.sql.SQLException)104 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)80 Test (org.junit.Test)78 Connection (java.sql.Connection)64 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)54 SQLClientInfoException (java.sql.SQLClientInfoException)50 JdbcThinConnection (org.apache.ignite.internal.jdbc.thin.JdbcThinConnection)50 IgniteException (org.apache.ignite.IgniteException)22 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)20 ResultSet (java.sql.ResultSet)18 Savepoint (java.sql.Savepoint)18 CacheException (javax.cache.CacheException)16 QueryIndex (org.apache.ignite.cache.QueryIndex)16 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)16 DatabaseMetaData (java.sql.DatabaseMetaData)10 PreparedStatement (java.sql.PreparedStatement)10 MalformedURLException (java.net.MalformedURLException)6 Statement (java.sql.Statement)6 Ignite (org.apache.ignite.Ignite)6