예제 #1
0
 public static String javaType(EdmType type) {
   // TODO support complex type keys?
   assert (type.isSimple());
   String javaType = null;
   if (EdmSimpleType.INT64 == type) {
     javaType = "Long";
   } else if (EdmSimpleType.INT32 == type) {
     javaType = "Integer";
   } else if (EdmSimpleType.INT16 == type) {
     javaType = "Integer";
   } else if (EdmSimpleType.STRING == type) {
     javaType = "String";
   } else if (EdmSimpleType.DATETIME == type) {
     javaType = "java.util.Date";
   } else if (EdmSimpleType.TIME == type) {
     javaType = "java.util.Date";
   } else if (EdmSimpleType.DECIMAL == type) {
     javaType = "java.math.BigDecimal";
   } else if (EdmSimpleType.SINGLE == type) {
     javaType = "Float";
   } else if (EdmSimpleType.DOUBLE == type) {
     javaType = "Double";
   } else if (EdmSimpleType.BOOLEAN == type) {
     javaType = "Boolean";
   } else if (EdmSimpleType.GUID == type) {
     javaType = "String";
   } else if (EdmSimpleType.BINARY == type) {
     javaType = "String";
   } else {
     // TODO support types other than Long and String
     throw new RuntimeException(
         "Entity property type " + type.getFullyQualifiedTypeName() + " not supported");
   }
   return javaType;
 }
 private void writeProperty(
     StreamWriter writer, EntityMetadata entityMetadata, EntityProperty property) {
   String elementText = entityMetadata.getPropertyValueAsString(property);
   writer.startElement(new QName(d, property.getName(), "d"));
   EdmType type =
       MetadataOData4j.termValueToEdmType(
           entityMetadata.getTermValue(property.getFullyQualifiedName(), TermValueType.TERM_NAME));
   boolean isNullable = entityMetadata.isPropertyNullable(property.getFullyQualifiedName());
   // Append Type Attribute
   if (!type.equals(EdmSimpleType.STRING)) {
     writer.writeAttribute(new QName(m, "type", "m"), type.getFullyQualifiedTypeName());
   }
   // Append Null attribute
   if (isNullable && (elementText.isEmpty()) && !type.equals(EdmSimpleType.STRING)) {
     writer.writeAttribute(new QName(m, "null", "m"), "true");
   }
   // Write the property text
   if (type.equals(EdmSimpleType.DATETIME) && !elementText.isEmpty()) {
     // Write dates in UTC format
     SimpleDateFormat formatUTC = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
     formatUTC.setTimeZone(TimeZone.getTimeZone("UTC"));
     writer.writeElementText(formatUTC.format((Date) property.getValue()));
   } else if (elementText != null) {
     writer.writeElementText(elementText);
   }
   writer.endElement();
 }
