Skip to content

Commit

Permalink
Merge branch 'master' of github.com:teiid/teiid
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Mar 21, 2016
2 parents 3006b7f + a93daa5 commit 55694c0
Show file tree
Hide file tree
Showing 13 changed files with 460 additions and 67 deletions.
2 changes: 1 addition & 1 deletion olingo/src/main/java/org/teiid/odata/api/Client.java
Expand Up @@ -45,7 +45,7 @@ void executeCall(String sql, List<SQLParameter> sqlParams, ProcedureReturnType r

void executeSQL(Query query, List<SQLParameter> parameters,
boolean calculateTotalSize, Integer skip, Integer top, String nextOption, int pageSize,
QueryResponse response) throws SQLException;
QueryResponse response, boolean expand) throws SQLException;

CountResponse executeCount(Query query, List<SQLParameter> parameters) throws SQLException;

Expand Down
4 changes: 3 additions & 1 deletion olingo/src/main/java/org/teiid/odata/api/QueryResponse.java
Expand Up @@ -25,9 +25,11 @@
import java.sql.SQLException;

public interface QueryResponse extends BaseResponse {
void addRow(ResultSet rs) throws SQLException;
void addRow(ResultSet rs, boolean sameEntity) throws SQLException;
long size();
void setCount(long count);
void setNextToken(String token);
String getNextToken();
boolean isSameEntity(ResultSet rs) throws SQLException;
void advanceRow(ResultSet rs, boolean sameEntity) throws SQLException;
}
Expand Up @@ -44,7 +44,7 @@ public CrossJoinResult(String baseURL, String invalidCharacterReplacement, Cross
}

