Package org.teiid.client

Examples of org.teiid.client.ResultsMessage


          long start = System.currentTimeMillis();
          RequestMessage request = new RequestMessage(command);
          request.setExecutionId(0L);
          request.setRowLimit(getMaxRowsFetchSize()); // this would limit the number of rows that are returned.
          Future<ResultsMessage> message = dqpCore.executeRequest(requestID, request);
          ResultsMessage rm = message.get(timoutInMilli, TimeUnit.MILLISECONDS);
         
              if (rm.getException() != null) {
                  throw new AdminProcessingException(rm.getException());
              }
             
              if (rm.isUpdateResult()) {
                results.addAll(new ArrayList(Arrays.asList("update count"))); //$NON-NLS-1$
                results.addAll(Arrays.asList(rm.getResults()));               
              }
              else {
                results.addAll(new ArrayList(Arrays.asList(rm.getColumnNames())));
                results.addAll(Arrays.asList(fixResults(rm.getResults())));
               
                while (rm.getFinalRow() == -1 || rm.getLastRow() < rm.getFinalRow()) {
                  long elapsed = System.currentTimeMillis() - start;
              message = dqpCore.processCursorRequest(requestID, rm.getLastRow()+1, 1024);
              rm = message.get(timoutInMilli-elapsed, TimeUnit.MILLISECONDS);
              results.addAll(Arrays.asList(fixResults(rm.getResults())));
                }
              }

              long elapsed = System.currentTimeMillis() - start;
              ResultsFuture<?> response = dqpCore.closeRequest(requestID);
View Full Code Here


        return createResultSet(records, rsmd);
    }

    ResultSetImpl createResultSet(List records, ResultSetMetaData rsmd) throws SQLException {
      rsmd.getScale(1); //force the load of the metadata
        ResultsMessage resultsMsg = createDummyResultsMessage(null, null, records);
    resultSet = new ResultSetImpl(resultsMsg, this, rsmd, 0);
    resultSet.setMaxFieldSize(this.maxFieldSize);
        return resultSet;
    }
View Full Code Here

    resultSet.setMaxFieldSize(this.maxFieldSize);
        return resultSet;
    }

    static ResultsMessage createDummyResultsMessage(String[] columnNames, String[] dataTypes, List records) {
        ResultsMessage resultsMsg = new ResultsMessage();
        resultsMsg.setColumnNames(columnNames);
        resultsMsg.setDataTypes(dataTypes);
        resultsMsg.setFirstRow(1);
        resultsMsg.setLastRow(records.size());
        resultsMsg.setFinalRow(records.size());
        resultsMsg.setResults((List[])records.toArray(new List[records.size()]));
        return resultsMsg;
    }
View Full Code Here

    public TestResultsMessage(String name) {
        super(name);
    }

  public static ResultsMessage example() {
        ResultsMessage message = new ResultsMessage();
        message.setColumnNames(new String[] {"A", "B", "C", "D"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        message.setDataTypes(new String[] {DataTypeManager.DefaultDataTypes.BIG_INTEGER,
                                           DataTypeManager.DefaultDataTypes.BIG_INTEGER,
                                           DataTypeManager.DefaultDataTypes.BIG_INTEGER,
                                           DataTypeManager.DefaultDataTypes.BIG_INTEGER});
        message.setFinalRow(200);
        message.setFirstRow(1);
        message.setLastRow(100);
        List parameters = new ArrayList();
        parameters.add(new ParameterInfo(ParameterInfo.IN, 0));
        parameters.add(new ParameterInfo(ParameterInfo.RESULT_SET, 5));
        message.setParameters(parameters);
        PlanNode planDescs = new PlanNode("test");
        planDescs.addProperty("key1", "val1"); //$NON-NLS-1$ //$NON-NLS-2$
        planDescs.addProperty("key2", "val2"); //$NON-NLS-1$ //$NON-NLS-2$
        planDescs.addProperty("key3", "val3"); //$NON-NLS-1$ //$NON-NLS-2$
        planDescs.addProperty("key4", "val4"); //$NON-NLS-1$ //$NON-NLS-2$
        message.setPlanDescription(planDescs);

        List results = new ArrayList();
        results.add(new BigInteger("100")); //$NON-NLS-1$
        results.add(new BigInteger("200")); //$NON-NLS-1$
        results.add(new BigInteger("300")); //$NON-NLS-1$
        results.add(new BigInteger("400")); //$NON-NLS-1$
        message.setResults(new List[] {results});
        List warnings = new ArrayList();
        warnings.add(new Exception("warning1")); //$NON-NLS-1$
        warnings.add(new Exception("warning2")); //$NON-NLS-1$
        message.setWarnings(warnings);
        return message;
    }
View Full Code Here

        message.setWarnings(warnings);
        return message;
    }
   
    public void testSerialize() throws Exception {
        ResultsMessage message = example();
       
        ResultsMessage copy = UnitTestUtil.helpSerialize(message);
       
        assertNotNull(copy.getColumnNames());
        assertEquals(4, copy.getColumnNames().length);
        assertEquals("A", copy.getColumnNames()[0]); //$NON-NLS-1$
        assertEquals("B", copy.getColumnNames()[1]); //$NON-NLS-1$
        assertEquals("C", copy.getColumnNames()[2]); //$NON-NLS-1$
        assertEquals("D", copy.getColumnNames()[3]); //$NON-NLS-1$
       
        assertNotNull(copy.getDataTypes());
        assertEquals(4, copy.getDataTypes().length);
        assertEquals(DataTypeManager.DefaultDataTypes.BIG_INTEGER, copy.getDataTypes()[0]);
        assertEquals(DataTypeManager.DefaultDataTypes.BIG_INTEGER, copy.getDataTypes()[1]);
        assertEquals(DataTypeManager.DefaultDataTypes.BIG_INTEGER, copy.getDataTypes()[2]);
        assertEquals(DataTypeManager.DefaultDataTypes.BIG_INTEGER, copy.getDataTypes()[3]);
       
        assertEquals(200, copy.getFinalRow());
        assertEquals(1, copy.getFirstRow());
        assertEquals(100, copy.getLastRow());
       
        assertNotNull(copy.getParameters());
        assertEquals(2, copy.getParameters().size());
        ParameterInfo info1 = (ParameterInfo) copy.getParameters().get(0);
        assertEquals(ParameterInfo.IN, info1.getType());
        assertEquals(0, info1.getNumColumns());
        ParameterInfo info2 = (ParameterInfo) copy.getParameters().get(1);
        assertEquals(ParameterInfo.RESULT_SET, info2.getType());
        assertEquals(5, info2.getNumColumns());
       
        assertNotNull(copy.getPlanDescription());
        assertEquals(4, copy.getPlanDescription().getProperties().size());
       
        assertNotNull(copy.getResults());
        assertEquals(1, copy.getResults().length);
        assertNotNull(copy.getResults()[0]);
        assertEquals(4, copy.getResults()[0].size());
        assertEquals(new BigInteger("100"), copy.getResults()[0].get(0)); //$NON-NLS-1$
        assertEquals(new BigInteger("200"), copy.getResults()[0].get(1)); //$NON-NLS-1$
        assertEquals(new BigInteger("300"), copy.getResults()[0].get(2)); //$NON-NLS-1$
        assertEquals(new BigInteger("400"), copy.getResults()[0].get(3)); //$NON-NLS-1$
       
        assertNotNull(copy.getWarnings());
        assertEquals(2, copy.getWarnings().size());
        assertEquals(Exception.class, copy.getWarnings().get(0).getClass());
        assertEquals("warning1", ((Exception)copy.getWarnings().get(0)).getMessage()); //$NON-NLS-1$
        assertEquals(Exception.class, copy.getWarnings().get(1).getClass());
        assertEquals("warning2", ((Exception)copy.getWarnings().get(1)).getMessage()); //$NON-NLS-1$
       
    }
View Full Code Here

    }

    @Test public void testEnvSessionId() throws Exception {
        String sql = "SELECT env('sessionid') as SessionID"; //$NON-NLS-1$
        String userName = "1"; //$NON-NLS-1$
        ResultsMessage rm = helpExecute(sql, userName);
        assertEquals("1", rm.getResults()[0].get(0)); //$NON-NLS-1$
    }
