Пример #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;
 }
  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();
    }
  }