예제 #3
0
  /*
   * Create a property with vocabulary term from the Edmx property
   */
  public static EMProperty createEMProperty(EdmProperty property) {
    EMProperty emProperty = new EMProperty(property.getName());
    if (property.isNullable()) {
      emProperty.addVocabularyTerm(new EMTerm(TermMandatory.TERM_NAME, "true"));
    }

    // Set the value type vocabulary term
    EdmType type = property.getType();
    if (type.equals(EdmSimpleType.DATETIME)) {
      emProperty.addVocabularyTerm(new EMTerm(TermValueType.TERM_NAME, TermValueType.TIMESTAMP));
    } else if (type.equals(EdmSimpleType.TIME)) {
      emProperty.addVocabularyTerm(new EMTerm(TermValueType.TERM_NAME, TermValueType.TIME));
    } else if (type.equals(EdmSimpleType.INT64)
        || type.equals(EdmSimpleType.INT32)
        || type.equals(EdmSimpleType.INT16)) {
      emProperty.addVocabularyTerm(
          new EMTerm(TermValueType.TERM_NAME, TermValueType.INTEGER_NUMBER));
    } else if (type.equals(EdmSimpleType.SINGLE)
        || type.equals(EdmSimpleType.DOUBLE)
        || type.equals(EdmSimpleType.DECIMAL)) {
      emProperty.addVocabularyTerm(new EMTerm(TermValueType.TERM_NAME, TermValueType.NUMBER));
    } else if (type.equals(EdmSimpleType.BOOLEAN)) {
      emProperty.addVocabularyTerm(new EMTerm(TermValueType.TERM_NAME, TermValueType.BOOLEAN));
    }
    return emProperty;
  }
  public static Iterable<OProperty<?>> parseProperties(
      XMLEventReader2 reader, StartElement2 propertiesElement) {
    List<OProperty<?>> rt = new ArrayList<OProperty<?>>();

    while (reader.hasNext()) {
      XMLEvent2 event = reader.nextEvent();

      if (event.isEndElement()
          && event.asEndElement().getName().equals(propertiesElement.getName())) {
        return rt;
      }

      if (event.isStartElement()
          && event.asStartElement().getName().getNamespaceURI().equals(NS_DATASERVICES)) {

        String name = event.asStartElement().getName().getLocalPart();
        Attribute2 typeAttribute = event.asStartElement().getAttributeByName(M_TYPE);
        Attribute2 nullAttribute = event.asStartElement().getAttributeByName(M_NULL);
        boolean isNull = nullAttribute != null && "true".equals(nullAttribute.getValue());

        OProperty<?> op = null;

        String type = null;
        boolean isComplexType = false;
        if (typeAttribute != null) {
          type = typeAttribute.getValue();
          EdmType et = EdmType.get(type);
          isComplexType = !et.isSimple();
        }

        if (isComplexType) {
          op =
              OProperties.complex(
                  name,
                  type,
                  isNull
                      ? null
                      : Enumerable.create(parseProperties(reader, event.asStartElement()))
                          .toList());
        } else {
          op = OProperties.parse(name, type, isNull ? null : reader.getElementText());
        }
        rt.add(op);
      }
    }

    throw new RuntimeException();
  }
예제 #5
0
 /**
  * 指定したアノテーションを取得する.
  *
  * @param type EdmType
  * @param namespaceUri 名前空間
  * @param localName 取得対象名
  * @return namespaceUri
  */
 private NamespacedAnnotation<?> findAnnotation(
     EdmType type, String namespaceUri, String localName) {
   if (type != null) {
     for (NamespacedAnnotation<?> annotation : type.getAnnotations()) {
       if (localName.equals(annotation.getName())) {
         String uri = annotation.getNamespace().getUri();
         if ((namespaceUri == null && uri == null)
             || (namespaceUri != null && namespaceUri.equals(uri))) {
           return annotation;
         }
       }
     }
   }
   return null;
 }
예제 #6
0
 private EdmFunctionParameter.Builder parseEdmFunctionParameter(
     XMLEventReader2 reader, StartElement2 paramStartElement) {
   List<EdmAnnotation<?>> annotElements = new ArrayList<EdmAnnotation<?>>();
   Attribute2 modeAttribute = paramStartElement.getAttributeByName("Mode");
   String nullableS = getAttributeValueIfExists(paramStartElement, "Nullable");
   String maxLength = getAttributeValueIfExists(paramStartElement, "MaxLength");
   String precision = getAttributeValueIfExists(paramStartElement, "Precision");
   String scale = getAttributeValueIfExists(paramStartElement, "Scale");
   while (reader.hasNext()) {
     XMLEvent2 event = reader.nextEvent();
     if (event.isStartElement()) {
       EdmAnnotation<?> anElement = getAnnotationElements(event, reader);
       if (anElement != null) {
         annotElements.add(anElement);
       }
     }
     if (isEndElement(event, paramStartElement.getName())) {
       return EdmFunctionParameter.newBuilder()
           .setName(paramStartElement.getAttributeByName("Name").getValue())
           .setType(
               EdmType.newDeferredBuilder(
                   paramStartElement.getAttributeByName("Type").getValue(), dataServices))
           .setMode(modeAttribute != null ? Mode.valueOf(modeAttribute.getValue()) : null)
           .setNullable(nullableS == null ? null : "true".equalsIgnoreCase(nullableS))
           .setMaxLength(
               maxLength == null
                   ? null
                   : maxLength.equals("Max") ? Integer.MAX_VALUE : Integer.parseInt(maxLength))
           .setPrecision(precision == null ? null : Integer.parseInt(precision))
           .setScale(scale == null ? null : Integer.parseInt(scale))
           .setAnnotations(getAnnotations(paramStartElement))
           .setAnnotationElements(annotElements);
     }
   }
   throw new UnsupportedOperationException();
 }
