Search in sources :

Example 56 with RunnableX

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

the class JdbcThinStatementSelfTest method testGetMoreResultsCloseAll.

/**
 * @throws Exception If failed.
 */
@org.junit.Test
public void testGetMoreResultsCloseAll() 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.CLOSE_ALL_RESULTS));
    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)

Example 57 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 58 with RunnableX

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

the class JdbcThinResultSetSelfTest method testExceptionOnClosedResultSet.

/**
 * @throws Exception If failed.
 */
@Test
public void testExceptionOnClosedResultSet() throws Exception {
    final ResultSet rs = stmt.executeQuery(SQL);
    rs.close();
    // Must do nothing on closed result set
    rs.close();
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getBoolean(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getBoolean("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getByte(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getByte("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getShort(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getShort("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getInt(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getInt("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getLong(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getLong("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getFloat(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getFloat("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getDouble(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getDouble("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getString(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getString("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getBytes(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getBytes("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getDate(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getDate(1, new GregorianCalendar());
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getDate("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getDate("id", new GregorianCalendar());
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getTime(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getTime(1, new GregorianCalendar());
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getTime("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getTime("id", new GregorianCalendar());
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getTimestamp(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getTimestamp(1, new GregorianCalendar());
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getTimestamp("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getTimestamp("id", new GregorianCalendar());
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getObject("objVal");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getObject("objVal", TestObjectField.class);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.wasNull();
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getMetaData();
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.next();
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.last();
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.afterLast();
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.beforeFirst();
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.first();
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.findColumn("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getRow();
        }
    });
}
Also used : RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) ResultSet(java.sql.ResultSet) GregorianCalendar(java.util.GregorianCalendar) SQLException(java.sql.SQLException) MalformedURLException(java.net.MalformedURLException) Test(org.junit.Test)

Example 59 with RunnableX

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

the class JdbcThinResultSetSelfTest method testNotSupportedTypes.

/**
 * @throws Exception If failed.
 */
@Test
public void testNotSupportedTypes() throws Exception {
    final ResultSet rs = stmt.executeQuery(SQL);
    assert rs.next();
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getArray(1);
        }
    });
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getArray("id");
        }
    });
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getAsciiStream(1);
        }
    });
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getAsciiStream("id");
        }
    });
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getBinaryStream(1);
        }
    });
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getBinaryStream("id");
        }
    });
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getBlob(1);
        }
    });
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getBlob("id");
        }
    });
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getClob(1);
        }
    });
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getClob("id");
        }
    });
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getCharacterStream(1);
        }
    });
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getCharacterStream("id");
        }
    });
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getNCharacterStream(1);
        }
    });
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getNCharacterStream("id");
        }
    });
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getNClob(1);
        }
    });
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getNClob("id");
        }
    });
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getRef(1);
        }
    });
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getRef("id");
        }
    });
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getRowId(1);
        }
    });
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getRowId("id");
        }
    });
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getSQLXML(1);
        }
    });
    checkNotSupported(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getSQLXML("id");
        }
    });
}
Also used : RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) ResultSet(java.sql.ResultSet) SQLException(java.sql.SQLException) MalformedURLException(java.net.MalformedURLException) Test(org.junit.Test)

Example 60 with RunnableX

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

the class DynamicIndexAbstractBasicSelfTest method checkCreate.

/**
 * Check normal create operation.
 *
 * @param mode Mode.
 * @param atomicityMode Atomicity mode.
 * @param near Near flag.
 * @throws Exception If failed.
 */
private void checkCreate(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
    initialize(mode, atomicityMode, near);
    final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1_ESCAPED));
    dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false, 0);
    assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, QueryIndex.DFLT_INLINE_SIZE, field(FIELD_NAME_1_ESCAPED));
    assertIgniteSqlException(new RunnableX() {

        @Override
        public void runx() throws Exception {
            dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, false, 0);
        }
    }, IgniteQueryErrorCode.INDEX_ALREADY_EXISTS);
    dynamicIndexCreate(CACHE_NAME, TBL_NAME, idx, true, 0);
    assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1, QueryIndex.DFLT_INLINE_SIZE, field(FIELD_NAME_1_ESCAPED));
    assertSimpleIndexOperations(SQL_SIMPLE_FIELD_1);
    assertIndexUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1);
}
Also used : RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) QueryIndex(org.apache.ignite.cache.QueryIndex) CacheException(javax.cache.CacheException) IgniteException(org.apache.ignite.IgniteException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException)

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