View Full Code Here

    }
   
    @Test public void testEnvSessionIdMixedCase() throws Exception {
        String sql = "SELECT env('sEsSIonId') as SessionID"; //$NON-NLS-1$
        String userName = "1"; //$NON-NLS-1$
        ResultsMessage rm = helpExecute(sql, userName);
        assertEquals("1", rm.getResults()[0].get(0)); //$NON-NLS-1$
    }
View Full Code Here

    @Test public void testLimitCompensation() throws Exception {
      String sql = "SELECT * FROM VQT.SmallA_2589g LIMIT 1, 1"; //$NON-NLS-1$
      BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
      caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
      agds.setCaps(caps);
      ResultsMessage rm = helpExecute(sql, "a"); //$NON-NLS-1$
      //we test for > 0 here because the autogen service doesn't obey the limit
      assertTrue(rm.getResults().length > 0);
    }
View Full Code Here

      assertTrue(rm.getResults().length > 0);
    }
   
    @Test public void testLimitCompensation1() throws Exception {
      String sql = "SELECT * FROM VQT.SmallA_2589g LIMIT 1, 1"; //$NON-NLS-1$
      ResultsMessage rm = helpExecute(sql, "a"); //$NON-NLS-1$
      assertEquals(1, rm.getResults().length);
    }
View Full Code Here

        reqMsg.setCursorType(ResultSet.TYPE_FORWARD_ONLY);
        DQPWorkContext.getWorkContext().getSession().setSessionId(sessionid);
        DQPWorkContext.getWorkContext().getSession().setUserName(userName);
        ((BufferManagerImpl)core.getBufferManager()).setProcessorBatchSize(2);
        Future<ResultsMessage> message = core.executeRequest(reqMsg.getExecutionId(), reqMsg);
        ResultsMessage rm = message.get(500000, TimeUnit.MILLISECONDS);
        assertNull(rm.getException());
        assertEquals(2, rm.getResults().length);
        RequestWorkItem item = core.getRequestWorkItem(DQPWorkContext.getWorkContext().getRequestID(reqMsg.getExecutionId()));

        message = core.processCursorRequest(reqMsg.getExecutionId(), 3, 2);
        rm = message.get(500000, TimeUnit.MILLISECONDS);
        assertNull(rm.getException());
        assertEquals(2, rm.getResults().length);
        //ensure that we are idle
        for (int i = 0; i < 10 && item.getThreadState() != ThreadState.IDLE; i++) {
          Thread.sleep(100);
        }
        assertEquals(ThreadState.IDLE, item.getThreadState());
        assertTrue(item.resultsBuffer.getManagedRowCount() <= 46);
        //pull the rest of the results
        for (int j = 0; j < 48; j++) {
            item = core.getRequestWorkItem(DQPWorkContext.getWorkContext().getRequestID(reqMsg.getExecutionId()));

          message = core.processCursorRequest(reqMsg.getExecutionId(), j * 2 + 5, 2);
          rm = message.get(5000, TimeUnit.MILLISECONDS);
          assertNull(rm.getException());
          assertEquals(2, rm.getResults().length);
        }
    }
View Full Code Here

TOP

Related Classes of org.teiid.client.ResultsMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.