Search in sources :

Example 41 with RunnableX

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

the class JdbcThinConnectionMvccEnabledSelfTest method testSetSavepoint.

/**
 * @throws Exception If failed.
 */
@Test
public void testSetSavepoint() throws Exception {
    try (Connection conn = DriverManager.getConnection(URL)) {
        assert !conn.getMetaData().supportsSavepoints();
        // Disallowed in auto-commit mode
        assertThrows(log, new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                conn.setSavepoint();
                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();
            }
        });
        conn.close();
        checkConnectionClosed(new RunnableX() {

            @Override
            public void runx() throws Exception {
                conn.setSavepoint();
            }
        });
    }
}
Also used : RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) Connection(java.sql.Connection) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 42 with RunnableX

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

the class JdbcThinConnectionSelfTest method testGetSetSchema.

/**
 * @throws Exception If failed.
 */
@Test
public void testGetSetSchema() throws Exception {
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
        assertEquals("PUBLIC", conn.getSchema());
        final String schema = "test";
        conn.setSchema(schema);
        assertEquals(schema.toUpperCase(), conn.getSchema());
        conn.setSchema('"' + schema + '"');
        assertEquals(schema, conn.getSchema());
        conn.close();
        checkConnectionClosed(new RunnableX() {

            @Override
            public void runx() throws Exception {
                conn.setSchema(schema);
            }
        });
        checkConnectionClosed(new RunnableX() {

            @Override
            public void runx() throws Exception {
                conn.getSchema();
            }
        });
    }
}
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 43 with RunnableX

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

the class JdbcThinConnectionSelfTest method testSetSavepoint.

/**
 * @throws Exception If failed.
 */
@Test
public void testSetSavepoint() throws Exception {
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
        assert !conn.getMetaData().supportsSavepoints();
        // Disallowed in auto-commit mode
        assertThrows(log, new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                conn.setSavepoint();
                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();
            }
        });
    }
}
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 44 with RunnableX

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

the class JdbcThinConnectionSelfTest method testGetMetaData.

/**
 * @throws Exception If failed.
 */
@Test
public void testGetMetaData() throws Exception {
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
        DatabaseMetaData meta = conn.getMetaData();
        assertNotNull(meta);
        conn.close();
        // Exception when called on closed connection
        checkConnectionClosed(new RunnableX() {

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

Example 45 with RunnableX

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

the class JdbcThinConnectionSelfTest method testGetSetTransactionIsolation.

/**
 * @throws Exception If failed.
 */
@Test
public void testGetSetTransactionIsolation() throws Exception {
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
        // Invalid parameter value
        assertThrows(log, new Callable<Object>() {

            @SuppressWarnings("MagicConstant")
            @Override
            public Object call() throws Exception {
                conn.setTransactionIsolation(-1);
                return null;
            }
        }, SQLException.class, "Invalid transaction isolation level");
        // default level
        assertEquals(TRANSACTION_NONE, conn.getTransactionIsolation());
        int[] levels = { TRANSACTION_READ_UNCOMMITTED, TRANSACTION_READ_COMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE };
        for (int level : levels) {
            conn.setTransactionIsolation(level);
            assertEquals(level, conn.getTransactionIsolation());
        }
        conn.close();
        // Exception when called on closed connection
        checkConnectionClosed(new RunnableX() {

            @Override
            public void runx() throws Exception {
                conn.getTransactionIsolation();
            }
        });
        // Exception when called on closed connection
        checkConnectionClosed(new RunnableX() {

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

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