示例#1
0
    public TupleSource registerRequest(
        CommandContext context,
        Command command,
        String modelName,
        RegisterRequestParameter parameterObject)
        throws TeiidComponentException, TeiidProcessingException {
      callCount++;

      int batchSize = 1;

      // ensure that we have the right kind of insert, and that the data for this row is valid
      if (command instanceof Insert) {
        Insert insert = (Insert) command;
        if (isBulk(insert)) {
          List batch = getBulkRows(insert, insert.getVariables());
          batchSize = batch.size();
          assertEquals(
              "Unexpected batch on call " + callCount, expectedBatchSize, batchSize); // $NON-NLS-1$

          for (int i = 0; i < batchSize; i++) {
            ensureValue2((List) batch.get(i), 2, ((callCount - 1) * batchSize) + i + 1);
          }
        } else if (insert.getTupleSource() != null) {
          TupleSource ts = insert.getTupleSource();
          List tuple = null;
          int i = 0;
          while ((tuple = ts.nextTuple()) != null) {
            ensureValue2(tuple, 2, ++i);
          }
          batchSize = i;
        } else {
          ensureValue(insert, 2, callCount);
        }
      } else if (command instanceof BatchedUpdateCommand) {
        BatchedUpdateCommand bu = (BatchedUpdateCommand) command;
        List<Command> batch = bu.getUpdateCommands();

        batchSize = batch.size();
        assertEquals(
            "Unexpected batch on call " + callCount, expectedBatchSize, batchSize); // $NON-NLS-1$
      } else {
        fail("Unexpected command type"); // $NON-NLS-1$
      }
      if (batchSize > 1) {
        return CollectionTupleSource.createUpdateCountArrayTupleSource(batchSize);
      }
      List counts = Arrays.asList(new Object[] {new Integer(batchSize)});
      FakeTupleSource fakeTupleSource = new FakeTupleSource(null, new List[] {counts});
      return fakeTupleSource;
    }