Search in sources :

Example 1 with ContinuousStatementCallback

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

the class TestAsynch method testAsynchContinuousEmpty.

@Test
public void testAsynchContinuousEmpty() 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.Schemas where 1 = 0", new ContinuousStatementCallback() {

        int execCount;

        @Override
        public void onRow(Statement s, ResultSet rs) throws SQLException {
            fail();
        }

        @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++;
            assertEquals(-1, s.getResultSet().unwrap(TeiidResultSet.class).available());
            if (execCount == 1024) {
                s.close();
            }
        }
    }, new RequestOptions().continuous(true));
    assertEquals(1024, 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 2 with ContinuousStatementCallback

use of org.teiid.jdbc.ContinuousStatementCallback 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)

Aggregations

ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Statement (java.sql.Statement)2 Test (org.junit.Test)2 ResultsFuture (org.teiid.client.util.ResultsFuture)2 AsynchPositioningException (org.teiid.jdbc.AsynchPositioningException)2 ContinuousStatementCallback (org.teiid.jdbc.ContinuousStatementCallback)2 RequestOptions (org.teiid.jdbc.RequestOptions)2 TeiidResultSet (org.teiid.jdbc.TeiidResultSet)2 TeiidStatement (org.teiid.jdbc.TeiidStatement)2 TranslatorException (org.teiid.translator.TranslatorException)2