Search in sources :

Example 21 with RunnableX

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

the class JdbcThinStatementSelfTest method testGetSetMaxRows.

/**
 * @throws Exception If failed.
 */
@org.junit.Test
public void testGetSetMaxRows() throws Exception {
    assertEquals(0, stmt.getMaxRows());
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            stmt.setMaxRows(-1);
            return null;
        }
    }, SQLException.class, "Invalid max rows value");
    assertEquals(0, stmt.getMaxRows());
    final int maxRows = 1;
    stmt.setMaxRows(maxRows);
    assertEquals(maxRows, stmt.getMaxRows());
    String sqlText = "select * from test";
    ResultSet rs = stmt.executeQuery(sqlText);
    assertTrue(rs.next());
    // max rows reached
    assertFalse(rs.next());
    stmt.close();
    // Call on a closed statement
    checkStatementClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            stmt.getMaxRows();
        }
    });
    // Call on a closed statement
    checkStatementClosed(new RunnableX() {

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

Example 22 with RunnableX

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

the class JdbcThinStatementSelfTest method testExecuteQuery1.

/**
 * @throws Exception If failed.
 */
@org.junit.Test
public void testExecuteQuery1() throws Exception {
    final String sqlText = "select val from test";
    try (ResultSet rs = stmt.executeQuery(sqlText)) {
        assertNotNull(rs);
        assertTrue(rs.next());
        int val = rs.getInt(1);
        assertTrue("Invalid val: " + val, val >= 1 && val <= 10);
    }
    stmt.close();
    // Call on a closed statement
    checkStatementClosed(new RunnableX() {

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

Example 23 with RunnableX

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

the class JdbcThinStatementSelfTest method testGetSetQueryTimeout.

/**
 * @throws Exception If failed.
 */
@org.junit.Test
public void testGetSetQueryTimeout() throws Exception {
    assertEquals(0, stmt.getQueryTimeout());
    // Invalid argument
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            stmt.setQueryTimeout(-1);
            return null;
        }
    }, SQLException.class, "Invalid timeout value");
    assertEquals(0, stmt.getQueryTimeout());
    final int timeout = 3;
    stmt.setQueryTimeout(timeout);
    assertEquals(timeout, stmt.getQueryTimeout());
    stmt.close();
    // Call on a closed statement
    checkStatementClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            stmt.getQueryTimeout();
        }
    });
    // Call on a closed statement
    checkStatementClosed(new RunnableX() {

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

Example 24 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 25 with RunnableX

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

the class JdbcThinStatementSelfTest method testMaxFieldSize.

/**
 * @throws Exception If failed.
 */
@org.junit.Test
public void testMaxFieldSize() throws Exception {
    assertTrue(stmt.getMaxFieldSize() >= 0);
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            stmt.setMaxFieldSize(-1);
            return null;
        }
    }, SQLException.class, "Invalid field limit");
    checkNotSupported(new RunnableX() {

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

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