예제 #7
0
  /**
   * adds the property. This property can be a navigation property too. In this case a link will be
   * added. If it's the meta data the information will be added to the entry too.
   *
   * @param entry JsonEntry
   * @param ees EdmEntitySet
   * @param name PropertyName
   * @param jsr JsonStreamReader
   * @return EdmEntitySet
   */
  protected EdmEntitySet addProperty(
      JsonEntry entry, EdmEntitySet ees, String name, JsonStreamReader jsr) {

    JsonEvent event = jsr.nextEvent();

    if (event.isEndProperty()) {
      // scalar property
      EdmProperty ep = entry.getEntityType().findProperty(name);
      if (ep == null) {
        // OpenEntityTypeの場合は、プロパティを追加する
        NamespacedAnnotation<?> openType =
            findAnnotation(ees.getType(), null, Edm.EntityType.OpenType);
        if (openType != null && openType.getValue() == "true") {
          Object propValue = null;
          try {
            propValue = event.asEndProperty().getObject();
          } catch (NumberFormatException e) {
            throw DcCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.params(name).reason(e);
          }

          // 型によって登録するEntityPropertyを変更する
          if (propValue instanceof Boolean) {
            entry.properties.add(
                JsonTypeConverter.parse(
                    name, (EdmSimpleType<?>) EdmSimpleType.BOOLEAN, propValue.toString()));
          } else if (propValue instanceof Double) {
            entry.properties.add(
                JsonTypeConverter.parse(
                    name, (EdmSimpleType<?>) EdmSimpleType.DOUBLE, propValue.toString()));
          } else {
            if (propValue == null) {
              entry.properties.add(
                  JsonTypeConverter.parse(name, (EdmSimpleType<?>) EdmSimpleType.STRING, null));
            } else {
              entry.properties.add(
                  JsonTypeConverter.parse(
                      name, (EdmSimpleType<?>) EdmSimpleType.STRING, propValue.toString()));
            }
          }
        } else {
          throw DcCoreException.OData.FIELED_INVALID_ERROR.params(
              "unknown property " + name + " for " + entry.getEntityType().getName());
        }
      } else {
        // StaticPropertyの値チェック
        String propValue = event.asEndProperty().getValue();
        if (propValue != null) {
          EdmType type = ep.getType();
          if (type.equals(EdmSimpleType.BOOLEAN) && !ODataUtils.validateBoolean(propValue)) {
            throw DcCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.params(name);
          } else if (type.equals(EdmSimpleType.STRING) && !ODataUtils.validateString(propValue)) {
            throw DcCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.params(name);
          } else if (type.equals(EdmSimpleType.DATETIME)) {
            if (!ODataUtils.validateDateTime(propValue)) {
              throw DcCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.params(name);
            }
            if (Common.SYSUTCDATETIME.equals(propValue)) {
              String crrTime = String.valueOf(getCurrentTimeMillis());
              propValue = String.format("/Date(%s)/", crrTime);
            }
          } else if (type.equals(EdmSimpleType.SINGLE) && !ODataUtils.validateSingle(propValue)) {
            throw DcCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.params(name);
          } else if (type.equals(EdmSimpleType.INT32) && !ODataUtils.validateInt32(propValue)) {
            throw DcCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.params(name);
          } else if (type.equals(EdmSimpleType.DOUBLE) && !ODataUtils.validateDouble(propValue)) {
            throw DcCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.params(name);
          }
        }
        if (ep.getType().isSimple()) {
          // シンプル型(文字列や数値など)であればプロパティに追加する
          entry.properties.add(
              JsonTypeConverter.parse(name, (EdmSimpleType<?>) ep.getType(), propValue));
        } else {
          if (propValue == null) {
            // ComplexType型で、値がnullの場合はエラーにしない
            entry.properties.add(
                JsonTypeConverter.parse(name, (EdmSimpleType<?>) EdmSimpleType.STRING, null));
          } else {
            // ComplexType型で、ComplexType型以外の値が指定された場合("aaa")はエラーとする
            throw DcCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.params(name);
          }
        }
      }
    } else if (event.isStartObject()) {
      // JSONオブジェクトの場合は値を取得する
      JsonObjectPropertyValue val = getValue(event, ees, name, jsr, entry);

      if (val.complexObject != null) {
        // ComplexTypeデータであればプロパティに追加する
        entry.properties.add(
            OProperties.complex(
                name,
                (EdmComplexType) val.complexObject.getType(),
                val.complexObject.getProperties()));
      } else {
        // ComplexTypeデータ以外はエラーとする
        throw DcCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.params(name);
      }
    } else if (event.isStartArray()) {
      // 配列オブジェクトの場合
      JsonObjectPropertyValue val = new JsonObjectPropertyValue();

      // スキーマ定義が存在してCollectionKindがNoneでなければ、配列としてパースする
      EdmProperty eprop = entry.getEntityType().findProperty(name);
      if (null != eprop && eprop.getCollectionKind() != CollectionKind.NONE) {
        val.collectionType = new EdmCollectionType(eprop.getCollectionKind(), eprop.getType());
        DcJsonCollectionFormatParser cfp =
            new DcJsonCollectionFormatParser(val.collectionType, this.metadata, name);
        val.collection = cfp.parseCollection(jsr);
      }

      // パースに成功した場合は、プロパティに追加する
      if (val.collectionType != null && val.collection != null) {
        entry.properties.add(OProperties.collection(name, val.collectionType, val.collection));
      } else {
        throw DcCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.params(name);
      }
    } else {
      throw DcCoreException.OData.INVALID_TYPE_ERROR.params(name);
    }
    return ees;
  }
