Java Code Examples for org.apache.olingo.odata2.api.edm.provider.Facets#setNullable()

The following examples show how to use org.apache.olingo.odata2.api.edm.provider.Facets#setNullable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JPAEdmKey.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
public void normalizeComplexKey(final ComplexType complexType, final List<PropertyRef> propertyRefList) {
  for (Property property : complexType.getProperties()) {
    try {

      SimpleProperty simpleProperty = (SimpleProperty) property;
      Facets facets = (Facets) simpleProperty.getFacets();
      if (facets == null) {
        simpleProperty.setFacets(new Facets().setNullable(false));
      } else {
        facets.setNullable(false);
      }
      PropertyRef propertyRef = new PropertyRef();
      propertyRef.setName(simpleProperty.getName());
      propertyRefList.add(propertyRef);

    } catch (ClassCastException e) {
      ComplexProperty complexProperty = (ComplexProperty) property;
      normalizeComplexKey(complexTypeView.searchEdmComplexType(complexProperty.getType()), propertyRefList);
    }

  }
}
 
Example 2
Source File: JPAEdmProperty.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private SimpleProperty buildSimpleProperty(final Attribute<?, ?> jpaAttribute, final SimpleProperty simpleProperty,
    final JoinColumn joinColumn)
    throws ODataJPAModelException, ODataJPARuntimeException {

  boolean isForeignKey = joinColumn != null;
  JPAEdmNameBuilder.build(JPAEdmProperty.this, isBuildModeComplexType, skipDefaultNaming, isForeignKey);
  EdmSimpleTypeKind simpleTypeKind = JPATypeConverter
      .convertToEdmSimpleType(jpaAttribute
          .getJavaType(), jpaAttribute);
  simpleProperty.setType(simpleTypeKind);
  Facets facets = JPAEdmFacets.createAndSet(jpaAttribute, simpleProperty);
  if(isForeignKey) {
    facets.setNullable(joinColumn.nullable());
  }

  return simpleProperty;

}
 
Example 3
Source File: JPAEdmFunctionImport.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private void buildEdmParameter(final FunctionImport functionImport, final Method method)
    throws ODataJPAModelException {
  Annotation[][] annotations = method.getParameterAnnotations();
  Class<?>[] parameterTypes = method.getParameterTypes();
  List<FunctionImportParameter> funcImpList = new ArrayList<FunctionImportParameter>();
  JPAEdmMapping mapping = null;
  int j = 0;
  for (Annotation[] annotationArr : annotations) {
    Class<?> parameterType = parameterTypes[j++];

    for (Annotation element : annotationArr) {
      if (element instanceof EdmFunctionImportParameter) {
        EdmFunctionImportParameter annotation = (EdmFunctionImportParameter) element;
        FunctionImportParameter functionImportParameter = new FunctionImportParameter();
        if ("".equals(annotation.name())) {
          throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_PARAM_NAME_EXP.addContent(method
              .getDeclaringClass().getName(), method.getName()), null);
        } else {
          functionImportParameter.setName(annotation.name());
        }

        functionImportParameter.setType(JPATypeConverter.convertToEdmSimpleType(parameterType, null));

        Facets facets = new Facets();
        if (annotation.facets().maxLength() > 0) {
          facets.setMaxLength(annotation.facets().maxLength());
        }
        if (annotation.facets().nullable() == false) {
          facets.setNullable(false);
        } else {
          facets.setNullable(true);
        }

        if (annotation.facets().precision() > 0) {
          facets.setPrecision(annotation.facets().precision());
        }
        if (annotation.facets().scale() >= 0) {
          facets.setScale(annotation.facets().scale());
        }

        functionImportParameter.setFacets(facets);
        mapping = new JPAEdmMappingImpl();
        mapping.setJPAType(parameterType);
        functionImportParameter.setMapping((Mapping) mapping);
        funcImpList.add(functionImportParameter);
      }
    }
  }
  if (!funcImpList.isEmpty()) {
    functionImport.setParameters(funcImpList);
  }
}
 
Example 4
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private Facets readFacets(final XMLStreamReader reader) throws XMLStreamException {
  String isNullable = reader.getAttributeValue(null, XmlMetadataConstants.EDM_PROPERTY_NULLABLE);
  String maxLength = reader.getAttributeValue(null, XmlMetadataConstants.EDM_PROPERTY_MAX_LENGTH);
  String precision = reader.getAttributeValue(null, XmlMetadataConstants.EDM_PROPERTY_PRECISION);
  String scale = reader.getAttributeValue(null, XmlMetadataConstants.EDM_PROPERTY_SCALE);
  String isFixedLength = reader.getAttributeValue(null, XmlMetadataConstants.EDM_PROPERTY_FIXED_LENGTH);
  String isUnicode = reader.getAttributeValue(null, XmlMetadataConstants.EDM_PROPERTY_UNICODE);
  String concurrencyMode = reader.getAttributeValue(null, XmlMetadataConstants.EDM_PROPERTY_CONCURRENCY_MODE);
  String defaultValue = reader.getAttributeValue(null, XmlMetadataConstants.EDM_PROPERTY_DEFAULT_VALUE);
  String collation = reader.getAttributeValue(null, XmlMetadataConstants.EDM_PROPERTY_COLLATION);
  if (isNullable != null || maxLength != null || precision != null || scale != null || isFixedLength != null
      || isUnicode != null || concurrencyMode != null || defaultValue != null || collation != null) {
    Facets facets = new Facets();
    if (isNullable != null) {
      facets.setNullable("true".equalsIgnoreCase(isNullable));
    }
    if (maxLength != null) {
      if (XmlMetadataConstants.EDM_PROPERTY_MAX_LENGTH_MAX_VALUE_FIRST_UPPERCASE.equals(maxLength)
          || XmlMetadataConstants.EDM_PROPERTY_MAX_LENGTH_MAX_VALUE_LOWERCASE.equals(maxLength)) {
        facets.setMaxLength(Integer.MAX_VALUE);
      } else {
        facets.setMaxLength(Integer.parseInt(maxLength));
      }
    }
    if (precision != null) {
      facets.setPrecision(Integer.parseInt(precision));
    }
    if (scale != null) {
      facets.setScale(Integer.parseInt(scale));
    }
    if (isFixedLength != null) {
      facets.setFixedLength("true".equalsIgnoreCase(isFixedLength));
    }
    if (isUnicode != null) {
      facets.setUnicode("true".equalsIgnoreCase(isUnicode));
    }
    for (int i = 0; i < EdmConcurrencyMode.values().length; i++) {
      if (EdmConcurrencyMode.values()[i].name().equalsIgnoreCase(concurrencyMode)) {
        facets.setConcurrencyMode(EdmConcurrencyMode.values()[i]);
      }
    }
    facets.setDefaultValue(defaultValue);
    facets.setCollation(collation);
    return facets;
  } else {
    return null;
  }
}