Ejemplo n.º 1
0
  @Test
  public void testForwardOnly() throws Exception {
    ElementSymbol x = new ElementSymbol("x"); // $NON-NLS-1$
    x.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    List<ElementSymbol> schema = Arrays.asList(x);
    TupleBuffer tb =
        BufferManagerFactory.getStandaloneBufferManager()
            .createTupleBuffer(schema, "x", TupleSourceType.PROCESSOR); // $NON-NLS-1$
    tb.setForwardOnly(true);
    tb.addTuple(Arrays.asList(1));
    TupleBatch batch = tb.getBatch(1);
    assertTrue(!batch.getTerminationFlag());
    assertEquals(1, batch.getBeginRow());
    try {
      tb.getBatch(1);
      fail("expected exception"); // $NON-NLS-1$
    } catch (AssertionError e) {

    }
    tb.addTuple(Arrays.asList(1));
    tb.close();
    batch = tb.getBatch(2);
    assertTrue(batch.getTerminationFlag());
    assertEquals(2, batch.getBeginRow());
  }
Ejemplo n.º 2
0
 public void truncateTo(int rowLimit) throws TeiidComponentException {
   if (rowCount <= rowLimit) {
     return;
   }
   // TODO this could be more efficient with handling the last batch
   TupleBatch last = this.getBatch(rowLimit);
   TupleBatch tb = last;
   if (this.batchBuffer != null) {
     this.batchBuffer.clear();
   }
   int begin = tb.getBeginRow();
   do {
     if (tb == null) {
       tb = this.getBatch(begin);
     }
     Long id = this.batches.remove(begin);
     if (id != null) {
       this.manager.remove(id);
     }
     if (this.lobManager != null) {
       for (List<?> tuple : tb.getTuples()) {
         this.lobManager.updateReferences(tuple, ReferenceMode.REMOVE);
       }
     }
     begin = tb.getEndRow() + 1;
     tb = null;
   } while (begin <= rowCount);
   rowCount = last.getBeginRow() - 1;
   Iterator<List<?>> iter = last.getTuples().iterator();
   while (rowCount < rowLimit) {
     addTuple(iter.next());
   }
   saveBatch(false);
 }
Ejemplo n.º 3
0
 @Test
 public void testTruncate() throws Exception {
   ElementSymbol x = new ElementSymbol("x"); // $NON-NLS-1$
   x.setType(DataTypeManager.DefaultDataClasses.INTEGER);
   List<ElementSymbol> schema = Arrays.asList(x);
   TupleBuffer tb =
       BufferManagerFactory.getStandaloneBufferManager()
           .createTupleBuffer(schema, "x", TupleSourceType.PROCESSOR); // $NON-NLS-1$
   tb.setBatchSize(2);
   for (int i = 0; i < 5; i++) {
     tb.addTuple(Arrays.asList(1));
   }
   TupleBatch batch = tb.getBatch(1);
   assertTrue(!batch.getTerminationFlag());
   assertEquals(2, batch.getEndRow());
   tb.close();
   assertEquals(5, tb.getManagedRowCount());
   tb.truncateTo(3);
   assertEquals(3, tb.getManagedRowCount());
   assertEquals(3, tb.getRowCount());
   batch = tb.getBatch(3);
   assertTrue(batch.getTerminationFlag());
   tb.truncateTo(2);
   assertEquals(2, tb.getManagedRowCount());
   assertEquals(2, tb.getRowCount());
   batch = tb.getBatch(2);
   assertTrue(batch.getTerminationFlag());
 }
Ejemplo n.º 4
0
 /**
  * Adds the given batch preserving row offsets.
  *
  * @param batch
  * @throws TeiidComponentException
  */
 public void addTupleBatch(TupleBatch batch, boolean save) throws TeiidComponentException {
   setRowCount(batch.getBeginRow() - 1);
   List<List<?>> tuples = batch.getTuples();
   if (save) {
     for (int i = 0; i < batch.getRowCount(); i++) {
       addTuple(tuples.get(i));
     }
   } else {
     // add the lob references only, since they may still be referenced later
     if (isLobs()) {
       for (int i = 0; i < batch.getRowCount(); i++) {
         lobManager.updateReferences(tuples.get(i), ReferenceMode.CREATE);
       }
     }
   }
 }
Ejemplo n.º 5
0
 public void truncateTo(int rowLimit) throws TeiidComponentException {
   if (rowCount <= rowLimit) {
     return;
   }
   // TODO this could be more efficient with handling the last batch
   if (this.batchBuffer != null) {
     for (int i = batchBuffer.size() - 1; i >= 0; i--) {
       if (this.rowCount == rowLimit) {
         break;
       }
       this.rowCount--;
       List<?> tuple = this.batchBuffer.remove(i);
       if (this.lobManager != null) {
         this.lobManager.updateReferences(tuple, ReferenceMode.REMOVE);
       }
     }
   }
   TupleBatch last = null;
   while (rowCount > rowLimit) {
     last = this.getBatch(rowCount);
     Long id = this.batches.remove(last.getBeginRow());
     if (id != null) {
       this.manager.remove(id);
     }
     if (this.lobManager != null) {
       for (List<?> tuple : last.getTuples()) {
         this.lobManager.updateReferences(tuple, ReferenceMode.REMOVE);
       }
     }
     rowCount = last.getBeginRow() - 1;
   }
   if (rowCount < rowLimit) {
     List<List<?>> tuples = last.getTuples();
     int i = 0;
     while (rowCount < rowLimit) {
       addTuple(tuples.get(i++));
     }
   }
   saveBatch(false);
 }