예제 #8
0
 /**
  * Creates a new OData property of the given edm simple type with a null value.
  *
  * @param name the property name
  * @param fqSimpleTypeName the property edm simple type
  * @return a new OData property instance
  */
 public static OProperty<?> null_(String name, String fqSimpleTypeName) {
   return new Impl<Object>(name, EdmType.getSimple(fqSimpleTypeName), null);
 }
예제 #9
0
  @SuppressWarnings("unchecked")
  protected void writeProperty(
      XMLWriter2 writer,
      String name,
      EdmType type,
      Object value,
      boolean isDocumentElement,
      boolean writeType) {

    writer.startElement(new QName2(d, name, "d"));

    if (isDocumentElement) {
      writer.writeNamespace("m", m);
      writer.writeNamespace("d", d);
    }

    String sValue = null;

    if (!type.isSimple()) {
      if (writeType) {
        String typename = type.getFullyQualifiedTypeName();
        if (value instanceof OCollection) {
          EdmCollectionType collectionType = (EdmCollectionType) type;
          typename = "Bag(" + collectionType.getItemType().getFullyQualifiedTypeName() + ")";
        }
        writer.writeAttribute(new QName2(m, "type", "m"), typename);
      }
      // complex or collection
      if (value instanceof OCollection) {
        writeCollection(writer, name, (OCollection<? extends OObject>) value);
      } else if (value instanceof OComplexObject) {
        writeProperties(writer, ((OComplexObject) value).getProperties());
      } else {
        // deprecated form of a complex object.
        List<OProperty<?>> complexProperties = (List<OProperty<?>>) value;
        if (complexProperties != null) {
          writeProperties(writer, complexProperties);
        }
      }
    } else {
      // simple
      // write the type attribute if requested and not a string
      if (writeType && type != EdmSimpleType.STRING) {
        writer.writeAttribute(new QName2(m, "type", "m"), type.getFullyQualifiedTypeName());
      }
      // now write the value
      if (type == EdmSimpleType.INT32) {
        if (value != null) {
          sValue = value.toString();
        }
      } else if (type == EdmSimpleType.INT16) {
        if (value != null) {
          sValue = value.toString();
        }
      } else if (type == EdmSimpleType.INT64) {
        if (value != null) {
          sValue = value.toString();
        }
      } else if (type == EdmSimpleType.BOOLEAN) {
        if (value != null) {
          sValue = value.toString();
        }
      } else if (type == EdmSimpleType.BYTE) {
        if (value != null) {
          sValue = value.toString();
        }
      } else if (type == EdmSimpleType.SBYTE) {
        if (value != null) {
          sValue = value.toString();
        }
      } else if (type == EdmSimpleType.DECIMAL) {
        if (value != null) {
          sValue = ((BigDecimal) value).toPlainString();
        }
      } else if (type == EdmSimpleType.SINGLE) {
        if (value != null) {
          sValue = value.toString();
        }
      } else if (type == EdmSimpleType.DOUBLE) {
        if (value != null) {
          sValue = value.toString();
        }
      } else if (type == EdmSimpleType.STRING) {
        if (value != null) {
          sValue = value.toString();
        }
      } else if (type == EdmSimpleType.DATETIME) {
        if (value != null) sValue = InternalUtil.formatDateTimeForXml((LocalDateTime) value);
      } else if (type == EdmSimpleType.BINARY) {
        byte[] bValue = (byte[]) value;
        if (value != null) {
          sValue = Base64.encodeBase64String(bValue);
        }
      } else if (type == EdmSimpleType.GUID) {
        if (value != null) {
          sValue = value.toString();
        }
      } else if (type == EdmSimpleType.TIME) {
        if (value != null) {
          sValue = InternalUtil.formatTimeForXml((LocalTime) value);
        }
      } else if (type == EdmSimpleType.DATETIMEOFFSET) {
        // Edm.DateTimeOffset '-'? yyyy '-' mm '-' dd 'T' hh ':' mm
        // ':' ss ('.' s+)? (zzzzzz)?
        if (value != null) {
          sValue = InternalUtil.formatDateTimeOffsetForXml((DateTime) value);
        }
      } else {
        throw new UnsupportedOperationException("Implement " + type);
      }
    }

    if (value == null) {
      writer.writeAttribute(new QName2(m, "null", "m"), "true");
    } else if (sValue != null) {
      writer.writeText(sValue);
    }

    writer.endElement(name);
  }
