[teiid-commits] teiid SVN: r1779 - in trunk: client-jdbc/src/main/java/com/metamatrix/jdbc and 6 other directories.
teiid-commits at lists.jboss.org
teiid-commits at lists.jboss.org
Mon Jan 25 23:55:59 EST 2010
Author: shawkins
Date: 2010-01-25 23:55:59 -0500 (Mon, 25 Jan 2010)
New Revision: 1779
Added:
trunk/engine/src/test/java/com/metamatrix/common/buffer/TestTupleBuffer.java
Removed:
trunk/engine/src/test/java/com/metamatrix/common/buffer/storage/
Modified:
trunk/build/kit-runtime/deploy.properties
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/BatchResults.java
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMResultSet.java
trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestAllResultsImpl.java
trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestBatchResults.java
trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestMMResultSet.java
trunk/common-core/src/main/java/com/metamatrix/core/util/LRUCache.java
trunk/engine/src/main/java/com/metamatrix/common/buffer/TupleBatch.java
trunk/engine/src/main/java/com/metamatrix/common/buffer/TupleBuffer.java
trunk/engine/src/main/java/com/metamatrix/query/processor/BatchCollector.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
Log:
TEIID-913 refining forward only to not output batches consumed by the client and fixing output parameter indexing
Modified: trunk/build/kit-runtime/deploy.properties
===================================================================
--- trunk/build/kit-runtime/deploy.properties 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/build/kit-runtime/deploy.properties 2010-01-26 04:55:59 UTC (rev 1779)
@@ -37,11 +37,11 @@
#Plan debug messages allowed. see option debug.
process.optionDebugAllowed=true
-#Maximum allowed fetch size, set via JDBC. User requested value ignored above this value. (default 20000)
-process.maxRowsFetchSize=20000
+#Maximum allowed fetch size, set via JDBC. User requested value ignored above this value. (default 20480)
+process.maxRowsFetchSize=20480
-# The max lob chunk size transferred each time when processing blobs, clobs(10KB default)
-process.lobChunkSizeInKB=10
+# The max lob chunk size transferred each time when processing blobs, clobs(100KB default)
+process.lobChunkSizeInKB=100
#
# BufferManager Settings
@@ -56,8 +56,8 @@
#Defines whether to use disk buffering or not. (default true)
dqp.buffer.useDisk=true
-#The numeric memory size in MB, to be used before disk buffering kicks in (default 64)
-dqp.buffer.memory=64
+#The number of batches to actively hold in the BufferManager
+org.teiid.buffer.maxReserveBatches=64
#
# Cache Settings
@@ -66,7 +66,7 @@
#The maximum number of query plans that are cached. Note: this is a memory based cache. (default 250)
PreparedPlanCache.maxCount=250
-#Maximum number of cached lookup tables. Note: this is a memory based cache and should be set to a value of at least 10 to accomidate system usage. (default 200)
+#Maximum number of cached lookup tables. Note: this is a memory based cache. (default 200)
CodeTables.maxCount=200
#Maximum number of records in a single lookup table (default 10000)
@@ -97,8 +97,8 @@
#Maximum number of sessions allowed by the system (default 5000)
session.maxSessions=5000
-#Max allowed time before the session is terminated by the system (default unlimited, default is 86400000 - 24hrs)
-#session.expirationTimeInMilli=86400000
+#Max allowed time before the session is terminated by the system, 0 indicates unlimited (default 0)
+#session.expirationTimeInMilli=0
#
# Membership Service Settings (handles the authentication of the user)
@@ -144,7 +144,7 @@
ssl.enabled=false
#ssl.protocol=SSLv3
-#SSL Authentication Mode, may be one of 1-way, 2-way, or annonymous (default 1-way)
+#SSL Authentication Mode, may be one of 1-way, 2-way, or anonymous (default 1-way)
#ssl.authenticationMode=1-way
#ssl.keymanagementalgorithm=
#ssl.keystore.filename=ssl.keystore
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/BatchResults.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/BatchResults.java 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/BatchResults.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -73,6 +73,7 @@
private ArrayList<Batch> batches = new ArrayList<Batch>();
private int currentRowNumber;
+ private List<?> currentRow;
private int lastRowNumber = -1;
private int highestRowNumber;
private BatchFetcher batchFetcher;
@@ -93,25 +94,30 @@
* Moving backward through the results it's expected that the batches will match the fetch size.
*/
public List getCurrentRow() throws SQLException {
- if (currentRowNumber == 0 || (lastRowNumber != -1 && currentRowNumber > lastRowNumber)) {
+ if (currentRow != null) {
+ return currentRow;
+ }
+ if (this.currentRowNumber == 0 || (lastRowNumber != -1 && this.currentRowNumber > lastRowNumber)) {
return null;
}
for (int i = 0; i < batches.size(); i++) {
Batch batch = batches.get(i);
- if (currentRowNumber < batch.getBeginRow()) {
+ if (this.currentRowNumber < batch.getBeginRow()) {
continue;
}
- if (currentRowNumber > batch.getEndRow()) {
+ if (this.currentRowNumber > batch.getEndRow()) {
continue;
}
if (i != 0) {
batches.add(0, batches.remove(i));
}
- return batch.getRow(currentRowNumber);
+ currentRow = batch.getRow(this.currentRowNumber);
+ return currentRow;
}
- requestBatchAndWait(currentRowNumber);
+ requestBatchAndWait(this.currentRowNumber);
Batch batch = batches.get(0);
- return batch.getRow(currentRowNumber);
+ currentRow = batch.getRow(this.currentRowNumber);
+ return currentRow;
}
private void requestNextBatch() throws SQLException {
@@ -120,29 +126,30 @@
public boolean next() throws SQLException{
if (hasNext()) {
- currentRowNumber++;
+ setCurrentRowNumber(this.currentRowNumber + 1);
+ getCurrentRow();
return true;
}
- if (currentRowNumber == highestRowNumber) {
- currentRowNumber++;
+ if (this.currentRowNumber == highestRowNumber) {
+ setCurrentRowNumber(this.currentRowNumber + 1);
}
return false;
}
public boolean hasPrevious() {
- return (currentRowNumber != 0 && currentRowNumber != 1);
+ return (this.currentRowNumber != 0 && this.currentRowNumber != 1);
}
public boolean previous() {
if (hasPrevious()) {
- currentRowNumber--;
+ setCurrentRowNumber(this.currentRowNumber - 1);
return true;
}
if (this.currentRowNumber == 1) {
- currentRowNumber--;
+ setCurrentRowNumber(this.currentRowNumber - 1);
}
return false;
@@ -158,7 +165,7 @@
public boolean absolute(int row, int offset) throws SQLException {
if(row == 0) {
- currentRowNumber = 0;
+ setCurrentRowNumber(0);
return false;
}
@@ -169,11 +176,11 @@
}
if (row + offset <= highestRowNumber) {
- currentRowNumber = row;
+ setCurrentRowNumber(row);
return true;
}
- currentRowNumber = lastRowNumber + 1 - offset;
+ setCurrentRowNumber(lastRowNumber + 1 - offset);
return false;
}
@@ -186,11 +193,11 @@
int positiveRow = lastRowNumber + row + 1;
if (positiveRow <= 0) {
- currentRowNumber = 0;
+ setCurrentRowNumber(0);
return false;
}
- currentRowNumber = positiveRow;
+ setCurrentRowNumber(positiveRow);
return true;
}
@@ -219,11 +226,11 @@
}
public boolean hasNext(int next) throws SQLException {
- while (currentRowNumber + next > highestRowNumber && lastRowNumber == -1) {
+ while (this.currentRowNumber + next > highestRowNumber && lastRowNumber == -1) {
requestNextBatch();
}
- return (currentRowNumber + next <= highestRowNumber);
+ return (this.currentRowNumber + next <= highestRowNumber);
}
public int getFinalRowNumber() {
@@ -233,5 +240,12 @@
public int getHighestRowNumber() {
return highestRowNumber;
}
+
+ private void setCurrentRowNumber(int currentRowNumber) {
+ if (currentRowNumber != this.currentRowNumber) {
+ this.currentRow = null;
+ }
+ this.currentRowNumber = currentRowNumber;
+ }
}
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMResultSet.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMResultSet.java 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMResultSet.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -400,7 +400,7 @@
}
protected int getOffset() {
- return parameters;
+ return parameters > 0 ? 1 : 0;
}
protected int getAbsoluteRowNumber() {
Modified: trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestAllResultsImpl.java
===================================================================
--- trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestAllResultsImpl.java 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestAllResultsImpl.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -22,6 +22,7 @@
package com.metamatrix.jdbc;
+import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.sql.ResultSet;
@@ -38,10 +39,10 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import org.junit.Before;
+import org.junit.Test;
import org.mockito.Matchers;
-import junit.framework.TestCase;
-
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.common.types.MMJDBCSQLTypeInfo;
import com.metamatrix.common.util.TimestampWithTimezone;
@@ -51,7 +52,7 @@
import com.metamatrix.dqp.message.ResultsMessage;
import com.metamatrix.query.unittest.TimestampUtil;
-public class TestAllResultsImpl extends TestCase {
+public class TestAllResultsImpl {
private static final long REQUEST_ID = 0;
private static final int TYPE_FORWARD_ONLY = ResultSet.TYPE_FORWARD_ONLY;
@@ -59,17 +60,12 @@
private MMStatement statement;
- public TestAllResultsImpl(String name) {
- super(name);
+ @Before public void setUp() throws Exception {
+ statement = TestMMResultSet.createMockStatement(TYPE_SCROLL_SENSITIVE);
}
-
- @Override
- protected void setUp() throws Exception {
- statement = TestMMResultSet.createMockStatement();
- }
/** test hasNext(), actual result set should return FALSE. */
- public void testHasNext1() throws Exception {
+ @Test public void testHasNext1() throws Exception {
MMResultSet rs = new MMResultSet(exampleResultsMsg1(),
statement);
while (rs.next()) {
@@ -84,7 +80,7 @@
}
/** test hasNext(), actual result set should return TRUE. */
- public void testHasNext2() throws Exception {
+ @Test public void testHasNext2() throws Exception {
List[] results = exampleResults1(5);
MMResultSet rs = new MMResultSet(exampleResultsMsg1(),
statement);
@@ -104,7 +100,7 @@
* test next(), whether the result set's cursor is positioned on next row or
* not
*/
- public void testNext1() throws Exception {
+ @Test public void testNext1() throws Exception {
MMResultSet rs = new MMResultSet(exampleResultsMsg1(),
statement);
@@ -117,7 +113,7 @@
}
/** test next(), walk through all rows of a result set and compare each row. */
- public void testNext2() throws Exception {
+ @Test public void testNext2() throws Exception {
List[] results = exampleResults1(5);
MMResultSet rs = new MMResultSet(exampleResultsMsg1(),
statement);
@@ -135,7 +131,7 @@
}
/** test next(), get result set and close without walking through */
- public void testNext3() throws Exception {
+ @Test public void testNext3() throws Exception {
MMResultSet rs = new MMResultSet(exampleResultsMsg1(),
statement);
assertEquals(new Integer(0), new Integer(rs.getRow()));
@@ -144,7 +140,7 @@
}
/** test next(), walk through partial rows of a result set */
- public void testNext4() throws Exception {
+ @Test public void testNext4() throws Exception {
List[] results = exampleResults1(5);
MMResultSet rs = new MMResultSet(exampleResultsMsg1(),
statement);
@@ -160,7 +156,7 @@
}
/** test next(), when hasNext() == false */
- public void testNext5() throws Exception {
+ @Test public void testNext5() throws Exception {
MMResultSet rs = new MMResultSet(exampleResultsMsg1(),
statement);
while (rs.next()) {
@@ -175,7 +171,7 @@
}
/** test getObject() at columnIndex = 2 of 5th row */
- public void testGetObject1() throws Exception {
+ @Test public void testGetObject1() throws Exception {
List[] results = exampleResults2();
MMResultSet rs = new MMResultSet(exampleResultsMsg2a(),
statement);
@@ -199,7 +195,7 @@
}
/** Should fail, test getObject() at wrong columnIndex */
- public void testGetObject2() throws Exception {
+ @Test public void testGetObject2() throws Exception {
MMResultSet rs = new MMResultSet(exampleResultsMsg2a(),
statement);
@@ -218,7 +214,7 @@
rs.close();
}
- public void testGetRow() throws Exception {
+ @Test public void testGetRow() throws Exception {
MMResultSet rs = new MMResultSet(exampleResultsMsg2(),
statement);
@@ -233,7 +229,7 @@
}
- public void testPrevious() throws Exception {
+ @Test public void testPrevious() throws Exception {
List[] results = exampleResults1(5);
MMResultSet rs = new MMResultSet(exampleResultsMsg1(),
statement);
@@ -254,7 +250,7 @@
rs.close();
}
- public void testGetCurrentRecord() throws Exception {
+ @Test public void testGetCurrentRecord() throws Exception {
List[] results = exampleResults2();
MMResultSet rs = new MMResultSet(exampleResultsMsg2(),
statement);
@@ -265,7 +261,7 @@
rs.close();
}
- public void testGetMetaData() throws Exception {
+ @Test public void testGetMetaData() throws Exception {
MMResultSet rs = new MMResultSet(exampleResultsMsg2a(),
statement);
ResultSetMetaData rmetadata = rs.getMetaData();
@@ -280,20 +276,20 @@
rs.close();
}
- public void testResultsWarnings() throws Exception {
+ @Test public void testResultsWarnings() throws Exception {
MMResultSet rs = new MMResultSet(exampleResultsMsg2(),
statement);
rs.close();
}
- public void testClose() throws Exception {
+ @Test public void testClose() throws Exception {
MMResultSet rs = new MMResultSet(exampleResultsMsg2(),
statement);
rs.close();
verify(statement, times(0)).close();
}
- public void testGetFetchSize() throws Exception {
+ @Test public void testGetFetchSize() throws Exception {
MMStatement s = mock(MMStatement.class);
stub(s.getFetchSize()).toReturn(500);
MMResultSet rs = new MMResultSet(exampleResultsMsg2(), s);
@@ -304,27 +300,17 @@
// //////////////////////Functions refer to ResultSet's TYPE_FORWARD_ONLY///
// /////////////////
- public void testIsAfterLast1() throws Exception {
+ @Test(expected=SQLException.class) public void testIsAfterLast1() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_FORWARD_ONLY);
-
- // the last row
rs.last();
- boolean actual = rs.isAfterLast();
- assertEquals(false, actual);
- rs.close();
}
- public void testAfterLast1() throws Exception {
+ @Test(expected=SQLException.class) public void testAfterLast1() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_FORWARD_ONLY);
-
- // move cursor right past the last row
rs.afterLast();
- assertEquals(0, rs.getRow());
- rs.close();
-
}
- public void testIsBeforeFirst1() throws Exception {
+ @Test public void testIsBeforeFirst1() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_FORWARD_ONLY);
// right before the first row
@@ -333,7 +319,7 @@
rs.close();
}
- public void testIsBeforeFirst2() throws Exception {
+ @Test public void testIsBeforeFirst2() throws Exception {
MMResultSet rs = helpGetNoResults(TYPE_FORWARD_ONLY);
// right before the first row
@@ -342,7 +328,7 @@
rs.close();
}
- public void testBeforeFirst1() throws Exception {
+ @Test(expected=SQLException.class) public void testBeforeFirst1() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_FORWARD_ONLY);
// move cursor to the first row
@@ -350,12 +336,9 @@
// move back to before first row
rs.beforeFirst();
-
- assertEquals(0, rs.getRow());
- rs.close();
}
- public void testIsFirst1() throws Exception {
+ @Test public void testIsFirst1() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_FORWARD_ONLY);
// move cursor to the first row
@@ -365,7 +348,7 @@
rs.close();
}
- public void testIsFirst2() throws Exception {
+ @Test public void testIsFirst2() throws Exception {
MMResultSet rs = helpGetNoResults(TYPE_FORWARD_ONLY);
// move cursor to the first row
@@ -375,27 +358,23 @@
rs.close();
}
- public void testFirst1() throws Exception {
+ @Test(expected=SQLException.class) public void testFirst1() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_FORWARD_ONLY);
// move cursor to the first row
rs.next();
- boolean actual = rs.first();
- assertEquals(true, actual);
- rs.close();
+ rs.first();
}
- public void testFirst2() throws Exception {
+ @Test(expected=SQLException.class) public void testFirst2() throws Exception {
MMResultSet rs = helpGetNoResults(TYPE_FORWARD_ONLY);
// move cursor to the first row
rs.next();
- boolean actual = rs.first();
- assertEquals(false, actual);
- rs.close();
+ rs.first();
}
- public void testFindColumn() throws Exception {
+ @Test public void testFindColumn() throws Exception {
MMResultSet rs = new MMResultSet(exampleResultsMsg2a(),
statement);
@@ -403,45 +382,29 @@
rs.close();
}
- public void testIsLast1() throws Exception {
+ @Test public void testIsLast1() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_FORWARD_ONLY);
// move cursor to the last row
- rs.last();
boolean actual = rs.isLast();
- assertEquals(true, actual);
- rs.close();
+ assertEquals(false, actual);
}
- public void testIsLast2() throws Exception {
+ @Test public void testIsLast2() throws Exception {
MMResultSet rs = helpGetNoResults(TYPE_FORWARD_ONLY);
// move cursor to the last row
- rs.last();
boolean actual = rs.isLast();
assertEquals(false, actual);
- rs.close();
}
- public void testLast1() throws Exception {
+ @Test(expected=SQLException.class) public void testLast1() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_FORWARD_ONLY);
- // check whether the movement of cursor is successful
- boolean actual = rs.last();
- assertEquals(true, actual);
- rs.close();
+ rs.last();
}
- public void testLast2() throws Exception {
- MMResultSet rs = helpGetNoResults(TYPE_FORWARD_ONLY);
-
- // check whether the movement of cursor is successful
- boolean actual = rs.last();
- assertEquals(false, actual);
- rs.close();
- }
-
- public void testRelative1() throws Exception {
+ @Test public void testRelative1() throws Exception {
MMResultSet rs = new MMResultSet(exampleResultsMsg2(),
statement);
@@ -458,28 +421,16 @@
rs.close();
}
- public void testAbsolute1() throws Exception {
+ @Test(expected=SQLException.class) public void testAbsolute1() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_FORWARD_ONLY);
- // check whether the movement of cursor is successful
- boolean actual = rs.absolute(1);
- assertEquals(true, actual);
- rs.close();
+ rs.absolute(1);
}
- public void testAbsolute2() throws Exception {
- MMResultSet rs = helpGetNoResults(TYPE_FORWARD_ONLY);
-
- // check whether the movement of cursor is successful
- boolean actual = rs.absolute(1);
- assertEquals(false, actual);
- rs.close();
- }
-
// //////////Functions refer to other types other than ResultSet's
// TYPE_FORWARD_ONLY//////
- public void testAfterLast1a() throws Exception {
+ @Test public void testAfterLast1a() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// move cursor right past the last row
@@ -490,7 +441,7 @@
rs.close();
}
- public void testIsAfterLast1a() throws Exception {
+ @Test public void testIsAfterLast1a() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// the last row
@@ -505,7 +456,7 @@
rs.close();
}
- public void testIsBeforeFirst1a() throws Exception {
+ @Test public void testIsBeforeFirst1a() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// right before the first row
@@ -514,7 +465,7 @@
rs.close();
}
- public void testBeforeFirst1a() throws Exception {
+ @Test public void testBeforeFirst1a() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// move cursor to the first row
@@ -528,7 +479,7 @@
rs.close();
}
- public void testIsFirst1a() throws Exception {
+ @Test public void testIsFirst1a() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// move cursor to the first row
@@ -541,7 +492,7 @@
rs.close();
}
- public void testFirst1a() throws Exception {
+ @Test public void testFirst1a() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// move cursor to the first row
@@ -563,7 +514,7 @@
rs.close();
}
- public void testIsLast1a() throws Exception {
+ @Test public void testIsLast1a() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// check whether the movement of cursor is successful
@@ -576,7 +527,7 @@
rs.close();
}
- public void testLast1a() throws Exception {
+ @Test public void testLast1a() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// check whether the movement of cursor is successful
@@ -589,7 +540,7 @@
}
/** normal relative move, only including moving from valid row to valid one */
- public void testRelative1a() throws Exception {
+ @Test public void testRelative1a() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// move to 1st row
@@ -607,7 +558,7 @@
}
/** normal relative move, including moving from valid row to invalid one */
- public void testRelative1b() throws Exception {
+ @Test public void testRelative1b() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// move to 1st row
@@ -635,7 +586,7 @@
}
/** check only moving from an invalid row */
- public void testRelative1c() throws Exception {
+ @Test public void testRelative1c() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// test if move before first will work or not
@@ -685,7 +636,7 @@
}
/** test only valid row in result set */
- public void testAbsolute1a() throws Exception {
+ @Test public void testAbsolute1a() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// start from beginning
@@ -710,7 +661,7 @@
}
/** test only valid row in result set */
- public void testAbsolute2a() throws Exception {
+ @Test public void testAbsolute2a() throws Exception {
MMResultSet rs = helpGetNoResults(TYPE_SCROLL_SENSITIVE);
// start from beginning
@@ -729,7 +680,7 @@
* Case 4293 - timestamps for begin and end processing should both be set
* server-side (from the same system clock)
*/
- public void testProcessingTime() throws Exception {
+ @Test public void testProcessingTime() throws Exception {
RequestMessage request = new RequestMessage();
request.setProcessingTimestamp(new Date(12345678L));
ResultsMessage resultsMsg = new ResultsMessage(request);
@@ -757,7 +708,7 @@
/**
* 3 batches
*/
- public void testMoreResults() throws Exception {
+ @Test public void testMoreResults() throws Exception {
int fetchSize = 5;
int batchLength = 4;
int totalLength = 10;
@@ -795,8 +746,7 @@
}
ResultsMessage msg = exampleResultsMsg4(1, batchLength, fetchSize, batchLength == totalLength);
- MMResultSet rs = new MMResultSet(msg, statement);
- return rs;
+ return new MMResultSet(msg, statement);
}
// /////////////////////Helper Method///////////////////
@@ -844,12 +794,14 @@
private MMResultSet helpGetResultSetImpl(int type)
throws SQLException {
ResultsMessage rsMsg = exampleResultsMsg2();
+ statement = TestMMResultSet.createMockStatement(type);
MMResultSet rs = new MMResultSet(rsMsg, statement);
return rs;
}
private MMResultSet helpGetNoResults(int type) throws SQLException {
ResultsMessage rsMsg = exampleResultsMsg3();
+ statement = TestMMResultSet.createMockStatement(type);
MMResultSet rs = new MMResultSet(rsMsg, statement);
return rs;
}
@@ -913,7 +865,7 @@
return resultsMsg;
}
- public void testNotCallingNext() throws SQLException {
+ @Test public void testNotCallingNext() throws SQLException {
MMResultSet cs = new MMResultSet(exampleResultsMsg2a(),
statement);
@@ -925,7 +877,7 @@
}
}
- public void testDateType() throws SQLException {
+ @Test public void testDateType() throws SQLException {
RequestMessage request = new RequestMessage();
request.setProcessingTimestamp(new Date(1L));
request.setExecutionId(REQUEST_ID);
@@ -947,8 +899,8 @@
assertEquals(new Timestamp(0), rs.getTimestamp(1, Calendar.getInstance(TimeZone.getTimeZone("GMT-05:00")))); //$NON-NLS-1$
}
- public void testWasNull() throws SQLException{
- ResultsMessage message = exampleMessage(new List[] { Arrays.asList((String)null), Arrays.asList("1") }, new String[] { "string" }, //$NON-NLS-1$ //$NON-NLS-1$
+ @Test public void testWasNull() throws SQLException{
+ ResultsMessage message = exampleMessage(new List[] { Arrays.asList((String)null), Arrays.asList("1") }, new String[] { "string" }, //$NON-NLS-1$
new String[] { MMJDBCSQLTypeInfo.STRING });
MMResultSet rs = new MMResultSet(message, statement);
assertTrue(rs.next());
@@ -960,9 +912,9 @@
assertTrue(rs.wasNull());
assertEquals(0l, rs.getLong(1));
assertTrue(rs.wasNull());
- assertEquals(0f, rs.getFloat(1));
+ assertEquals(0f, rs.getFloat(1), 0);
assertTrue(rs.wasNull());
- assertEquals(0d, rs.getDouble(1));
+ assertEquals(0d, rs.getDouble(1), 0);
assertTrue(rs.wasNull());
assertNull(rs.getString(1));
assertTrue(rs.wasNull());
@@ -972,7 +924,7 @@
assertFalse(rs.next());
}
- public void testGetters() throws SQLException{
+ @Test public void testGetters() throws SQLException{
TimeZone.setDefault(TimeZone.getTimeZone("GMT-05:00")); //$NON-NLS-1$
ResultsMessage message = exampleMessage(new List[] { Arrays.asList(1, TimestampUtil.createTime(0, 0, 0), TimestampUtil.createDate(1, 1, 1), TimestampUtil.createTimestamp(1, 1, 1, 1, 1, 1, 1), "<root/>") }, //$NON-NLS-1$
new String[] { "int", "time", "date", "timestamp", "sqlxml" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
@@ -984,8 +936,8 @@
assertEquals(1, rs.getShort(1));
assertEquals(1, rs.getInt(1));
assertEquals(1l, rs.getLong(1));
- assertEquals(1f, rs.getFloat(1));
- assertEquals(1d, rs.getDouble(1));
+ assertEquals(1f, rs.getFloat(1), 0);
+ assertEquals(1d, rs.getDouble(1), 0);
assertEquals("1", rs.getString(1)); //$NON-NLS-1$
assertEquals(Integer.valueOf(1), rs.getObject(1));
//the mock statement is in GMT-6 the server results are from GMT-5, so we expect them to display the same
Modified: trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestBatchResults.java
===================================================================
--- trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestBatchResults.java 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestBatchResults.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -22,20 +22,20 @@
package com.metamatrix.jdbc;
+import static org.junit.Assert.*;
+
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
+import org.junit.Test;
+
import com.metamatrix.jdbc.BatchResults.Batch;
-import junit.framework.TestCase;
-
-
-
/**
* @since 4.3
*/
-public class TestBatchResults extends TestCase {
+public class TestBatchResults {
static class MockBatchFetcher implements BatchFetcher {
@@ -81,10 +81,6 @@
}
- public TestBatchResults (String name) {
- super(name);
- }
-
private static List[] createBatch(int begin, int end) {
List[] results = new List[end - begin + 1];
for(int i=0; i<(end - begin + 1); i++) {
@@ -98,9 +94,8 @@
List[] results = new List[0];
return results;
}
-
- public void testGetCurrentRow1() throws Exception{
+ @Test public void testGetCurrentRow1() throws Exception{
//empty batch
BatchResults batchResults = new BatchResults(createEmptyBatch(), 0, 0, true);
assertNull(batchResults.getCurrentRow());
@@ -108,7 +103,7 @@
assertNull(batchResults.getCurrentRow());
}
- public void testGetCurrentRow2() throws Exception{
+ @Test public void testGetCurrentRow2() throws Exception{
BatchResults batchResults = new BatchResults(createBatch(1, 10), 1, 10, true);
assertNull(batchResults.getCurrentRow());
batchResults.next();
@@ -117,30 +112,30 @@
assertEquals(batchResults.getCurrentRow(), expectedResult);
}
- public void testHasNext1() throws Exception{
+ @Test public void testHasNext1() throws Exception{
//empty batch
BatchResults batchResults = new BatchResults(createEmptyBatch(), 0, 0, true);
assertFalse(batchResults.hasNext());
}
- public void testHasNext2() throws Exception{
+ @Test public void testHasNext2() throws Exception{
//one row batch
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, true);
assertTrue(batchResults.hasNext());
}
- public void testHasNext3() throws Exception{
+ @Test public void testHasNext3() throws Exception{
BatchResults batchResults = new BatchResults(createBatch(1, 10), 1, 10, true);
assertTrue(batchResults.hasNext());
}
- public void testNext1() throws Exception{
+ @Test public void testNext1() throws Exception{
//empty batch
BatchResults batchResults = new BatchResults(createEmptyBatch(), 0, 0, true);
assertFalse(batchResults.next());
}
- public void testNext2() throws Exception{
+ @Test public void testNext2() throws Exception{
//one row batch
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, true);
assertTrue(batchResults.next());
@@ -150,7 +145,7 @@
assertFalse(batchResults.next());
}
- public void testNext3() throws Exception{
+ @Test public void testNext3() throws Exception{
//one row batch, multiple batches
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, false);
batchResults.setBatchFetcher(new MockBatchFetcher());
@@ -161,7 +156,7 @@
assertEquals(batchResults.getCurrentRow(), expectedResult);
}
- public void testNext4() throws Exception{
+ @Test public void testNext4() throws Exception{
BatchResults batchResults = new BatchResults(createBatch(1, 10), 1, 10, false);
batchResults.setBatchFetcher(new MockBatchFetcher());
int i;
@@ -179,13 +174,13 @@
assertFalse(batchResults.next());
}
- public void testHasPrevious1() throws Exception{
+ @Test public void testHasPrevious1() throws Exception{
//empty batch
BatchResults batchResults = new BatchResults(createEmptyBatch(), 0, 0, true);
assertFalse(batchResults.hasPrevious());
}
- public void testHasPrevious2() throws Exception{
+ @Test public void testHasPrevious2() throws Exception{
//one row batch
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, true);
assertFalse(batchResults.hasPrevious());
@@ -195,13 +190,13 @@
assertTrue(batchResults.hasPrevious());
}
- public void testPrevious1() throws Exception{
+ @Test public void testPrevious1() throws Exception{
//empty batch
BatchResults batchResults = new BatchResults(createEmptyBatch(), 0, 0, true);
assertFalse(batchResults.previous());
}
- public void testPrevious2() throws Exception{
+ @Test public void testPrevious2() throws Exception{
//one row batch
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, true);
assertTrue(batchResults.next());
@@ -214,7 +209,7 @@
assertEquals(batchResults.getCurrentRow(), expectedResult);
}
- public void testPrevious3() throws Exception{
+ @Test public void testPrevious3() throws Exception{
//one row batch, multiple batches
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, false);
batchResults.setBatchFetcher(new MockBatchFetcher());
@@ -235,7 +230,7 @@
assertEquals(batchResults.getCurrentRow(), expectedResult);
}
- public void testPrevious4() throws Exception{
+ @Test public void testPrevious4() throws Exception{
BatchResults batchResults = new BatchResults(createBatch(1, 10), 1, 10, false);
batchResults.setBatchFetcher(new MockBatchFetcher());
int i;
@@ -250,14 +245,14 @@
}
}
- public void testAbsolute1() throws Exception{
+ @Test public void testAbsolute1() throws Exception{
//empty batch
BatchResults batchResults = new BatchResults(createEmptyBatch(), 0, 0, true);
assertFalse(batchResults.absolute(0));
assertFalse(batchResults.absolute(1));
}
- public void testAbsolute2() throws Exception{
+ @Test public void testAbsolute2() throws Exception{
//one row batch
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, true);
batchResults.setBatchFetcher(new MockBatchFetcher());
@@ -269,7 +264,7 @@
assertEquals(batchResults.getCurrentRow(), expectedResult);
}
- public void testAbsolute3() throws Exception{
+ @Test public void testAbsolute3() throws Exception{
BatchResults batchResults = new BatchResults(createBatch(1, 10), 1, 10, false);
batchResults.setBatchFetcher(new MockBatchFetcher(200));
assertFalse(batchResults.absolute(0));
@@ -288,7 +283,7 @@
}
//move backwards with absolute
- public void testAbsolute4() throws Exception{
+ @Test public void testAbsolute4() throws Exception{
//one row batch
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, false);
batchResults.setBatchFetcher(new MockBatchFetcher());
@@ -299,7 +294,7 @@
assertEquals(batchResults.getCurrentRow(), expectedResult);
}
- public void testAbsolute5() throws Exception{
+ @Test public void testAbsolute5() throws Exception{
//one row batch
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, false);
batchResults.setBatchFetcher(new MockBatchFetcher());
@@ -311,7 +306,7 @@
assertFalse(batchResults.absolute(-100));
}
- public void testCurrentRowNumber() throws Exception {
+ @Test public void testCurrentRowNumber() throws Exception {
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, true);
assertEquals(0, batchResults.getCurrentRowNumber());
batchResults.next();
@@ -322,7 +317,7 @@
assertEquals(2, batchResults.getCurrentRowNumber());
}
- public void testSetException() throws Exception {
+ @Test public void testSetException() throws Exception {
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, false);
MockBatchFetcher batchFetcher = new MockBatchFetcher();
batchResults.setBatchFetcher(batchFetcher);
@@ -335,7 +330,7 @@
}
}
- public void testBatching() throws Exception {
+ @Test public void testBatching() throws Exception {
BatchResults batchResults = new BatchResults(createBatch(1, 10), 1, 10, false);
MockBatchFetcher batchFetcher = new MockBatchFetcher(60);
batchResults.setBatchFetcher(batchFetcher);
Modified: trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestMMResultSet.java
===================================================================
--- trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestMMResultSet.java 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestMMResultSet.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -22,6 +22,7 @@
package com.metamatrix.jdbc;
+import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.sql.ResultSet;
@@ -29,32 +30,30 @@
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.util.TimeZone;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
-import junit.framework.TestCase;
+import org.junit.Test;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.dqp.client.ClientSideDQP;
+import com.metamatrix.dqp.message.ResultsMessage;
-public class TestMMResultSet extends TestCase {
+public class TestMMResultSet {
- public TestMMResultSet(String name) {
- super(name);
- }
-
/** test next() without walking through */
- public void testNext1() throws SQLException {
+ @Test public void testNext1() throws SQLException {
ResultSet cs = helpExecuteQuery();
assertEquals(" Actual doesn't match with expected. ", new Integer(0), new Integer(cs.getRow())); //$NON-NLS-1$
cs.close();
}
/** test next() with walking through all the rows and compare records */
- public void testNext2() throws SQLException {
+ @Test public void testNext2() throws SQLException {
List[] expected = TestAllResultsImpl.exampleResults1(1000);
MMResultSet cs = helpExecuteQuery();
@@ -75,37 +74,37 @@
public static final int PROC_BATCH_SIZE = 100;
/** Test stability when next() is called beyond the rowcount. */
- public void testNextBeyondEnd_fetchEqualsCount() throws Exception {
+ @Test public void testNextBeyondEnd_fetchEqualsCount() throws Exception {
helpTestNextBeyondResultSet(1000, 1000);
}
/** Test stability when next() is called beyond the rowcount. */
- public void testNextBeyondEnd_fetchLessThanCount() throws Exception {
+ @Test public void testNextBeyondEnd_fetchLessThanCount() throws Exception {
helpTestNextBeyondResultSet(100, 1000);
}
/** Test stability when next() is called beyond the rowcount with one more row. */
- public void testNextBeyondEnd_fetchLessThanCount1() throws Exception {
+ @Test public void testNextBeyondEnd_fetchLessThanCount1() throws Exception {
helpTestNextBeyondResultSet(100, 101);
}
/** Test stability when next() is called beyond the rowcount. */
- public void testNextBeyondEnd_fetchLessThanCountNonMultiple() throws Exception {
+ @Test public void testNextBeyondEnd_fetchLessThanCountNonMultiple() throws Exception {
helpTestNextBeyondResultSet(120, 1000);
}
/** Test stability when next() is called beyond the rowcount. */
- public void testNextBeyondEnd_fetchGreaterThanCount() throws Exception {
+ @Test public void testNextBeyondEnd_fetchGreaterThanCount() throws Exception {
helpTestNextBeyondResultSet(300, PROC_BATCH_SIZE);
}
/** Test stability when next() is called beyond the rowcount. */
- public void testNextBeyondEnd_fetchGreaterThanCountNonMultiple() throws Exception {
+ @Test public void testNextBeyondEnd_fetchGreaterThanCountNonMultiple() throws Exception {
helpTestNextBeyondResultSet(310, PROC_BATCH_SIZE-50);
}
/** Test stability when next() is called beyond the rowcount. */
- public void testNextBeyondEnd_fetchGreaterThanCountNonMultiple2() throws Exception {
+ @Test public void testNextBeyondEnd_fetchGreaterThanCountNonMultiple2() throws Exception {
helpTestNextBeyondResultSet(300, PROC_BATCH_SIZE+10);
}
@@ -113,12 +112,12 @@
* fetchSize < rows < proc batch size.
* Test for defect 11356
*/
- public void testNextBeyondEnd_fetchLessThanCount_ResultsBetweenFetchAndProcBatch() throws Exception {
+ @Test public void testNextBeyondEnd_fetchLessThanCount_ResultsBetweenFetchAndProcBatch() throws Exception {
helpTestNextBeyondResultSet(30, PROC_BATCH_SIZE-25);
}
public void helpTestNextBeyondResultSet(int fetchSize, int numRows) throws Exception {
- ResultSet cs = helpExecuteQuery(fetchSize, numRows);
+ ResultSet cs = helpExecuteQuery(fetchSize, numRows, ResultSet.TYPE_SCROLL_INSENSITIVE);
try {
Object lastRowValue = null;
for (int rowNum = 1; rowNum <= numRows; rowNum++) {
@@ -144,7 +143,7 @@
}
/** test both next() and previous() -- when result set scroll in bidirection */
- public void testBidirection() throws SQLException {
+ @Test public void testBidirection() throws SQLException {
MMResultSet cs = helpExecuteQuery();
assertNotNull(cs);
cs.absolute(290);
@@ -161,14 +160,14 @@
}
/** test hasNext() without walking through any row */
- public void testHasNext1() throws SQLException {
+ @Test public void testHasNext1() throws SQLException {
MMResultSet cs = helpExecuteQuery();
assertEquals(" hasNext() doesn't match expected value. ", true, cs.hasNext()); //$NON-NLS-1$
cs.close();
}
/** test hasNext() with blocking for the Next batch -- triggering point */
- public void testHasNext2() throws SQLException {
+ @Test public void testHasNext2() throws SQLException {
MMResultSet cs = helpExecuteQuery();
cs.absolute(100);
assertEquals(" hasNext() doesn't match expected value. ", true, cs.hasNext()); //$NON-NLS-1$
@@ -176,7 +175,7 @@
}
/** test hasNext() with nextBatch!=null -- short response */
- public void testHasNext3() throws SQLException {
+ @Test public void testHasNext3() throws SQLException {
MMResultSet cs = helpExecuteQuery();
int i = 0;
while (cs.next()) {
@@ -190,7 +189,7 @@
}
/** at the end of all batches */
- public void testHasNext4() throws SQLException {
+ @Test public void testHasNext4() throws SQLException {
MMResultSet cs = helpExecuteQuery();
cs.absolute(1000);
assertTrue(!cs.hasNext());
@@ -198,7 +197,7 @@
}
/** walk all way through from the end back to first row */
- public void testPrevious1() throws SQLException {
+ @Test public void testPrevious1() throws SQLException {
MMResultSet cs = helpExecuteQuery();
List[] expected = TestAllResultsImpl.exampleResults1(1000);
while(cs.next()) {
@@ -218,7 +217,7 @@
}
/** test the previous in the middle of a batch */
- public void testPrevious2() throws SQLException {
+ @Test public void testPrevious2() throws SQLException {
MMResultSet cs = helpExecuteQuery();
cs.absolute(290);
@@ -229,9 +228,9 @@
}
/** walk all way through from the end back to first row */
- public void testPrevious3() throws SQLException {
+ @Test public void testPrevious3() throws Exception {
//large batch size
- MMResultSet cs = helpExecuteQuery(600, 10000);
+ MMResultSet cs = helpExecuteQuery(600, 10000, ResultSet.TYPE_SCROLL_INSENSITIVE);
List[] expected = TestAllResultsImpl.exampleResults1(10000);
while(cs.next()) {
}
@@ -249,9 +248,9 @@
}
/** walk all way through from the end back to first row */
- public void testPrevious4() throws SQLException {
+ @Test public void testPrevious4() throws Exception {
//small batch size
- MMResultSet cs = helpExecuteQuery(50, 1000);
+ MMResultSet cs = helpExecuteQuery(50, 1000, ResultSet.TYPE_SCROLL_INSENSITIVE);
List[] expected = TestAllResultsImpl.exampleResults1(1000);
while(cs.next()) {
//System.out.println(" rs.next == " + cs.getCurrentRecord());
@@ -270,7 +269,7 @@
}
/** test rare case that cursor change direction */
- public void testChangeDirection() throws SQLException {
+ @Test public void testChangeDirection() throws SQLException {
MMResultSet cs = helpExecuteQuery();
cs.absolute(291);
cs.previous();
@@ -279,7 +278,7 @@
cs.close();
}
- public void testIsFirst() throws SQLException {
+ @Test public void testIsFirst() throws SQLException {
MMResultSet cs = helpExecuteQuery();
cs.next();
assertTrue(cs.isFirst());
@@ -287,7 +286,7 @@
}
/** test cursor is in the middle of all batches */
- public void testIsLast1() throws SQLException {
+ @Test public void testIsLast1() throws SQLException {
MMResultSet cs = helpExecuteQuery();
cs.next();
assertTrue(!cs.isLast());
@@ -295,7 +294,7 @@
}
/** test cursor at the triggering point -- blocking case*/
- public void testIsLast2() throws SQLException {
+ @Test public void testIsLast2() throws SQLException {
MMResultSet cs = helpExecuteQuery();
int i = 0;
@@ -311,20 +310,20 @@
}
/** test cursor at the last row of all batches */
- public void testIsLast3() throws SQLException {
+ @Test public void testIsLast3() throws SQLException {
MMResultSet cs = helpExecuteQuery();
cs.absolute(1000);
assertTrue(cs.isLast());
cs.close();
}
- public void testIsBeforeFirst() throws SQLException {
+ @Test public void testIsBeforeFirst() throws SQLException {
MMResultSet cs = helpExecuteQuery();
assertTrue(cs.isBeforeFirst());
cs.close();
}
- public void testBeforeFirst() throws SQLException {
+ @Test public void testBeforeFirst() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// move to row 1
@@ -337,7 +336,7 @@
cs.close();
}
- public void testFirst() throws SQLException {
+ @Test public void testFirst() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// move to row #2
@@ -351,7 +350,7 @@
cs.close();
}
- public void testAfterLast() throws SQLException {
+ @Test public void testAfterLast() throws SQLException {
MMResultSet cs = helpExecuteQuery();
cs.afterLast();
assertTrue(cs.isAfterLast());
@@ -359,7 +358,7 @@
}
/** right after the last row */
- public void testIsAfterLast1() throws SQLException {
+ @Test public void testIsAfterLast1() throws SQLException {
MMResultSet cs = helpExecuteQuery();
cs.absolute(1000);
cs.next();
@@ -368,14 +367,14 @@
}
/** right before the first */
- public void testIsAfterLast2() throws Exception {
+ @Test public void testIsAfterLast2() throws Exception {
MMResultSet cs = helpExecuteQuery();
assertTrue(!cs.isAfterLast());
cs.close();
}
/** absolute with cursor movement backward in the same batch -- absolute(positive) */
- public void testAbsolute1() throws SQLException {
+ @Test public void testAbsolute1() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// move to row #2
@@ -390,7 +389,7 @@
}
/** absolute with cursor movement forward in the same batch -- absolute(positive) */
- public void testAbsolute2() throws SQLException {
+ @Test public void testAbsolute2() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// move to row #2
@@ -405,7 +404,7 @@
}
/** absolute with cursor movement forward -- absolute(positive) -- blocking */
- public void testAbsolute3() throws SQLException {
+ @Test public void testAbsolute3() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// move to row #2
@@ -420,7 +419,7 @@
}
/** absolute with cursor movement forward -- absolute(positive) -- triggering point */
- public void testAbsolute4() throws SQLException {
+ @Test public void testAbsolute4() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// move to row #2
@@ -435,7 +434,7 @@
}
/** absolute with cursor movement back in the same batch -- absolute(negative) */
- public void testAbsolute5() throws SQLException {
+ @Test public void testAbsolute5() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// move to row #2
@@ -450,7 +449,7 @@
}
/** absolute after last row */
- public void testAbsolute6() throws SQLException {
+ @Test public void testAbsolute6() throws SQLException {
MMResultSet cs = helpExecuteQuery();
cs.absolute(1005);
// Cursor should be after last row. getRow() should return 0 because
@@ -460,7 +459,7 @@
}
/** relative(positive) -- forward to another batch */
- public void testRelative1() throws SQLException {
+ @Test public void testRelative1() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// move to the row #3
@@ -474,7 +473,7 @@
}
/** relative(negative) -- backward to another batch */
- public void testRelative2() throws SQLException {
+ @Test public void testRelative2() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// move to the row #137
@@ -488,7 +487,7 @@
}
/** relative(negative) -- backward to triggering point or blocking batch */
- public void testRelative3() throws SQLException {
+ @Test public void testRelative3() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// move to the row #137
@@ -502,7 +501,7 @@
}
/** relative(negative) -- backward to triggering point or blocking batch */
- public void testRelative4() throws SQLException {
+ @Test public void testRelative4() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// move to the row #237 in the third batch, so that the fourth batch has been requested when we switch direction
@@ -516,7 +515,7 @@
}
/** in the first fetched batch */
- public void testGetRow1() throws SQLException {
+ @Test public void testGetRow1() throws SQLException {
ResultSet cs = helpExecuteQuery();
int i = 0;
@@ -532,7 +531,7 @@
}
/** in the first batch */
- public void testGetRow2() throws SQLException {
+ @Test public void testGetRow2() throws SQLException {
ResultSet cs = helpExecuteQuery();
cs.next();
@@ -541,7 +540,7 @@
}
/** in the triggering point -- blocking */
- public void testGetRow3() throws SQLException {
+ @Test public void testGetRow3() throws SQLException {
ResultSet cs = helpExecuteQuery();
int i = 0;
while (cs.next()) {
@@ -554,7 +553,7 @@
cs.close();
}
- public void testGetCurrentRecord() throws SQLException {
+ @Test public void testGetCurrentRecord() throws SQLException {
ResultSet cs = helpExecuteQuery();
cs.absolute(103);
assertEquals(" Current record doesn't match with expected one.", new Integer(103), ((MMResultSet)cs).getCurrentRecord().get(0)); //$NON-NLS-1$
@@ -562,14 +561,14 @@
}
/** test close() without walking through any of the record*/
- public void testClose() throws SQLException {
+ @Test public void testClose() throws SQLException {
MMResultSet cs = helpExecuteQuery();
assertEquals(" Actual doesn't match with expected. ", new Integer(0), new Integer(cs.getRow())); //$NON-NLS-1$
cs.close();
}
/** test basic results-related metadata */
- public void testGetMetaData() throws SQLException {
+ @Test public void testGetMetaData() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// check result set metadata
@@ -590,7 +589,7 @@
cs.close();
}
- public void testFindColumn() throws SQLException {
+ @Test public void testFindColumn() throws SQLException {
MMResultSet cs = helpExecuteQuery();
ResultSetMetaData rm = cs.getMetaData();
assertNotNull(rm);
@@ -599,7 +598,7 @@
cs.close();
}
- public void testFindNonExistentColumn() throws SQLException {
+ @Test public void testFindNonExistentColumn() throws SQLException {
ResultSet rs = helpExecuteQuery();
rs.next();
try {
@@ -614,13 +613,13 @@
rs.close();
}
- public void testGetStatement() throws SQLException {
+ @Test public void testGetStatement() throws SQLException {
MMResultSet cs = helpExecuteQuery();
assertNotNull(cs.getStatement());
cs.close();
}
- public void testGetPlanDescription() throws SQLException {
+ @Test public void testGetPlanDescription() throws SQLException {
MMResultSet cs = helpExecuteQuery();
assertNotNull(cs);
@@ -629,7 +628,7 @@
}
/** getObject(String) */
- public void testGetObject2() throws SQLException {
+ @Test public void testGetObject2() throws SQLException {
ResultSet cs = helpExecuteQuery();
// move to the 1st row
@@ -638,19 +637,19 @@
cs.close();
}
- public void testGetWarnings() throws SQLException {
+ @Test public void testGetWarnings() throws SQLException {
ResultSet cs = helpExecuteQuery();
assertNull(cs.getWarnings());
cs.close();
}
- public void testGetCursorName() throws SQLException {
+ @Test public void testGetCursorName() throws SQLException {
MMResultSet cs = helpExecuteQuery();
assertNull(cs.getCursorName());
cs.close();
}
- public void testAllGetters() throws SQLException {
+ @Test public void testAllGetters() throws SQLException {
MMResultSet cs = helpExecuteQuery();
cs.next();
assertEquals(" Actual value of getInt() doesn't match with expected one. ", 1, cs.getInt("IntKey")); //$NON-NLS-1$ //$NON-NLS-2$
@@ -664,7 +663,7 @@
}
/** test wasNull() for ResultSet, this result actually is not a cursor result, but AllResults here. */
- public void testWasNull() throws SQLException {
+ @Test public void testWasNull() throws SQLException {
ResultSet cs = helpExecuteQuery();
cs.next();
assertNotNull(cs.getObject("IntKey")); //$NON-NLS-1$
@@ -672,38 +671,64 @@
}
/** test getProcessingTime() -- include test for getProcessingTimestamp() and getCompletedTimestamp() */
- public void testGetProcessingTime() throws SQLException {
+ @Test public void testGetProcessingTime() throws SQLException {
MMResultSet cs = helpExecuteQuery();
assertTrue(cs.getProcessingTime() == cs.getCompletedTimestamp().getTime() - 1);
cs.close();
}
+
+ @Test public void testForwardOnly() throws Exception {
+ MMResultSet cs = helpExecuteQuery(400, 1000, ResultSet.TYPE_FORWARD_ONLY);
+
+ while (cs.next()) {
+ cs.getObject(1);
+ }
+
+ assertTrue(cs.isAfterLast());
+ cs.close();
+ }
+
+ @Test public void testOutputParameter() throws Exception {
+ MMStatement statement = createMockStatement(ResultSet.TYPE_FORWARD_ONLY);
+ ResultsMessage resultsMsg = new ResultsMessage();
+ resultsMsg.setResults(new List<?>[] {Arrays.asList(1, null, null), Arrays.asList(null, 2, 3)});
+ resultsMsg.setLastRow(2);
+ resultsMsg.setFirstRow(1);
+ resultsMsg.setFinalRow(2);
+ resultsMsg.setColumnNames(new String[] {"x", "out1", "out2"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ resultsMsg.setDataTypes(new String[] {"integer", "integer", "integer"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ MMResultSet cs = new MMResultSet(resultsMsg, statement, null, 2);
+
+ int count = 0;
+ while (cs.next()) {
+ cs.getObject(1);
+ count++;
+ }
+ assertEquals(1, count);
+ assertTrue(cs.isAfterLast());
+ assertEquals(2, cs.getOutputParamValue(2));
+ assertEquals(3, cs.getOutputParamValue(3));
+ }
/////////////////////// Helper Method ///////////////////
- private MMResultSet helpExecuteQuery() throws SQLException {
- return helpExecuteQuery(400, 1000);
- }
-
- private MMResultSet helpExecuteQuery(int fetchSize, int totalResults) throws SQLException {
- MMStatement statement = createMockStatement();
+ private MMResultSet helpExecuteQuery() {
try {
- return TestAllResultsImpl.helpTestBatching(statement, fetchSize, Math.min(fetchSize, totalResults), totalResults);
- } catch (MetaMatrixProcessingException e) {
- throw new SQLException(e.getMessage());
- } catch (InterruptedException e) {
- throw new SQLException(e.getMessage());
- } catch (ExecutionException e) {
- throw new SQLException(e.getMessage());
- } catch (TimeoutException e) {
- throw new SQLException(e.getMessage());
+ return helpExecuteQuery(400, 1000, ResultSet.TYPE_SCROLL_INSENSITIVE);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
}
}
+
+ private MMResultSet helpExecuteQuery(int fetchSize, int totalResults, int cursorType) throws SQLException, MetaMatrixProcessingException, InterruptedException, ExecutionException, TimeoutException {
+ MMStatement statement = createMockStatement(cursorType);
+ return TestAllResultsImpl.helpTestBatching(statement, fetchSize, Math.min(fetchSize, totalResults), totalResults);
+ }
- static MMStatement createMockStatement() throws SQLException {
+ static MMStatement createMockStatement(int cursorType) throws SQLException {
MMStatement statement = mock(MMStatement.class);
stub(statement.getDQP()).toReturn(mock(ClientSideDQP.class));
- stub(statement.getResultSetType()).toReturn(
- ResultSet.TYPE_SCROLL_INSENSITIVE);
+ stub(statement.getResultSetType()).toReturn(cursorType);
TimeZone tz = TimeZone.getTimeZone("GMT-06:00"); //$NON-NLS-1$
TimeZone serverTz = TimeZone.getTimeZone("GMT-05:00"); //$NON-NLS-1$
stub(statement.getDefaultCalendar()).toReturn(Calendar.getInstance(tz));
Modified: trunk/common-core/src/main/java/com/metamatrix/core/util/LRUCache.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/LRUCache.java 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/common-core/src/main/java/com/metamatrix/core/util/LRUCache.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -27,7 +27,6 @@
/**
* This class replaces a verbose legacy implementation of LRUCaching.
- * However technically this is an eldest first purging policy.
*/
public class LRUCache<K, V> extends LinkedHashMap<K, V> {
Modified: trunk/engine/src/main/java/com/metamatrix/common/buffer/TupleBatch.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/common/buffer/TupleBatch.java 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/engine/src/main/java/com/metamatrix/common/buffer/TupleBatch.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -26,7 +26,6 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
-import java.io.Serializable;
import java.util.List;
import com.metamatrix.common.batch.BatchSerializer;
@@ -151,6 +150,10 @@
this.types = types;
}
+ public boolean containsRow(int row) {
+ return rowOffset <= row && getEndRow() >= row;
+ }
+
/**
* Return a String describing this object
* @param String representation of this TupleBatch
Modified: trunk/engine/src/main/java/com/metamatrix/common/buffer/TupleBuffer.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/common/buffer/TupleBuffer.java 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/engine/src/main/java/com/metamatrix/common/buffer/TupleBuffer.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -200,21 +200,39 @@
}
batchBuffer.add(tuple);
if (batchBuffer.size() == batchSize) {
- saveBatch(false);
+ saveBatch(false, false);
}
}
/**
+ * Adds the given batch preserving row offsets.
+ * @param batch
+ * @throws MetaMatrixComponentException
+ */
+ public void addTupleBatch(TupleBatch batch, boolean save) throws MetaMatrixComponentException {
+ Assertion.assertTrue(this.rowCount < batch.getBeginRow());
+ if (this.rowCount != batch.getBeginRow() - 1) {
+ saveBatch(false, true);
+ this.rowCount = batch.getBeginRow() - 1;
+ }
+ if (save) {
+ for (List<?> tuple : batch.getAllTuples()) {
+ addTuple(tuple);
+ }
+ }
+ }
+
+ /**
* Force the persistence of any rows held in memory.
* @throws MetaMatrixComponentException
*/
public void saveBatch() throws MetaMatrixComponentException {
- this.saveBatch(false);
+ this.saveBatch(false, false);
}
- void saveBatch(boolean finalBatch) throws MetaMatrixComponentException {
+ void saveBatch(boolean finalBatch, boolean force) throws MetaMatrixComponentException {
Assertion.assertTrue(!this.isRemoved());
- if (batchBuffer == null || batchBuffer.isEmpty() || batchBuffer.size() < Math.max(1, batchSize / 32)) {
+ if (batchBuffer == null || batchBuffer.isEmpty() || (!force && batchBuffer.size() < Math.max(1, batchSize / 32))) {
return;
}
TupleBatch writeBatch = new TupleBatch(rowCount - batchBuffer.size() + 1, batchBuffer);
@@ -230,7 +248,7 @@
public void close() throws MetaMatrixComponentException {
//if there is only a single batch, let it stay in memory
if (!this.batches.isEmpty()) {
- saveBatch(true);
+ saveBatch(true, false);
}
this.isFinal = true;
}
@@ -252,36 +270,35 @@
* @throws MetaMatrixComponentException
*/
public TupleBatch getBatch(int row) throws MetaMatrixComponentException {
+ TupleBatch result = null;
if (row > rowCount) {
- TupleBatch batch = new TupleBatch(rowCount + 1, new List[] {});
- if (isFinal) {
- batch.setTerminationFlag(true);
- }
- return batch;
- }
- if (this.batchBuffer != null && row > rowCount - this.batchBuffer.size()) {
- TupleBatch result = new TupleBatch(rowCount - this.batchBuffer.size() + 1, batchBuffer);
+ result = new TupleBatch(rowCount + 1, new List[] {});
+ } else if (this.batchBuffer != null && row > rowCount - this.batchBuffer.size()) {
+ result = new TupleBatch(rowCount - this.batchBuffer.size() + 1, batchBuffer);
if (forwardOnly) {
this.batchBuffer = null;
}
- return result;
+ } else {
+ if (this.batchBuffer != null && !this.batchBuffer.isEmpty()) {
+ //this is just a sanity check to ensure we're not holding too many
+ //hard references to batches.
+ saveBatch(isFinal, false);
+ }
+ Map.Entry<Integer, BatchManager.ManagedBatch> entry = batches.floorEntry(row);
+ Assertion.isNotNull(entry);
+ BatchManager.ManagedBatch batch = entry.getValue();
+ result = batch.getBatch(!forwardOnly, types);
+ if (lobs && result.getDataTypes() == null) {
+ correctLobReferences(result.getAllTuples());
+ }
+ result.setDataTypes(types);
+ if (forwardOnly) {
+ batches.remove(entry.getKey());
+ }
}
- if (this.batchBuffer != null && !this.batchBuffer.isEmpty()) {
- //this is just a sanity check to ensure we're not holding too many
- //hard references to batches.
- saveBatch(isFinal);
+ if (isFinal && result.getEndRow() == rowCount) {
+ result.setTerminationFlag(true);
}
- Map.Entry<Integer, BatchManager.ManagedBatch> entry = batches.floorEntry(row);
- Assertion.isNotNull(entry);
- BatchManager.ManagedBatch batch = entry.getValue();
- TupleBatch result = batch.getBatch(!forwardOnly, types);
- if (lobs && result.getDataTypes() == null) {
- correctLobReferences(result.getAllTuples());
- }
- result.setDataTypes(types);
- if (forwardOnly) {
- batches.remove(entry.getKey());
- }
return result;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/BatchCollector.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/BatchCollector.java 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/BatchCollector.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -51,7 +51,7 @@
}
public interface BatchHandler {
- void batchProduced(TupleBatch batch) throws MetaMatrixProcessingException, MetaMatrixComponentException;
+ boolean batchProduced(TupleBatch batch) throws MetaMatrixProcessingException, MetaMatrixComponentException;
}
private BatchProducer sourceNode;
@@ -59,7 +59,6 @@
private boolean done = false;
private TupleBuffer buffer;
- private boolean collectedAny;
public BatchCollector(BatchProducer sourceNode, TupleBuffer buffer) {
this.sourceNode = sourceNode;
@@ -91,28 +90,20 @@
* Flush the batch by giving it to the buffer manager.
*/
private void flushBatch(TupleBatch batch) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+ boolean add = true;
+ if (this.batchHandler != null && (batch.getRowCount() > 0 || batch.getTerminationFlag())) {
+ add = this.batchHandler.batchProduced(batch);
+ }
// Add batch
if(batch.getRowCount() > 0) {
- for (List tuple : batch.getAllTuples()) {
- buffer.addTuple(tuple);
- }
- collectedAny = true;
+ buffer.addTupleBatch(batch, add);
}
- if (this.batchHandler != null && (batch.getRowCount() > 0 || batch.getTerminationFlag())) {
- this.batchHandler.batchProduced(batch);
- }
}
public void setBatchHandler(BatchHandler batchHandler) {
this.batchHandler = batchHandler;
}
- public boolean collectedAny() {
- boolean result = collectedAny;
- collectedAny = false;
- return result;
- }
-
public int getRowCount() {
return buffer.getRowCount();
}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -129,7 +129,7 @@
private static final int DEFAULT_MAX_CODE_TABLE_RECORDS = 10000;
private static final int DEFAULT_MAX_CODE_TABLES = 200;
private static final int DEFAULT_MAX_CODE_RECORDS = 200000;
- private static final int DEFAULT_FETCH_SIZE = 2000;
+ private static final int DEFAULT_MAX_FETCH_SIZE = RequestMessage.DEFAULT_FETCH_SIZE * 10;
private static final int DEFAULT_PROCESSOR_TIMESLICE = 2000;
private static final String PROCESS_PLAN_QUEUE_NAME = "QueryProcessorQueue"; //$NON-NLS-1$
private static final int DEFAULT_MAX_PROCESS_WORKERS = 15;
@@ -139,7 +139,7 @@
private int maxCodeTables = DEFAULT_MAX_CODE_TABLES;
private int maxCodeRecords = DEFAULT_MAX_CODE_RECORDS;
- private int maxFetchSize = DEFAULT_FETCH_SIZE;
+ private int maxFetchSize = DEFAULT_MAX_FETCH_SIZE;
// Resources
private BufferManager bufferManager;
@@ -601,7 +601,7 @@
PropertiesUtils.setBeanProperties(this, props, null);
this.processorTimeslice = PropertiesUtils.getIntProperty(props, DQPEmbeddedProperties.PROCESS_TIMESLICE, DEFAULT_PROCESSOR_TIMESLICE);
- this.maxFetchSize = PropertiesUtils.getIntProperty(props, DQPEmbeddedProperties.MAX_FETCH_SIZE, DEFAULT_FETCH_SIZE);
+ this.maxFetchSize = PropertiesUtils.getIntProperty(props, DQPEmbeddedProperties.MAX_FETCH_SIZE, DEFAULT_MAX_FETCH_SIZE);
this.processorDebugAllowed = PropertiesUtils.getBooleanProperty(props, DQPEmbeddedProperties.PROCESSOR_DEBUG_ALLOWED, true);
this.maxCodeTableRecords = PropertiesUtils.getIntProperty(props, DQPEmbeddedProperties.MAX_CODE_TABLE_RECORDS_PER_TABLE, DEFAULT_MAX_CODE_TABLE_RECORDS);
this.maxCodeTables = PropertiesUtils.getIntProperty(props, DQPEmbeddedProperties.MAX_CODE_TABLES, DEFAULT_MAX_CODE_TABLES);
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -343,8 +343,8 @@
processor = request.processor;
collector = processor.createBatchCollector();
collector.setBatchHandler(new BatchHandler() {
- public void batchProduced(TupleBatch batch) throws MetaMatrixComponentException {
- sendResultsIfNeeded(batch);
+ public boolean batchProduced(TupleBatch batch) throws MetaMatrixComponentException {
+ return sendResultsIfNeeded(batch);
}
});
resultsBuffer = collector.getTupleBuffer();
@@ -373,82 +373,91 @@
/**
* Send results if they have been requested. This should only be called from the processing thread.
*/
- protected void sendResultsIfNeeded(TupleBatch batch) throws MetaMatrixComponentException {
+ protected boolean sendResultsIfNeeded(TupleBatch batch) throws MetaMatrixComponentException {
ResultsMessage response = null;
ResultsReceiver<ResultsMessage> receiver = null;
-
+ boolean result = true;
synchronized (this) {
if (this.resultsReceiver == null
- || (this.begin > this.resultsBuffer.getRowCount() && !doneProducingBatches)
+ || (this.begin > (batch != null?batch.getEndRow():this.resultsBuffer.getRowCount()) && !doneProducingBatches)
|| (this.transactionState == TransactionState.ACTIVE)) {
- return;
+ return result;
}
- }
- if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
- LogManager.logDetail(LogConstants.CTX_DQP, "[RequestWorkItem.sendResultsIfNeeded] requestID: " + requestID + " resultsID: " + this.resultsBuffer + " done: " + doneProducingBatches ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- if (batch == null || !(batch.getBeginRow() <= this.begin && batch.getEndRow() >= this.begin)) {
- if (savedBatch != null && savedBatch.getBeginRow() <= this.begin && savedBatch.getEndRow() >= this.begin) {
- batch = savedBatch;
- } else {
- batch = resultsBuffer.getBatch(begin);
- }
- //TODO: support fetching more than 1 batch
+
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
+ LogManager.logDetail(LogConstants.CTX_DQP, "[RequestWorkItem.sendResultsIfNeeded] requestID:", requestID, "resultsID:", this.resultsBuffer, "done:", doneProducingBatches ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ //TODO: support fetching more than 1 batch
+ boolean fromBuffer = false;
+ if (batch == null || !(batch.containsRow(this.begin))) {
+ if (savedBatch != null && savedBatch.containsRow(this.begin)) {
+ batch = savedBatch;
+ } else {
+ batch = resultsBuffer.getBatch(begin);
+ }
+ savedBatch = null;
+ fromBuffer = true;
+ }
int count = this.end - this.begin + 1;
if (batch.getRowCount() > count) {
- if (requestMsg.getCursorType() == ResultSet.TYPE_FORWARD_ONLY) {
- savedBatch = batch;
- }
int beginRow = Math.min(this.begin, batch.getEndRow() - count + 1);
int endRow = Math.min(beginRow + count - 1, batch.getEndRow());
+ boolean last = false;
+ if (endRow == batch.getEndRow()) {
+ last = batch.getTerminationFlag();
+ } else if (fromBuffer && requestMsg.getCursorType() == ResultSet.TYPE_FORWARD_ONLY) {
+ savedBatch = batch;
+ }
int firstOffset = beginRow - batch.getBeginRow();
List[] memoryRows = batch.getAllTuples();
List[] rows = new List[count];
System.arraycopy(memoryRows, firstOffset, rows, 0, endRow - beginRow + 1);
batch = new TupleBatch(beginRow, rows);
+ batch.setTerminationFlag(last);
+ } else if (!fromBuffer){
+ result = requestMsg.getCursorType() != ResultSet.TYPE_FORWARD_ONLY;
}
- }
- int finalRowCount = this.resultsBuffer.isFinal()?this.resultsBuffer.getRowCount():-1;
-
- response = createResultsMessage(requestMsg, batch.getAllTuples(), this.processor.getProcessorPlan().getOutputElements(), analysisRecord);
- response.setFirstRow(batch.getBeginRow());
- response.setLastRow(batch.getEndRow());
- response.setUpdateResult(this.returnsUpdateCount);
- // set final row
- response.setFinalRow(finalRowCount);
-
- // send any schemas associated with the results
- response.setSchemas(this.schemas);
-
- // send any warnings with the response object
- List<Throwable> responseWarnings = new ArrayList<Throwable>();
- List<Exception> currentWarnings = processor.getAndClearWarnings();
- if (currentWarnings != null) {
- responseWarnings.addAll(currentWarnings);
- }
- synchronized (warnings) {
- responseWarnings.addAll(this.warnings);
- this.warnings.clear();
- }
- response.setWarnings(responseWarnings);
-
- // If it is stored procedure, set parameters
- if (originalCommand instanceof StoredProcedure) {
- StoredProcedure proc = (StoredProcedure)originalCommand;
- if (proc.returnParameters()) {
- response.setParameters(getParameterInfo(proc));
- }
- }
- /*
- * mark the results sent at this point.
- * communication exceptions will be treated as non-recoverable
- */
- synchronized (this) {
+ int finalRowCount = this.resultsBuffer.isFinal()?this.resultsBuffer.getRowCount():(batch.getTerminationFlag()?batch.getEndRow():-1);
+
+ response = createResultsMessage(requestMsg, batch.getAllTuples(), this.processor.getProcessorPlan().getOutputElements(), analysisRecord);
+ response.setFirstRow(batch.getBeginRow());
+ response.setLastRow(batch.getEndRow());
+ response.setUpdateResult(this.returnsUpdateCount);
+ // set final row
+ response.setFinalRow(finalRowCount);
+
+ // send any schemas associated with the results
+ response.setSchemas(this.schemas);
+
+ // send any warnings with the response object
+ List<Throwable> responseWarnings = new ArrayList<Throwable>();
+ List<Exception> currentWarnings = processor.getAndClearWarnings();
+ if (currentWarnings != null) {
+ responseWarnings.addAll(currentWarnings);
+ }
+ synchronized (warnings) {
+ responseWarnings.addAll(this.warnings);
+ this.warnings.clear();
+ }
+ response.setWarnings(responseWarnings);
+
+ // If it is stored procedure, set parameters
+ if (originalCommand instanceof StoredProcedure) {
+ StoredProcedure proc = (StoredProcedure)originalCommand;
+ if (proc.returnParameters()) {
+ response.setParameters(getParameterInfo(proc));
+ }
+ }
+ /*
+ * mark the results sent at this point.
+ * communication exceptions will be treated as non-recoverable
+ */
receiver = this.resultsReceiver;
this.resultsReceiver = null;
}
receiver.receiveResults(response);
+ return result;
}
public static ResultsMessage createResultsMessage(RequestMessage message, List[] batch, List columnSymbols, AnalysisRecord analysisRecord) {
Added: trunk/engine/src/test/java/com/metamatrix/common/buffer/TestTupleBuffer.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/common/buffer/TestTupleBuffer.java (rev 0)
+++ trunk/engine/src/test/java/com/metamatrix/common/buffer/TestTupleBuffer.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.common.buffer;
+
+import static org.junit.Assert.*;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+
+import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.common.types.DataTypeManager;
+import com.metamatrix.query.sql.symbol.ElementSymbol;
+
+public class TestTupleBuffer {
+
+ @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 = new TupleBuffer(new BatchManager() {
+
+ @Override
+ public void remove() {
+
+ }
+
+ @Override
+ public ManagedBatch createManagedBatch(final TupleBatch batch)
+ throws MetaMatrixComponentException {
+ return new ManagedBatch() {
+
+ @Override
+ public void remove() {
+
+ }
+
+ @Override
+ public TupleBatch getBatch(boolean cache, String[] types)
+ throws MetaMatrixComponentException {
+ return batch;
+ }
+ };
+ }
+ }, "x", schema, 32); //$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());
+ }
+
+}
Property changes on: trunk/engine/src/test/java/com/metamatrix/common/buffer/TestTupleBuffer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
More information about the teiid-commits
mailing list