use of org.apache.olingo.commons.api.edm.EdmNavigationProperty in project teiid by teiid.
the class ODataSQLBuilder method visit.
@Override
public void visit(UriResourceNavigation info) {
EdmNavigationProperty property = info.getProperty();
try {
DocumentNode joinResource = DocumentNode.build(property.getType(), info.getKeyPredicates(), this.metadata, this.odata, this.nameGenerator, true, getUriInfo(), parseService);
this.context.joinTable(joinResource, property, JoinType.JOIN_INNER);
// In the context of canonical queries if key predicates are available then do not set the criteria
if (joinResource.getCriteria() == null) {
joinResource.addCriteria(this.context.getCriteria());
}
this.context = joinResource;
this.navigation = true;
} catch (TeiidException e) {
this.exceptions.add(e);
}
}
use of org.apache.olingo.commons.api.edm.EdmNavigationProperty in project teiid by teiid.
the class ReferenceUpdateSQLBuilder method visit.
@Override
public void visit(UriResourceNavigation info) {
EdmNavigationProperty property = info.getProperty();
this.referenceTable = new ScopedTable(DocumentNode.findTable(property.getType(), this.metadata), property.getType(), info.getKeyPredicates());
if (property.isCollection()) {
ForeignKey fk = DocumentNode.joinFK(referenceTable, this.updateTable, property);
referenceTable.setFk(fk);
ScopedTable temp = this.updateTable;
this.updateTable = referenceTable;
this.referenceTable = temp;
this.collection = true;
} else {
ForeignKey fk = DocumentNode.joinFK(this.updateTable, referenceTable, property);
this.updateTable.setFk(fk);
}
}
use of org.apache.olingo.commons.api.edm.EdmNavigationProperty in project teiid by teiid.
the class TeiidServiceHandler method performDeepInsert.
private UpdateResponse performDeepInsert(String rawURI, UriInfo uriInfo, EdmEntityType entityType, Entity entity, List<ExpandNode> expandNodes) throws SQLException, TeiidException {
UpdateResponse response = performInsert(rawURI, uriInfo, entityType, entity);
for (String navigationName : entityType.getNavigationPropertyNames()) {
EdmNavigationProperty navProperty = entityType.getNavigationProperty(navigationName);
Link navLink = entity.getNavigationLink(navigationName);
if (navLink != null && navLink.getInlineEntity() != null) {
ExpandNode node = new ExpandNode();
node.navigationProperty = navProperty;
expandNodes.add(node);
performDeepInsert(rawURI, uriInfo, navProperty.getType(), navLink.getInlineEntity(), node.children);
} else if (navLink != null && navLink.getInlineEntitySet() != null && !navLink.getInlineEntitySet().getEntities().isEmpty()) {
ExpandNode node = new ExpandNode();
node.navigationProperty = navProperty;
expandNodes.add(node);
for (Entity inlineEntity : navLink.getInlineEntitySet().getEntities()) {
performDeepInsert(rawURI, uriInfo, navProperty.getType(), inlineEntity, node.children);
}
}
}
return response;
}
use of org.apache.olingo.commons.api.edm.EdmNavigationProperty in project teiid by teiid.
the class ODataSQLBuilder method buildExpandGraph.
private void buildExpandGraph(HashSet<String> seen, List<ExpandNode> starExpand, EdmEntityType edmEntityType, int remainingLevels) {
for (String name : edmEntityType.getNavigationPropertyNames()) {
if (seen != null && seen.contains(name)) {
// explicit expand supersedes
continue;
}
EdmNavigationProperty property = edmEntityType.getNavigationProperty(name);
ExpandNode en = new ExpandNode();
en.navigationProperty = property;
starExpand.add(en);
if (remainingLevels > 0) {
buildExpandGraph(null, en.children, property.getType(), remainingLevels - 1);
}
}
}
use of org.apache.olingo.commons.api.edm.EdmNavigationProperty in project teiid by teiid.
the class ODataSQLBuilder method processExpandOption.
private void processExpandOption(ExpandOption option, DocumentNode node, Query outerQuery, int expandLevel, Integer cyclicLevel) throws TeiidException {
checkExpandLevel(expandLevel);
int starLevels = 0;
HashSet<String> seen = new HashSet<String>();
for (ExpandItem ei : option.getExpandItems()) {
if (ei.getSearchOption() != null) {
throw new TeiidNotImplementedException(ODataPlugin.Event.TEIID16035, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16035));
}
Integer levels = null;
if (cyclicLevel != null) {
levels = cyclicLevel - 1;
} else if (ei.getLevelsOption() != null) {
if (ei.getLevelsOption().isMax()) {
levels = MAX_EXPAND_LEVEL - expandLevel + 1;
} else {
levels = ei.getLevelsOption().getValue();
checkExpandLevel(expandLevel + levels - 1);
}
}
ExpandSQLBuilder esb = new ExpandSQLBuilder(ei);
EdmNavigationProperty property = esb.getNavigationProperty();
if (property == null) {
if (ei.isStar()) {
if (starLevels > 0) {
throw new TeiidProcessingException(ODataPlugin.Event.TEIID16058, // $NON-NLS-1$
ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16058, "*"));
}
if (levels != null) {
starLevels = levels;
} else {
starLevels = 1;
}
continue;
}
throw new TeiidNotImplementedException(ODataPlugin.Event.TEIID16057, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16057));
}
if (!seen.add(property.getName())) {
throw new TeiidProcessingException(ODataPlugin.Event.TEIID16058, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16058, property.getName()));
}
// always pass in the root as the parent as that seems to be the definition of the current context
// if instead it should refer to the parent expands, then we would pass in the node instead
ExpandDocumentNode expandResource = ExpandDocumentNode.buildExpand(property, this.metadata, this.odata, this.nameGenerator, true, getUriInfo(), this.parseService, this.context);
node.addExpand(expandResource);
// process $filter
if (ei.getFilterOption() != null) {
Expression expandCriteria = processFilterOption(ei.getFilterOption(), expandResource);
expandResource.addCriteria(expandCriteria);
}
OrderBy expandOrder = null;
if (ei.getOrderByOption() != null) {
expandOrder = new OrderBy();
processOrderBy(expandOrder, ei.getOrderByOption().getOrders(), expandResource);
} else {
expandOrder = expandResource.addDefaultOrderBy();
}
// process $select
processSelectOption(ei.getSelectOption(), expandResource, this.reference);
if (ei.getSkipOption() != null) {
expandResource.setSkip(ei.getSkipOption().getValue());
}
if (ei.getTopOption() != null) {
expandResource.setTop(ei.getTopOption().getValue());
}
Query query = expandResource.buildQuery();
if (ei.getExpandOption() != null) {
processExpandOption(ei.getExpandOption(), expandResource, query, expandLevel + 1, null);
} else if (levels != null) {
// self reference check
if (!property.getType().getFullQualifiedName().equals(node.getEdmEntityType().getFullQualifiedName())) {
throw new TeiidProcessingException(ODataPlugin.Event.TEIID16060, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16060, node.getEdmEntityType().getFullQualifiedName(), property.getType().getFullQualifiedName()));
}
if (levels > 1) {
ExpandOptionImpl eoi = new ExpandOptionImpl();
eoi.addExpandItem(ei);
processExpandOption(eoi, expandResource, query, expandLevel + 1, levels);
}
}
buildAggregateQuery(node, outerQuery, expandResource, expandOrder, query, property);
}
if (starLevels > 0) {
List<ExpandNode> starExpand = new ArrayList<TeiidServiceHandler.ExpandNode>();
EdmEntityType edmEntityType = node.getEdmEntityType();
buildExpandGraph(seen, starExpand, edmEntityType, starLevels - 1);
if (!starExpand.isEmpty()) {
processExpand(starExpand, node, outerQuery, expandLevel);
}
}
}
Aggregations