예제 #10
0
  @SuppressWarnings("unchecked")
  protected void writeProperty(XMLWriter2 writer, OProperty<?> prop, boolean isDocumentElement) {

    String name = prop.getName();
    EdmType type = prop.getType();
    Object value = prop.getValue();

    if (isDocumentElement) writer.startElement(new QName2(name), d);
    else writer.startElement(new QName2(d, name, "d"));

    String sValue = null;

    if (!type.isSimple()) {
      writer.writeAttribute(new QName2(m, "type", "m"), type.toTypeString());
      // complex
      List<OProperty<?>> complexProperties = (List<OProperty<?>>) value;
      if (complexProperties != null) {
        writeProperties(writer, complexProperties);
      }
    } else {
      // simple
      if (type == EdmType.INT32) {
        writer.writeAttribute(new QName2(m, "type", "m"), type.toTypeString());
        if (value != null) {
          sValue = value.toString();
        }
      } else if (type == EdmType.INT16) {
        writer.writeAttribute(new QName2(m, "type", "m"), type.toTypeString());
        if (value != null) {
          sValue = value.toString();
        }
      } else if (type == EdmType.INT64) {
        writer.writeAttribute(new QName2(m, "type", "m"), type.toTypeString());
        if (value != null) {
          sValue = value.toString();
        }
      } else if (type == EdmType.BOOLEAN) {
        writer.writeAttribute(new QName2(m, "type", "m"), type.toTypeString());
        if (value != null) {
          sValue = value.toString();
        }
      } else if (type == EdmType.BYTE) {
        writer.writeAttribute(new QName2(m, "type", "m"), type.toTypeString());
        if (value != null) {
          sValue = Hex.encodeHexString(new byte[] {(Byte) value});
        }
      } else if (type == EdmType.DECIMAL) {
        writer.writeAttribute(new QName2(m, "type", "m"), type.toTypeString());
        if (value != null) {
          sValue = value.toString();
        }
      } else if (type == EdmType.SINGLE) {
        writer.writeAttribute(new QName2(m, "type", "m"), type.toTypeString());
        if (value != null) {
          sValue = value.toString();
        }
      } else if (type == EdmType.DOUBLE) {
        writer.writeAttribute(new QName2(m, "type", "m"), type.toTypeString());
        if (value != null) {
          sValue = value.toString();
        }
      } else if (type == EdmType.STRING) {
        if (value != null) {
          sValue = value.toString();
        }
      } else if (type == EdmType.DATETIME) {
        writer.writeAttribute(new QName2(m, "type", "m"), type.toTypeString());
        if (value != null) sValue = InternalUtil.formatDateTime((LocalDateTime) value);
      } else if (type == EdmType.BINARY) {
        writer.writeAttribute(new QName2(m, "type", "m"), type.toTypeString());
        byte[] bValue = (byte[]) value;
        if (value != null) {
          sValue = Base64.encodeBase64String(bValue);
        }
      } else if (type == EdmType.GUID) {
        writer.writeAttribute(new QName2(m, "type", "m"), type.toTypeString());
        if (value != null) {
          sValue = value.toString();
        }
      } else if (type == EdmType.TIME) {
        writer.writeAttribute(new QName2(m, "type", "m"), type.toTypeString());
        if (value != null) {
          sValue = InternalUtil.toString((LocalTime) value);
        }
      } else if (type == EdmType.DATETIMEOFFSET) {
        // Edm.DateTimeOffset '-'? yyyy '-' mm '-' dd 'T' hh ':' mm
        // ':' ss ('.' s+)? (zzzzzz)?
        writer.writeAttribute(new QName2(m, "type", "m"), type.toTypeString());
        if (value != null) {
          sValue = InternalUtil.toString((DateTime) value);
        }
      } else {
        throw new UnsupportedOperationException("Implement " + type);
      }
    }

    if (value == null) {
      writer.writeAttribute(new QName2(m, "null", "m"), "true");
    } else {
      writer.writeText(sValue);
    }
    writer.endElement(name);
  }
