Search in sources :

Example 6 with StatementCallback

use of org.teiid.jdbc.StatementCallback 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 7 with StatementCallback

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

Example 8 with StatementCallback

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

the class TestAsynch method testAsynchContinuousWithAlter.

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

        int rowCount;

        @Override
        public void onRow(Statement s, ResultSet rs) {
            try {
                rowCount++;
                if (rowCount < 3) {
                    assertEquals(1, rs.getInt(1));
                    if (rowCount == 2) {
                        Statement st = internalConnection.createStatement();
                        st.execute("alter view v.test as select 2");
                        st.close();
                        try {
                            // we only track down to millisecond resolution
                            Thread.sleep(100);
                        } catch (InterruptedException e) {
                            result.getResultsReceiver().exceptionOccurred(e);
                        }
                    }
                } else {
                    // new value
                    assertEquals(2, rs.getInt(1));
                    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(3, 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)

Aggregations

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