Search in sources :

Example 6 with TeiidStatement

use of org.teiid.jdbc.TeiidStatement in project teiid by teiid.

the class TestAsynch method testAsynchContinuousMergeBlock.

@Test
public void testAsynchContinuousMergeBlock() throws Exception {
    Statement stmt = this.internalConnection.createStatement();
    stmt.execute("create temporary table t (c string, primary key (c))");
    stmt.execute("set autoCommitTxn off");
    TeiidStatement ts = stmt.unwrap(TeiidStatement.class);
    final ResultsFuture<Integer> result = new ResultsFuture<Integer>();
    ts.submitExecute("begin merge into t select name from schemas limit 2; select rowcount; end", new StatementCallback() {

        int rowCount;

        @Override
        public void onRow(Statement s, ResultSet rs) throws SQLException {
            rowCount++;
            if (rowCount == 10) {
                s.close();
            }
        }

        @Override
        public void onException(Statement s, Exception e) {
            result.getResultsReceiver().exceptionOccurred(e);
        }

        @Override
        public void onComplete(Statement s) {
            result.getResultsReceiver().receiveResults(rowCount);
        }
    }, new RequestOptions().continuous(true));
    assertEquals(10, result.get().intValue());
    stmt = this.internalConnection.createStatement();
    ResultSet rs = stmt.executeQuery("select count(*) from t");
    rs.next();
    assertEquals(2, rs.getInt(1));
}
Also used : ResultsFuture(org.teiid.client.util.ResultsFuture) ContinuousStatementCallback(org.teiid.jdbc.ContinuousStatementCallback) StatementCallback(org.teiid.jdbc.StatementCallback) SQLException(java.sql.SQLException) RequestOptions(org.teiid.jdbc.RequestOptions) TeiidStatement(org.teiid.jdbc.TeiidStatement) Statement(java.sql.Statement) TeiidStatement(org.teiid.jdbc.TeiidStatement) ResultSet(java.sql.ResultSet) TeiidResultSet(org.teiid.jdbc.TeiidResultSet) AsynchPositioningException(org.teiid.jdbc.AsynchPositioningException) SQLException(java.sql.SQLException) TranslatorException(org.teiid.translator.TranslatorException) Test(org.junit.Test)

Example 7 with TeiidStatement

use of org.teiid.jdbc.TeiidStatement in project teiid by teiid.

the class TestAsynch method testAsynchContinuousNonEmpty.

@Test
public void testAsynchContinuousNonEmpty() throws Exception {
    Statement stmt = this.internalConnection.createStatement();
    TeiidStatement ts = stmt.unwrap(TeiidStatement.class);
    final ResultsFuture<Integer> result = new ResultsFuture<Integer>();
    ts.submitExecute("select 1", new ContinuousStatementCallback() {

        int execCount;

        @Override
        public void onRow(Statement s, ResultSet rs) throws SQLException {
            assertEquals(0, rs.unwrap(TeiidResultSet.class).available());
            s.close();
        }

        @Override
        public void onException(Statement s, Exception e) {
            result.getResultsReceiver().exceptionOccurred(e);
        }

        @Override
        public void onComplete(Statement s) {
            result.getResultsReceiver().receiveResults(execCount);
        }

        @Override
        public void beforeNextExecution(Statement s) throws SQLException {
            execCount++;
        }
    }, new RequestOptions().continuous(true));
    assertEquals(0, result.get().intValue());
}
Also used : SQLException(java.sql.SQLException) RequestOptions(org.teiid.jdbc.RequestOptions) TeiidStatement(org.teiid.jdbc.TeiidStatement) Statement(java.sql.Statement) TeiidStatement(org.teiid.jdbc.TeiidStatement) AsynchPositioningException(org.teiid.jdbc.AsynchPositioningException) SQLException(java.sql.SQLException) TranslatorException(org.teiid.translator.TranslatorException) ResultsFuture(org.teiid.client.util.ResultsFuture) ContinuousStatementCallback(org.teiid.jdbc.ContinuousStatementCallback) ResultSet(java.sql.ResultSet) TeiidResultSet(org.teiid.jdbc.TeiidResultSet) TeiidResultSet(org.teiid.jdbc.TeiidResultSet) Test(org.junit.Test)

