Skip to content

Commit

Permalink
TEIID-2933 fix for skip token
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins authored and johnathonlee committed Jul 11, 2014
1 parent c819c6d commit 23fed3c
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 1 deletion.
5 changes: 4 additions & 1 deletion odata/src/main/java/org/teiid/odata/EntityList.java
Expand Up @@ -76,8 +76,11 @@ public EntityList(LinkedHashMap<String, Boolean> columns, EdmEntitySet entitySet
if (size == -1) {
size = Integer.MAX_VALUE;
}
if (skipSize > 0) {
rs.absolute(skipSize);
}
for (int i = 1; i <= size; i++) {
if (!rs.absolute(i)) {
if (!rs.next()) {
break;
}
this.add(getEntity(rs, propertyTypes, columns, entitySet));
Expand Down
99 changes: 99 additions & 0 deletions odata/src/test/java/org/teiid/odata/TestODataIntegration.java
Expand Up @@ -25,6 +25,7 @@
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;

import java.io.IOException;
import java.io.StringWriter;
import java.math.BigDecimal;
import java.util.ArrayList;
Expand Down Expand Up @@ -71,6 +72,9 @@
import org.teiid.core.util.UnitTestUtil;
import org.teiid.dqp.service.AutoGenDataService;
import org.teiid.jdbc.TeiidDriver;
import org.teiid.json.simple.ContentHandler;
import org.teiid.json.simple.JSONParser;
import org.teiid.json.simple.ParseException;
import org.teiid.language.QueryExpression;
import org.teiid.metadata.KeyRecord;
import org.teiid.metadata.MetadataStore;
Expand Down Expand Up @@ -336,6 +340,101 @@ public void testProcedureCall() throws Exception {
}
}

@Test public void testSkip() throws Exception {
EmbeddedServer es = new EmbeddedServer();
es.start(new EmbeddedConfiguration());
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("vw");
mmd.setSchemaSourceType("ddl");
mmd.setModelType(Type.VIRTUAL);
mmd.setSchemaText("create view x (a string primary key, b integer) as select 'xyz', 123 union all select 'abc', 456;");
es.deployVDB("northwind", mmd);

TeiidDriver td = es.getDriver();
Properties props = new Properties();
props.setProperty("batch-size", "1");
LocalClient lc = new LocalClient("northwind", 1, props);
lc.setDriver(td);
MockProvider.CLIENT = lc;

ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/odata/northwind/x?$format=json"));
ClientResponse<String> response = request.get(String.class);
assertEquals(200, response.getStatus());
JSONParser parser = new JSONParser();
final String[] val = new String[1];
parser.parse(response.getEntity(), new ContentHandler() {
boolean next;

@Override
public boolean startObjectEntry(String key) throws ParseException,
IOException {
if (key.equals("__next")) {
next = true;
}
return true;
}

@Override
public boolean startObject() throws ParseException, IOException {
return true;
}

@Override
public void startJSON() throws ParseException, IOException {

}

@Override
public boolean startArray() throws ParseException, IOException {
return true;
}

@Override
public boolean primitive(Object value) throws ParseException, IOException {
if (next) {
val[0] = (String) value;
next = false;
}
return true;
}

@Override
public boolean endObjectEntry() throws ParseException, IOException {
return true;
}

@Override
public boolean endObject() throws ParseException, IOException {
return true;
}

@Override
public void endJSON() throws ParseException, IOException {

}

@Override
public boolean endArray() throws ParseException, IOException {
return true;
}
});
assertNotNull(val[0]);
assertTrue(response.getEntity().contains("abc"));
assertTrue(!response.getEntity().contains("xyz"));

//follow the skip
request = new ClientRequest(val[0]);
response = request.get(String.class);
assertEquals(200, response.getStatus());

assertTrue(!response.getEntity().contains("abc"));
assertTrue(response.getEntity().contains("xyz"));
} finally {
es.stop();
}
}

@Test public void testCompositeKeyUpdates() throws Exception {
EmbeddedServer es = new EmbeddedServer();
HardCodedExecutionFactory hc = new HardCodedExecutionFactory() {
Expand Down

0 comments on commit 23fed3c

Please sign in to comment.