Search in sources :

Example 11 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 12 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 13 with RunnableX

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

the class JdbcThinConnectionSelfTest method testCreateArrayOf.

/**
 * @throws Exception If failed.
 */
@Test
public void testCreateArrayOf() throws Exception {
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
        final String typeName = "varchar";
        final String[] elements = new String[] { "apple", "pear" };
        // Invalid typename
        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 runx() throws Exception {
                conn.createArrayOf(typeName, elements);
            }
        });
        conn.close();
        checkConnectionClosed(new RunnableX() {

            @Override
            public void runx() throws Exception {
                conn.createArrayOf(typeName, elements);
            }
        });
    }
}
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 14 with RunnableX

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

the class JdbcThinPreparedStatementSelfTest method testCustomObjectSupportCanBeDisabled.

/**
 * Ensure custom object support could be disabled via disabledFeatures connection property
 *      - start grid and create and fill table such one of the columns was user's object
 *      - from another connection with disabledFeatures set to {@link JdbcThinFeature#CUSTOM_OBJECT}
 *      execute query with filter by this object
 *      - verify that exception is thrown when you try to set custom object as statement param
 * @throws SQLException
 */
@Test
public void testCustomObjectSupportCanBeDisabled() throws SQLException {
    try (Connection conn = createConnection(JdbcThinFeature.CUSTOM_OBJECT);
        PreparedStatement stmt = conn.prepareStatement(SQL_PART + " where objVal is not distinct from ?")) {
        Throwable t = GridTestUtils.assertThrowsWithCause(new RunnableX() {

            @Override
            public void runx() throws Exception {
                stmt.setObject(1, new TestObjectField(100, "AAAA"));
            }
        }, SQLException.class);
        Assert.assertThat(t.getMessage(), is(containsString("Custom objects are not supported")));
    }
}
Also used : RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 15 with RunnableX

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

the class JdbcThinConnectionMvccEnabledSelfTest method testSetSavepointName.

/**
 * @throws Exception If failed.
 */
@Test
public void testSetSavepointName() throws Exception {
    try (Connection conn = DriverManager.getConnection(URL)) {
        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.setAutoCommit(false);
        // Unsupported
        checkNotSupported(new RunnableX() {

            @Override
            public void runx() throws Exception {
                conn.setSavepoint(name);
            }
        });
        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) SQLException(java.sql.SQLException) Test(org.junit.Test)

Aggregations

RunnableX (org.apache.ignite.testframework.GridTestUtils.RunnableX)63 SQLException (java.sql.SQLException)52 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)40 Test (org.junit.Test)39 Connection (java.sql.Connection)32 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)27 SQLClientInfoException (java.sql.SQLClientInfoException)25 JdbcThinConnection (org.apache.ignite.internal.jdbc.thin.JdbcThinConnection)25 IgniteException (org.apache.ignite.IgniteException)11 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)10 ResultSet (java.sql.ResultSet)9 Savepoint (java.sql.Savepoint)9 CacheException (javax.cache.CacheException)8 QueryIndex (org.apache.ignite.cache.QueryIndex)8 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)8 DatabaseMetaData (java.sql.DatabaseMetaData)5 PreparedStatement (java.sql.PreparedStatement)5 MalformedURLException (java.net.MalformedURLException)3 Statement (java.sql.Statement)3 Ignite (org.apache.ignite.Ignite)3