Example 8 with TeiidStatement

use of org.teiid.jdbc.TeiidStatement in project teiid by teiid.

the class TestAsynch method testAsynchAnon.

/**
 * Runs sufficient iterations to ensure the temptablestore state is correct
 * @throws Exception
 */
@Test
public void testAsynchAnon() throws Exception {
    String query = "begin\n" + "insert into #mom_collectors select 'a' as hostname, 123 as port, 1 as id from sometable;\n" + "insert into #apm_collectors select 'a' as hostname, 124 as port, 12 as id from sometable;\n" + "select 'add', hostname, port, id from #mom_collectors\n" + "where (hostname, port) not in (select (hostname, port) from #apm_collectors)\n" + "union select 'delete', hostname, port, id from #apm_collectors\n" + "where (hostname, port) not in (select (hostname, port) from #mom_collectors) with return; end";
    Statement stmt = this.internalConnection.createStatement();
    TeiidStatement ts = stmt.unwrap(TeiidStatement.class);
    ef.addData("SELECT someTable.col FROM someTable", Collections.nCopies(1, Arrays.asList(1)));
    ts.setExecutionProperty("autoCommitTxn", "off");
    final ResultsFuture<Integer> result = new ResultsFuture<Integer>();
    ts.submitExecute(query, new StatementCallback() {

        int rowCount;

        @Override
        public void onRow(Statement s, ResultSet rs) {
            try {
                rowCount++;
                if (rowCount == 100000) {
                    s.close();
                }
            } catch (SQLException e) {
                result.getResultsReceiver().exceptionOccurred(e);
                throw new RuntimeException(e);
            }
        }

        @Override
        public void onException(Statement s, Exception e) {
            result.getResultsReceiver().exceptionOccurred(e);
        }

        @Override
        public void onComplete(Statement s) {
            result.getResultsReceiver().receiveResults(rowCount);
        }
    }, new RequestOptions().continuous(true));
    assertEquals(100000, result.get().intValue());
}
Also used : SQLException(java.sql.SQLException) RequestOptions(org.teiid.jdbc.RequestOptions) TeiidStatement(org.teiid.jdbc.TeiidStatement) Statement(java.sql.Statement) TeiidStatement(org.teiid.jdbc.TeiidStatement) AsynchPositioningException(org.teiid.jdbc.AsynchPositioningException) SQLException(java.sql.SQLException) TranslatorException(org.teiid.translator.TranslatorException) ResultsFuture(org.teiid.client.util.ResultsFuture) ContinuousStatementCallback(org.teiid.jdbc.ContinuousStatementCallback) StatementCallback(org.teiid.jdbc.StatementCallback) ResultSet(java.sql.ResultSet) TeiidResultSet(org.teiid.jdbc.TeiidResultSet) Test(org.junit.Test)

Example 9 with TeiidStatement

use of org.teiid.jdbc.TeiidStatement in project teiid by teiid.

the class TestAsynch method testAsynch.

