Пример #1
0
 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;
 }
Пример #2
0
  /**
   * Example: For the following navigation: DemoService.svc/Categories(1)/Products we need the
   * EdmEntitySet for the navigation property "Products"
   *
   * <p>This is defined as follows in the metadata: <code>
   *
   * <EntitySet Name="Categories" EntityType="OData.Demo.Category">
   * <NavigationPropertyBinding Path="Products" Target="Products"/>
   * </EntitySet>
   * </code> The "Target" attribute specifies the target EntitySet Therefore we need the
   * startEntitySet "Categories" in order to retrieve the target EntitySet "Products"
   */
  public static EdmEntitySet getNavigationTargetEntitySet(
      EdmEntitySet startEntitySet, EdmNavigationProperty edmNavigationProperty)
      throws ODataApplicationException {

    EdmEntitySet navigationTargetEntitySet = null;

    String navPropName = edmNavigationProperty.getName();
    EdmBindingTarget edmBindingTarget = startEntitySet.getRelatedBindingTarget(navPropName);
    if (edmBindingTarget == null) {
      throw new ODataApplicationException(
          "Not supported.", HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
    }

    if (edmBindingTarget instanceof EdmEntitySet) {
      navigationTargetEntitySet = (EdmEntitySet) edmBindingTarget;
    } else {
      throw new ODataApplicationException(
          "Not supported.", HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
    }

    return navigationTargetEntitySet;
  }
  private void appendNavigationProperties(
      final XMLStreamWriter writer, final EdmStructuredType type) throws XMLStreamException {
    List<String> navigationPropertyNames = new ArrayList<String>(type.getNavigationPropertyNames());
    if (type.getBaseType() != null) {
      navigationPropertyNames.removeAll(type.getBaseType().getNavigationPropertyNames());
    }
    for (String navigationPropertyName : navigationPropertyNames) {
      EdmNavigationProperty navigationProperty = type.getNavigationProperty(navigationPropertyName);

      writer.writeStartElement(XML_NAVIGATION_PROPERTY);
      writer.writeAttribute(XML_NAME, navigationPropertyName);
      writer.writeAttribute(
          XML_TYPE,
          getAliasedFullQualifiedName(
              navigationProperty.getType(), navigationProperty.isCollection()));
      if (!navigationProperty.isNullable()) {
        writer.writeAttribute(XML_NULLABLE, "" + navigationProperty.isNullable());
      }

      if (navigationProperty.getPartner() != null) {
        EdmNavigationProperty partner = navigationProperty.getPartner();
        writer.writeAttribute(XML_PARTNER, partner.getName());
      }

      if (navigationProperty.containsTarget()) {
        writer.writeAttribute(XML_CONTAINS_TARGET, "" + navigationProperty.containsTarget());
      }

      if (navigationProperty.getReferentialConstraints() != null) {
        for (EdmReferentialConstraint constraint : navigationProperty.getReferentialConstraints()) {
          writer.writeEmptyElement("ReferentialConstraint");
          writer.writeAttribute(XML_PROPERTY, constraint.getPropertyName());
          writer.writeAttribute("ReferencedProperty", constraint.getReferencedPropertyName());
        }
      }

      writer.writeEndElement();
    }
  }