Search in sources :

Example 26 with ResultsFuture

use of org.teiid.client.util.ResultsFuture in project teiid by teiid.

the class MaterializationManager method runJob.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void runJob(final CompositeVDB vdb, final Table table, final long ttl, final boolean onetimeJob) {
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
    String command = "execute SYSADMIN.loadMatView('" + StringUtil.replaceAll(table.getParent().getName(), "'", "''") + "','" + StringUtil.replaceAll(table.getName(), "'", "''") + "')";
    try {
        final AtomicInteger procReturn = new AtomicInteger();
        executeAsynchQuery(vdb.getVDB(), command, new DQPCore.ResultsListener() {

            @Override
            public void onResults(List<String> columns, List<? extends List<?>> results) throws Exception {
                procReturn.set((Integer) results.get(0).get(0));
            }
        }).addCompletionListener(new CompletionListener() {

            @Override
            public void onCompletion(ResultsFuture future) {
                try {
                    future.get();
                    if (!onetimeJob) {
                        if (procReturn.get() >= 0) {
                            scheduleSnapshotJob(vdb, table, ttl, ttl, onetimeJob);
                        } else {
                            // when in error re-schedule in 1 min or less
                            scheduleSnapshotJob(vdb, table, ttl, Math.min(ttl / 4, WAITTIME), onetimeJob);
                        }
                    }
                } catch (InterruptedException e) {
                } catch (ExecutionException e) {
                    LogManager.logWarning(LogConstants.CTX_MATVIEWS, e, e.getMessage());
                    // re-schedule the same job in one minute
                    scheduleSnapshotJob(vdb, table, ttl, Math.min(ttl / 4, WAITTIME), onetimeJob);
                }
            }
        });
    } catch (SQLException e) {
        LogManager.logWarning(LogConstants.CTX_MATVIEWS, e, e.getMessage());
        // re-schedule the same job in one minute
        scheduleSnapshotJob(vdb, table, ttl, Math.min(ttl / 4, WAITTIME), onetimeJob);
    }
}
Also used : ResultsFuture(org.teiid.client.util.ResultsFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompletionListener(org.teiid.client.util.ResultsFuture.CompletionListener) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException)

Example 27 with ResultsFuture

use of org.teiid.client.util.ResultsFuture in project teiid by teiid.

the class TestLocalConnections method testWaitForLoadTimeout.

@Test
public void testWaitForLoadTimeout() throws Exception {
    final ResultsFuture<Void> future = new ResultsFuture<Void>();
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                server.createConnection("jdbc:teiid:not_there.1;waitForLoad=1000");
                future.getResultsReceiver().receiveResults(null);
            } catch (Exception e) {
                future.getResultsReceiver().exceptionOccurred(e);
            }
        }
    };
    t.setDaemon(true);
    t.start();
    assertFalse(future.isDone());
    try {
        server.deployVDB(new ByteArrayInputStream("<vdb name=\"not_there\" version=\"1\"><model name=\"myschema\"><source name=\"x\" translator-name=\"x\" connection-jndi-name=\"x\"/></model></vdb>".getBytes(Charset.forName("UTF-8"))));
        fail();
    } catch (TranslatorException e) {
    // no connection factory
    }
    try {
        future.get(5000, TimeUnit.SECONDS);
        fail();
    } catch (ExecutionException e) {
        assertTrue(e.getMessage().contains("TEIID40097"));
    } finally {
        server.undeployVDB("not_there");
    }
}
Also used : ResultsFuture(org.teiid.client.util.ResultsFuture) ByteArrayInputStream(java.io.ByteArrayInputStream) TranslatorException(org.teiid.translator.TranslatorException) ExecutionException(java.util.concurrent.ExecutionException) LoginException(javax.security.auth.login.LoginException) InvalidSessionException(org.teiid.client.security.InvalidSessionException) LogonException(org.teiid.client.security.LogonException) SQLException(java.sql.SQLException) TranslatorException(org.teiid.translator.TranslatorException) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 28 with ResultsFuture

use of org.teiid.client.util.ResultsFuture 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)

Example 29 with ResultsFuture

use of org.teiid.client.util.ResultsFuture 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 30 with ResultsFuture

use of org.teiid.client.util.ResultsFuture 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

ResultsFuture (org.teiid.client.util.ResultsFuture)34 Test (org.junit.Test)21 SQLException (java.sql.SQLException)17 ResultsMessage (org.teiid.client.ResultsMessage)13 TranslatorException (org.teiid.translator.TranslatorException)11 ResultSet (java.sql.ResultSet)10 Statement (java.sql.Statement)10 RequestOptions (org.teiid.jdbc.RequestOptions)10 TeiidStatement (org.teiid.jdbc.TeiidStatement)10 AsynchPositioningException (org.teiid.jdbc.AsynchPositioningException)9 ContinuousStatementCallback (org.teiid.jdbc.ContinuousStatementCallback)9 TeiidResultSet (org.teiid.jdbc.TeiidResultSet)9 Properties (java.util.Properties)8 ExecutionException (java.util.concurrent.ExecutionException)8 StatementCallback (org.teiid.jdbc.StatementCallback)8 DQP (org.teiid.client.DQP)7 RequestMessage (org.teiid.client.RequestMessage)5 TeiidComponentException (org.teiid.core.TeiidComponentException)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4