예제 #11
0
  private EdmProperty.Builder parseEdmProperty(XMLEventReader2 reader, XMLEvent2 event) {
    List<EdmAnnotation<?>> annotElements = new ArrayList<EdmAnnotation<?>>();
    StartElement2 startElement = event.asStartElement();
    String propertyName = getAttributeValueIfExists(startElement, "Name");
    String propertyType = getAttributeValueIfExists(startElement, "Type");
    String propertyNullable = getAttributeValueIfExists(startElement, "Nullable");
    String maxLength = getAttributeValueIfExists(startElement, "MaxLength");
    String unicode = getAttributeValueIfExists(startElement, "Unicode");
    String fixedLength = getAttributeValueIfExists(startElement, "FixedLength");
    String collation = getAttributeValueIfExists(startElement, "Collation");
    String collectionKindS = getAttributeValueIfExists(startElement, "CollectionKind");
    CollectionKind ckind = CollectionKind.NONE;
    if (collectionKindS != null) {
      ckind = Enum.valueOf(CollectionKind.class, collectionKindS);
    }
    String defaultValue = getAttributeValueIfExists(startElement, "DefaultValue");
    String precision = getAttributeValueIfExists(startElement, "Precision");
    String scale = getAttributeValueIfExists(startElement, "Scale");

    String storeGeneratedPattern =
        getAttributeValueIfExists(
            startElement, new QName2(NS_EDMANNOTATION, "StoreGeneratedPattern"));
    String concurrencyMode = getAttributeValueIfExists(startElement, "ConcurrencyMode");

    String mimeType = getAttributeValueIfExists(startElement, M_MIMETYPE);
    String fcTargetPath = getAttributeValueIfExists(startElement, M_FC_TARGETPATH);
    String fcContentKind = getAttributeValueIfExists(startElement, M_FC_CONTENTKIND);
    String fcKeepInContent = getAttributeValueIfExists(startElement, M_FC_KEEPINCONTENT);
    String fcEpmContentKind = getAttributeValueIfExists(startElement, M_FC_EPMCONTENTKIND);
    String fcEpmKeepInContent = getAttributeValueIfExists(startElement, M_FC_EPMKEEPINCONTENT);
    String fcNsPrefix = getAttributeValueIfExists(startElement, M_FC_NSPREFIX);
    String fcNsUri = getAttributeValueIfExists(startElement, M_FC_NSURI);

    while (reader.hasNext()) {
      XMLEvent2 event2 = reader.nextEvent();

      if (event2.isStartElement()) {
        EdmAnnotation<?> anElement = getAnnotationElements(event2, reader);
        if (anElement != null) {
          annotElements.add(anElement);
        }
      }

      if (isEndElement(event2, startElement.getName())) {
        return EdmProperty.newBuilder(propertyName)
            .setType(EdmType.newDeferredBuilder(propertyType, dataServices))
            .setNullable("true".equalsIgnoreCase(propertyNullable))
            .setMaxLength(
                maxLength == null
                    ? null
                    : maxLength.equals("Max") ? Integer.MAX_VALUE : Integer.parseInt(maxLength))
            .setUnicode(unicode == null ? null : "true".equalsIgnoreCase(unicode))
            .setFixedLength(fixedLength == null ? null : "true".equalsIgnoreCase(fixedLength))
            .setCollation(collation)
            .setConcurrencyMode(concurrencyMode)
            .setStoreGeneratedPattern(storeGeneratedPattern)
            .setMimeType(mimeType)
            .setFcTargetPath(fcTargetPath)
            .setFcContentKind(fcContentKind)
            .setFcKeepInContent(fcKeepInContent)
            .setFcEpmContentKind(fcEpmContentKind)
            .setFcEpmKeepInContent(fcEpmKeepInContent)
            .setFcNsPrefix(fcNsPrefix)
            .setFcNsUri(fcNsUri)
            .setCollectionKind(ckind)
            .setDefaultValue(defaultValue)
            .setPrecision(precision == null ? null : Integer.parseInt(precision))
            .setScale(scale == null ? null : Integer.parseInt(scale))
            .setAnnotations(getAnnotations(startElement))
            .setAnnotationElements(annotElements.isEmpty() ? null : annotElements);
      }
    }
    throw new UnsupportedOperationException();
  }
