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

The following examples show how to use org.apache.olingo.odata2.api.edm.provider.Facets#setMaxLength() . 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: AnnotationEdmProvider.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private Facets createFacets(final EdmFacets facets, final EdmConcurrencyControl concurrencyControl) {
  Facets resultFacets = new Facets().setNullable(facets.nullable());
  if(facets.maxLength() > -1) {
    resultFacets.setMaxLength(facets.maxLength());
  }
  if(facets.precision() > -1) {
    resultFacets.setPrecision(facets.precision());
  }
  if(facets.scale() > -1) {
    resultFacets.setScale(facets.scale());
  }
  if (concurrencyControl != null) {
    resultFacets.setConcurrencyMode(EdmConcurrencyMode.Fixed);
  }
  return resultFacets;
}
 
Example 2
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 3
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;
  }
}