use of org.teiid.jdbc.BatchResults.Batch in project teiid by teiid.
the class ResultSetImpl method getCurrentBatch.
private Batch getCurrentBatch(ResultsMessage currentResultMsg) throws TeiidSQLException {
this.updatedPlanDescription = currentResultMsg.getPlanDescription();
if (usePrefetch && !asynch && prefetch == null && currentResultMsg.getLastRow() != currentResultMsg.getFinalRow()) {
// fetch before processing the results
prefetch = submitRequestBatch(currentResultMsg.getLastRow() + 1);
}
currentResultMsg.processResults();
List<?> lastTuple = null;
List<List<?>> resultsList = (List<List<?>>) currentResultMsg.getResultsList();
// similar logic to BatchCollector on the server side
// this is a catch all in case the server doesn't enforce the max
// such as currently the case with cached subset results
List<?>[] tuples = null;
int firstRow = currentResultMsg.getFirstRow();
int endRow = currentResultMsg.getLastRow();
int lastRow = currentResultMsg.getFinalRow();
if (maxRows > 0) {
if (parameters > 0) {
if (currentResultMsg.getLastRow() == currentResultMsg.getFinalRow()) {
lastTuple = resultsList.get(resultsList.size() - 1);
} else if (maxRows < currentResultMsg.getFirstRow()) {
// skip ahead as far as possible
if (lastRow != 0) {
skipTo = lastRow;
} else {
skipTo = endRow + 1;
}
return new Batch(new List<?>[0], firstRow, firstRow - 1);
}
}
if (maxRows < currentResultMsg.getLastRow()) {
firstRow = Math.min(maxRows + 1, firstRow);
resultsList = resultsList.subList(0, maxRows - firstRow + 1);
endRow = maxRows;
lastRow = endRow;
}
tuples = resultsList.toArray(new List<?>[resultsList.size() + (lastTuple != null ? 1 : 0)]);
if (lastTuple != null) {
endRow++;
lastRow = endRow;
tuples[tuples.length - 1] = lastTuple;
}
} else {
tuples = resultsList.toArray(new List<?>[resultsList.size()]);
}
Batch result = new Batch(tuples, firstRow, endRow);
result.setLastRow(lastRow);
return result;
}
use of org.teiid.jdbc.BatchResults.Batch in project teiid by teiid.
the class ResultSetImpl method requestBatch.
public Batch requestBatch(int beginRow) throws SQLException {
checkClosed();
try {
if (prefetch != null) {
// TODO: this is not efficient if the user is skipping around the results
// but the server logic at this point basically requires us
// to read what we have requested before requesting more (no queuing)
ResultsMessage result = getResults(prefetch);
prefetch = null;
Batch nextBatch = processBatch(result);
return nextBatch;
}
ResultsFuture<ResultsMessage> results = submitRequestBatch(beginRow);
if (asynch && !results.isDone()) {
synchronized (this) {
asynchResults = results;
}
throw new AsynchPositioningException();
}
ResultsMessage currentResultMsg = getResults(results);
return processBatch(currentResultMsg);
} catch (InterruptedException e) {
throw TeiidSQLException.create(e);
} catch (ExecutionException e) {
throw TeiidSQLException.create(e);
} catch (TimeoutException e) {
throw TeiidSQLException.create(e);
}
}
use of org.teiid.jdbc.BatchResults.Batch in project teiid by teiid.
the class TestBatchResults method testAbsoluteWithLastRow.
@Test
public void testAbsoluteWithLastRow() throws Exception {
Batch batch = new Batch(createBatch(1, 10), 1, 10);
batch.setLastRow(50);
MockBatchFetcher mbf = new MockBatchFetcher();
mbf.setUseLastRow(true);
BatchResults batchResults = new BatchResults(mbf, batch, BatchResults.DEFAULT_SAVED_BATCHES);
assertTrue(batchResults.absolute(41));
assertEquals(Arrays.asList(41), batchResults.getCurrentRow());
// check to ensure that we skipped all the other batches
assertEquals(Arrays.asList(41), mbf.batchCalls);
}
use of org.teiid.jdbc.BatchResults.Batch in project teiid by teiid.
the class TestBatchResults method getBatchResults.
BatchResults getBatchResults(List<?>[] batch, boolean isLast) {
Batch batch2 = new Batch(batch, 1, batch.length);
if (isLast) {
batch2.setLastRow(batch.length);
}
BatchResults results = new BatchResults(null, batch2, BatchResults.DEFAULT_SAVED_BATCHES);
if (!isLast) {
results.setBatchFetcher(new MockBatchFetcher());
}
return results;
}
Aggregations