Search in sources :

Example 1 with TeiidStatement

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

the class TeiidSql method getPlanInfo.

protected void getPlanInfo(Statement s) {
    if (s == null) {
        return;
    }
    TeiidStatement ts;
    try {
        ts = s.unwrap(TeiidStatement.class);
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
    plan = ts.getPlanDescription();
    annotations = ts.getAnnotations();
    debugLog = ts.getDebugLog();
    try {
        warnings = ts.getWarnings();
    } catch (SQLException e) {
        LOG.log(Level.WARNING, "Caught exception getting warnings: " + e, e);
    }
}
Also used : SQLException(java.sql.SQLException) TeiidStatement(org.teiid.jdbc.TeiidStatement)

Example 2 with TeiidStatement

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

the class TestAsynch method testAsynchPlaning.

@Test
public void testAsynchPlaning() throws Exception {
    Statement stmt = this.internalConnection.createStatement();
    TeiidStatement ts = stmt.unwrap(TeiidStatement.class);
    ef.addData("SELECT someTable.col FROM someTable", Arrays.asList(Arrays.asList(1)));
    final ResultsFuture<Integer> result = new ResultsFuture<Integer>();
    ts.submitExecute("select * from someTable", new StatementCallback() {

        int rowCount;

        @Override
        public void onRow(Statement s, ResultSet rs) {
            try {
                rowCount++;
                if (rowCount == 3) {
                    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());
    assertEquals(3, partIds.size());
    assertEquals(partIds.get(0), partIds.get(1));
    assertEquals(partIds.get(1), partIds.get(2));
}
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 3 with TeiidStatement

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

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

the class TestAsynch method testTransactionCycle.

@Test
public void testTransactionCycle() throws Exception {
    Statement stmt = this.internalConnection.createStatement();
    TeiidStatement ts = stmt.unwrap(TeiidStatement.class);
    final ResultsFuture<Void> result = new ResultsFuture<Void>();
    ts.submitExecute("start transaction", new StatementCallback() {

        @Override
        public void onRow(Statement s, ResultSet rs) {
        }

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

        @Override
        public void onComplete(Statement s) {
            result.getResultsReceiver().receiveResults(null);
        }
    }, new RequestOptions());
    result.get();
    final ResultsFuture<Void> rollBackResult = new ResultsFuture<Void>();
    ts.submitExecute("rollback", new StatementCallback() {

        @Override
        public void onRow(Statement s, ResultSet rs) {
        }

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

        @Override
        public void onComplete(Statement s) {
            rollBackResult.getResultsReceiver().receiveResults(null);
        }
    }, new RequestOptions());
    rollBackResult.get();
}
Also used : ResultsFuture(org.teiid.client.util.ResultsFuture) ContinuousStatementCallback(org.teiid.jdbc.ContinuousStatementCallback) StatementCallback(org.teiid.jdbc.StatementCallback) 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 5 with TeiidStatement

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

the class TestExecutionReuse method testReusableAsynchContinuous.

@Test
public void testReusableAsynchContinuous() throws Exception {
    Connection c = server.createConnection("jdbc:teiid:partssupplier");
    Statement s = c.createStatement();
    TeiidStatement ts = s.unwrap(TeiidStatement.class);
    final ResultsFuture<Integer> result = new ResultsFuture<Integer>();
    ts.submitExecute("select part_id from parts order by part_id", new StatementCallback() {

        int rowCount;

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

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

        @Override
        public void onComplete(Statement stmt) {
            result.getResultsReceiver().receiveResults(rowCount);
        }
    }, new RequestOptions().continuous(true));
    synchronized (TestExecutionReuse.class) {
        while (!isDisposed) {
            TestExecutionReuse.class.wait();
        }
    }
    assertEquals(EXEC_COUNT, result.get().intValue());
    assertTrue(ec.getCommandContext().isContinuous());
    Mockito.verify(execution, Mockito.times(1)).dispose();
    Mockito.verify(execution, Mockito.times(EXEC_COUNT)).execute();
    Mockito.verify(execution, Mockito.times(EXEC_COUNT)).close();
    Mockito.verify(execution, Mockito.times(EXEC_COUNT - 1)).reset((Command) Mockito.anyObject(), (ExecutionContext) Mockito.anyObject(), Mockito.anyObject());
}
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) Connection(java.sql.Connection) SQLException(java.sql.SQLException) TranslatorException(org.teiid.translator.TranslatorException) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) ResultsFuture(org.teiid.client.util.ResultsFuture) StatementCallback(org.teiid.jdbc.StatementCallback) ResultSet(java.sql.ResultSet) 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