[teiid-commits] teiid SVN: r2818 - in trunk/client/src: test/java/org/teiid/jdbc and 1 other directory.
teiid-commits at lists.jboss.org
teiid-commits at lists.jboss.org
Wed Jan 5 11:34:07 EST 2011
Author: shawkins
Date: 2011-01-05 11:34:06 -0500 (Wed, 05 Jan 2011)
New Revision: 2818
Modified:
trunk/client/src/main/java/org/teiid/jdbc/BatchResults.java
trunk/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java
trunk/client/src/test/java/org/teiid/jdbc/TestBatchResults.java
Log:
TEIID-1421 making better use cached results (or any results where the final row is known) with scrollable result sets
Modified: trunk/client/src/main/java/org/teiid/jdbc/BatchResults.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/BatchResults.java 2011-01-04 22:16:41 UTC (rev 2817)
+++ trunk/client/src/main/java/org/teiid/jdbc/BatchResults.java 2011-01-05 16:34:06 UTC (rev 2818)
@@ -43,14 +43,26 @@
private int beginRow;
private int endRow;
private boolean isLast;
+ private int lastRow = -1;
Batch(List[] batch, int beginRow, int endRow, boolean isLast){
this.batch = batch;
this.beginRow = beginRow;
this.endRow = endRow;
this.isLast = isLast;
+ if (isLast) {
+ this.lastRow = endRow;
+ }
}
+ int getLastRow() {
+ return lastRow;
+ }
+
+ void setLastRow(int lastRow) {
+ this.lastRow = lastRow;
+ }
+
int getLength() {
return batch.length;
}
@@ -219,10 +231,12 @@
private void setBatch(Batch batch) {
Assertion.assertTrue(batch.getLength() != 0 || batch.isLast());
- if (batch.isLast()) {
- this.lastRowNumber = batch.getEndRow();
+ if (batch.getLastRow() != -1) {
+ this.lastRowNumber = batch.getLastRow();
+ this.highestRowNumber = batch.getLastRow();
+ } else {
+ highestRowNumber = Math.max(batch.getEndRow(), highestRowNumber);
}
- highestRowNumber = Math.max(batch.getEndRow(), highestRowNumber);
this.batches.add(0, batch);
}
Modified: trunk/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java 2011-01-04 22:16:41 UTC (rev 2817)
+++ trunk/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java 2011-01-05 16:34:06 UTC (rev 2818)
@@ -381,7 +381,9 @@
private Batch getCurrentBatch(ResultsMessage currentResultMsg) {
this.updatedPlanDescription = currentResultMsg.getPlanDescription();
boolean isLast = currentResultMsg.getResults().length == 0 || currentResultMsg.getFinalRow() == currentResultMsg.getLastRow();
- return new Batch(currentResultMsg.getResults(), currentResultMsg.getFirstRow(), currentResultMsg.getLastRow(), isLast);
+ Batch result = new Batch(currentResultMsg.getResults(), currentResultMsg.getFirstRow(), currentResultMsg.getLastRow(), isLast);
+ result.setLastRow(currentResultMsg.getFinalRow());
+ return result;
}
protected int getFinalRowNumber() {
Modified: trunk/client/src/test/java/org/teiid/jdbc/TestBatchResults.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestBatchResults.java 2011-01-04 22:16:41 UTC (rev 2817)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestBatchResults.java 2011-01-05 16:34:06 UTC (rev 2818)
@@ -26,6 +26,7 @@
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.junit.Test;
@@ -42,6 +43,7 @@
private int totalRows = 50;
private boolean throwException;
+ private boolean useLastRow;
List<Integer> batchCalls = new ArrayList<Integer>();
public MockBatchFetcher() {
@@ -51,7 +53,11 @@
public MockBatchFetcher(int totalRows) {
this.totalRows = totalRows;
}
-
+
+ public void setUseLastRow(boolean useLastRow) {
+ this.useLastRow = useLastRow;
+ }
+
public Batch requestBatch(int beginRow) throws SQLException {
batchCalls.add(beginRow);
if (throwException) {
@@ -73,7 +79,11 @@
endRow = totalRows;
isLast = true;
}
- return new Batch(createBatch(beginRow, endRow), beginRow, endRow, isLast);
+ Batch batch = new Batch(createBatch(beginRow, endRow), beginRow, endRow, isLast);
+ if (useLastRow) {
+ batch.setLastRow(totalRows);
+ }
+ return batch;
}
public void throwException() {
@@ -306,6 +316,18 @@
assertFalse(batchResults.absolute(-100));
}
+
+ @Test public void testAbsoluteWithLastRow() throws Exception{
+ Batch batch = new Batch(createBatch(1, 10), 1, 10, false);
+ 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);
+ }
@Test public void testCurrentRowNumber() throws Exception {
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, true);
More information about the teiid-commits
mailing list