Search in sources :

Example 1 with EdmNavigationProperty

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);
    }
}
Also used : EdmNavigationProperty(org.apache.olingo.commons.api.edm.EdmNavigationProperty) TeiidException(org.teiid.core.TeiidException)

Example 2 with EdmNavigationProperty

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);
    }
}
Also used : EdmNavigationProperty(org.apache.olingo.commons.api.edm.EdmNavigationProperty) ForeignKey(org.teiid.metadata.ForeignKey)

Example 3 with EdmNavigationProperty

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;
}
Also used : UpdateResponse(org.teiid.odata.api.UpdateResponse) Entity(org.apache.olingo.commons.api.data.Entity) EdmNavigationProperty(org.apache.olingo.commons.api.edm.EdmNavigationProperty) Link(org.apache.olingo.commons.api.data.Link)

Example 4 with EdmNavigationProperty

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);
        }
    }
}
Also used : ExpandNode(org.teiid.olingo.service.TeiidServiceHandler.ExpandNode) EdmNavigationProperty(org.apache.olingo.commons.api.edm.EdmNavigationProperty)

Example 5 with EdmNavigationProperty

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);
        }
    }
}
Also used : ExpandOptionImpl(org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl) ExpandNode(org.teiid.olingo.service.TeiidServiceHandler.ExpandNode) ArrayList(java.util.ArrayList) EdmNavigationProperty(org.apache.olingo.commons.api.edm.EdmNavigationProperty) EdmEntityType(org.apache.olingo.commons.api.edm.EdmEntityType) SubqueryHint(org.teiid.query.sql.lang.ExistsCriteria.SubqueryHint) TeiidProcessingException(org.teiid.core.TeiidProcessingException) Expression(org.teiid.query.sql.symbol.Expression) HashSet(java.util.HashSet)

Aggregations

EdmNavigationProperty (org.apache.olingo.commons.api.edm.EdmNavigationProperty)6 Entity (org.apache.olingo.commons.api.data.Entity)2 Link (org.apache.olingo.commons.api.data.Link)2 ExpandNode (org.teiid.olingo.service.TeiidServiceHandler.ExpandNode)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 EdmEntityType (org.apache.olingo.commons.api.edm.EdmEntityType)1 ExpandOptionImpl (org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl)1 TeiidException (org.teiid.core.TeiidException)1 TeiidProcessingException (org.teiid.core.TeiidProcessingException)1 ForeignKey (org.teiid.metadata.ForeignKey)1 UpdateResponse (org.teiid.odata.api.UpdateResponse)1 SubqueryHint (org.teiid.query.sql.lang.ExistsCriteria.SubqueryHint)1 Expression (org.teiid.query.sql.symbol.Expression)1