Search in sources :

Example 1 with AsynchPositioningException

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

Aggregations

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