@Override
public void addRow(ResultSet rs) throws SQLException {
public void addRow(ResultSet rs, boolean sameEntity) throws SQLException {

ArrayList<ComplexReturnType> row = new ArrayList<ComplexReturnType>();

Expand All @@ -66,6 +66,15 @@ public void addRow(ResultSet rs) throws SQLException {
this.out.add(row);
}

@Override
public boolean isSameEntity(ResultSet rs) throws SQLException {
return false;
}

@Override
public void advanceRow(ResultSet rs, boolean sameEntity) throws SQLException {
}

public CrossJoinNode getResource() {
return this.documentNode;
}
Expand Down
12 changes: 11 additions & 1 deletion olingo/src/main/java/org/teiid/olingo/service/DocumentNode.java
Expand Up @@ -257,7 +257,6 @@ void addProjectedColumn(final String columnName,

void addProjectedColumn(final Expression expr, final boolean visibility,
final EdmType type, final boolean collection) {

int i = 0;
for (i = 0; i < this.projectedColumns.size(); i++) {
ProjectedColumn pc = this.projectedColumns.get(i);
Expand All @@ -269,6 +268,17 @@ void addProjectedColumn(final Expression expr, final boolean visibility,
this.projectedColumns.add(new ProjectedColumn(expr, visibility, type, collection));
}

boolean hasProjectedColumn(final Expression expr) {
int i = 0;
for (i = 0; i < this.projectedColumns.size(); i++) {
ProjectedColumn pc = this.projectedColumns.get(i);
if (pc.getExpression().equals(expr)) {
return true;
}
}
return false;
}

OrderBy addDefaultOrderBy() {
OrderBy orderBy = new OrderBy();
// provide implicit ordering for cursor logic
Expand Down
Expand Up @@ -81,6 +81,10 @@ public class EntityCollectionResponse extends EntityCollection implements QueryR
private String baseURL;
private Map<String, Object> streams;

private EntityCollectionResponse() {
this.invalidCharacterReplacement = null;
}

public EntityCollectionResponse(String baseURL, String invalidCharacterReplacement,
DocumentNode resource) {
this.baseURL = baseURL;
Expand All @@ -89,15 +93,15 @@ public EntityCollectionResponse(String baseURL, String invalidCharacterReplaceme
}

@Override
public void addRow(ResultSet rs) throws SQLException {
public void addRow(ResultSet rs, boolean sameEntity) throws SQLException {
Entity entity = null;
boolean add = true;

if (this.currentEntity == null) {
entity = createEntity(rs, this.documentNode, this.invalidCharacterReplacement, this.baseURL, this);
this.currentEntity = entity;
} else {
if(isSameRow(rs, this.documentNode, this.currentEntity)) {
if(sameEntity) {
entity = this.currentEntity;
add = false;
} else {
Expand All @@ -113,16 +117,36 @@ public void addRow(ResultSet rs) throws SQLException {
ExpandDocumentNode expandNode = (ExpandDocumentNode)resource;
Entity expandEntity = createEntity(rs, expandNode, this.invalidCharacterReplacement, this.baseURL, this);

// make sure the expanded entity has valid key, otherwise it is just nulls on right side
boolean valid = true;
for (String key:resource.getEdmEntityType().getKeyPredicateNames()) {
Property p = expandEntity.getProperty(key);
if (p.getValue() == null) {
valid = false;
break;
}
}

if (!valid) {
continue;
}

Link link = entity.getNavigationLink(expandNode.getNavigationName());
if (expandNode.isCollection()) {
if (link.getInlineEntitySet() == null) {
link.setInlineEntitySet(new EntityCollection());
link.setInlineEntitySet(new EntityCollectionResponse());
}
EntityCollectionResponse expandResponse = (EntityCollectionResponse)link.getInlineEntitySet();
boolean addEntity = expandResponse.processOptions(
expandNode.getSkip(), expandNode.getTop(),
expandEntity);
if (addEntity) {
link.getInlineEntitySet().getEntities().add(expandEntity);
}
link.getInlineEntitySet().getEntities().add(expandEntity);
}
else {
link.setInlineEntity(expandEntity);
}
link.setInlineEntity(expandEntity);
}
}
}

Expand All @@ -134,8 +158,37 @@ public void addRow(ResultSet rs) throws SQLException {
}
}

@Override
public boolean isSameEntity(ResultSet rs) throws SQLException {
if (this.currentEntity == null) {
this.currentEntity = createEntity(rs, this.documentNode,
this.invalidCharacterReplacement, this.baseURL, this);
return false;
} else {
if (isSameRow(rs, this.documentNode, this.currentEntity)) {
return true;
} else {
this.currentEntity = createEntity(rs, this.documentNode,
this.invalidCharacterReplacement, this.baseURL, this);
return false;
}
}
}

@Override
public void advanceRow(ResultSet rs, boolean sameEntity) throws SQLException {
if (this.currentEntity == null) {
this.currentEntity = createEntity(rs, this.documentNode,
this.invalidCharacterReplacement, this.baseURL, this);
} else {
if (!sameEntity) {
this.currentEntity = createEntity(rs, this.documentNode,
this.invalidCharacterReplacement, this.baseURL, this);
}
}
}

private boolean isSameRow(ResultSet rs, DocumentNode node, Entity other) throws SQLException {

List<ProjectedColumn> projected = node.getAllProjectedColumns();
EdmEntityType entityType = node.getEdmEntityType();

Expand Down Expand Up @@ -467,7 +520,7 @@ public long size() {

@Override
public void setCount(long count) {
super.setCount((int) count);
this.collectionCount = (int)count;
}

@Override
Expand All @@ -479,4 +532,32 @@ public void setNextToken(String token) {
public String getNextToken() {
return this.nextToken;
}

private int skipped = 0;
private int topCount = 0;
private int collectionCount = 0;

private boolean processOptions(int skip, int top, Entity expandEntity) {
this.collectionCount++;

if (skip > 0 && this.skipped < skip) {
this.skipped++;
return false;
}

if (top > 0 ) {
if (this.topCount < top) {
this.topCount++;
return true;
} else {
return false;
}
}
return true;
}

@Override
public Integer getCount() {
return this.collectionCount;
}
}
Expand Up @@ -21,6 +21,7 @@
*/
package org.teiid.olingo.service;

import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
import org.apache.olingo.server.api.OData;
Expand All @@ -34,7 +35,10 @@
public class ExpandDocumentNode extends DocumentNode {
private String navigationName;
private boolean collection;

private int top;
private int skip;
private boolean calculateCount;

public static ExpandDocumentNode buildExpand(EdmNavigationProperty property,
MetadataStore metadata, OData odata, UniqueNameGenerator nameGenerator,
boolean useAlias, UriInfo uriInfo, URLParseService parseService) throws TeiidException {
Expand All @@ -61,5 +65,29 @@ public boolean isCollection() {

public void setCollection(boolean collection) {
this.collection = collection;
}
}

public void setTop(int value) {
this.top = value;
}

public int getTop() {
return top;
}

public void setSkip(int value) {
this.skip = value;
}

public int getSkip() {
return skip;
}

public boolean isCalculateCount() {
return this.calculateCount;
}

public void setCalculateCount(boolean calculateCount) {
this.calculateCount = calculateCount;
}
}

0 comments on commit 55694c0

Please sign in to comment.