Search in sources :

Example 51 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)

Example 52 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 53 with RunnableX

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

the class JdbcThinStatementSelfTest method testGetSetMaxFieldSizeUnsupported.

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

        @Override
        public Object call() throws Exception {
            stmt.setMaxFieldSize(100);
            return null;
        }
    }, SQLFeatureNotSupportedException.class, "Field size limitation is not supported");
    assertEquals(0, stmt.getMaxFieldSize());
    stmt.close();
    // Call on a closed statement
    checkStatementClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            stmt.getMaxFieldSize();
        }
    });
    // Call on a closed statement
    checkStatementClosed(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)

Example 54 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 55 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)

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