@Test
public void testAsynch() throws Exception {
    Statement stmt = this.internalConnection.createStatement();
    TeiidStatement ts = stmt.unwrap(TeiidStatement.class);
    final ResultsFuture<Integer> result = new ResultsFuture<Integer>();
    ts.submitExecute("select * from sys.tables a, sys.tables b, sys.tables c", new StatementCallback() {

        int rowCount;

        @Override
        public void onRow(Statement s, ResultSet rs) {
            rowCount++;
            try {
                if (!rs.isLast()) {
                    assertTrue(rs.unwrap(TeiidResultSet.class).available() > 0);
                }
                if (rowCount == 10000) {
                    s.close();
                }
            } catch (AsynchPositioningException e) {
                try {
                    assertEquals(0, rs.unwrap(TeiidResultSet.class).available());
                } catch (SQLException e1) {
                    result.getResultsReceiver().exceptionOccurred(e1);
                }
            } catch (SQLException e) {
                result.getResultsReceiver().exceptionOccurred(e);
            }
        }

        @Override
        public void onException(Statement s, Exception e) {
            result.getResultsReceiver().exceptionOccurred(e);
        }

        @Override
        public void onComplete(Statement s) {
            result.getResultsReceiver().receiveResults(rowCount);
        }
    }, new RequestOptions());
    assertEquals(10000, result.get().intValue());
}
Also used : SQLException(java.sql.SQLException) RequestOptions(org.teiid.jdbc.RequestOptions) TeiidStatement(org.teiid.jdbc.TeiidStatement) Statement(java.sql.Statement) TeiidStatement(org.teiid.jdbc.TeiidStatement) AsynchPositioningException(org.teiid.jdbc.AsynchPositioningException) AsynchPositioningException(org.teiid.jdbc.AsynchPositioningException) SQLException(java.sql.SQLException) TranslatorException(org.teiid.translator.TranslatorException) ResultsFuture(org.teiid.client.util.ResultsFuture) ContinuousStatementCallback(org.teiid.jdbc.ContinuousStatementCallback) StatementCallback(org.teiid.jdbc.StatementCallback) ResultSet(java.sql.ResultSet) TeiidResultSet(org.teiid.jdbc.TeiidResultSet) Test(org.junit.Test)

Example 10 with TeiidStatement

use of org.teiid.jdbc.TeiidStatement in project teiid by teiid.

the class TestAsynch method testAsynchContinuous.

@Test
public void testAsynchContinuous() throws Exception {
    Statement stmt = this.internalConnection.createStatement();
    TeiidStatement ts = stmt.unwrap(TeiidStatement.class);
    final ResultsFuture<Integer> result = new ResultsFuture<Integer>();
    ts.submitExecute("select xmlelement(name x) from SYS.Schemas", new StatementCallback() {

        int rowCount;

        @Override
        public void onRow(Statement s, ResultSet rs) throws SQLException {
            rowCount++;
            if (rowCount == 1024) {
                s.close();
            }
        }

        @Override
        public void onException(Statement s, Exception e) {
            result.getResultsReceiver().exceptionOccurred(e);
        }

        @Override
        public void onComplete(Statement s) {
            result.getResultsReceiver().receiveResults(rowCount);
        }
    }, new RequestOptions().continuous(true));
    assertEquals(1024, result.get().intValue());
}
Also used : ResultsFuture(org.teiid.client.util.ResultsFuture) ContinuousStatementCallback(org.teiid.jdbc.ContinuousStatementCallback) StatementCallback(org.teiid.jdbc.StatementCallback) SQLException(java.sql.SQLException) RequestOptions(org.teiid.jdbc.RequestOptions) TeiidStatement(org.teiid.jdbc.TeiidStatement) Statement(java.sql.Statement) TeiidStatement(org.teiid.jdbc.TeiidStatement) ResultSet(java.sql.ResultSet) TeiidResultSet(org.teiid.jdbc.TeiidResultSet) AsynchPositioningException(org.teiid.jdbc.AsynchPositioningException) SQLException(java.sql.SQLException) TranslatorException(org.teiid.translator.TranslatorException) Test(org.junit.Test)

Aggregations

SQLException (java.sql.SQLException)11 TeiidStatement (org.teiid.jdbc.TeiidStatement)11 ResultSet (java.sql.ResultSet)10 Statement (java.sql.Statement)10 Test (org.junit.Test)10 ResultsFuture (org.teiid.client.util.ResultsFuture)10 RequestOptions (org.teiid.jdbc.RequestOptions)10 TranslatorException (org.teiid.translator.TranslatorException)10 AsynchPositioningException (org.teiid.jdbc.AsynchPositioningException)9 ContinuousStatementCallback (org.teiid.jdbc.ContinuousStatementCallback)9 TeiidResultSet (org.teiid.jdbc.TeiidResultSet)9 StatementCallback (org.teiid.jdbc.StatementCallback)8 Connection (java.sql.Connection)1 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)1