예제 #12
0
  @Override
  public BaseResponse executeCall(String sql, List<SQLParam> parameters, EdmType returnType) {
    ConnectionImpl connection = null;
    try {
      LogManager.logDetail(LogConstants.CTX_ODATA, "Teiid-Query:", sql); // $NON-NLS-1$
      connection = getConnection();
      final CallableStatementImpl stmt = connection.prepareCall(sql);

      int i = 1;
      if (returnType != null && returnType.isSimple()) {
        stmt.registerOutParameter(
            i++,
            JDBCSQLTypeInfo.getSQLType(
                ODataTypeManager.teiidType(returnType.getFullyQualifiedTypeName())));
      }

      if (!parameters.isEmpty()) {
        for (SQLParam param : parameters) {
          stmt.setObject(i++, param.value, param.sqlType);
        }
      }

      boolean results = stmt.execute();
      if (results) {
        final ResultSet rs = stmt.getResultSet();
        OCollection.Builder resultRows =
            OCollections.newBuilder(
                (EdmComplexType) ((EdmCollectionType) returnType).getItemType());
        while (rs.next()) {
          int idx = 1;
          List<OProperty<?>> row = new ArrayList<OProperty<?>>();
          Iterator<EdmProperty> props =
              ((EdmComplexType) ((EdmCollectionType) returnType).getItemType())
                  .getProperties()
                  .iterator();
          while (props.hasNext()) {
            EdmProperty prop = props.next();
            row.add(
                buildPropery(
                    prop.getName(),
                    prop.getType(),
                    rs.getObject(idx++),
                    invalidCharacterReplacement));
          }
          OComplexObject erow =
              OComplexObjects.create(
                  (EdmComplexType) ((EdmCollectionType) returnType).getItemType(), row);
          resultRows.add(erow);
        }
        String collectionName = returnType.getFullyQualifiedTypeName();
        collectionName = collectionName.replace("(", "_"); // $NON-NLS-1$ //$NON-NLS-2$
        collectionName = collectionName.replace(")", "_"); // $NON-NLS-1$ //$NON-NLS-2$
        return Responses.collection(resultRows.build(), null, null, null, collectionName);
      }

      if (returnType != null) {
        Object result = stmt.getObject(1);
        OProperty prop =
            buildPropery("return", returnType, result, invalidCharacterReplacement); // $NON-NLS-1$
        return Responses.property(prop);
      }
      return null;
    } catch (Exception e) {
      throw new ServerErrorException(e.getMessage(), e);
    } finally {
      if (connection != null) {
        try {
          connection.close();
        } catch (SQLException e) {
        }
      }
    }
  }