Java Code Examples for org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind#Int64

The following examples show how to use org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind#Int64 . 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: EdmEnumTypeImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
public EdmEnumTypeImpl(final Edm edm, final FullQualifiedName enumName, final CsdlEnumType enumType) {
  super(edm, enumName, EdmTypeKind.ENUM, enumType);

  if (enumType.getUnderlyingType() == null) {
    underlyingType = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32);
  } else {
    final EdmPrimitiveTypeKind underlyingTypeKind = EdmPrimitiveTypeKind.valueOfFQN(enumType.getUnderlyingType());
    if (underlyingTypeKind == EdmPrimitiveTypeKind.Byte
        || underlyingTypeKind == EdmPrimitiveTypeKind.SByte
        || underlyingTypeKind == EdmPrimitiveTypeKind.Int16
        || underlyingTypeKind == EdmPrimitiveTypeKind.Int32
        || underlyingTypeKind == EdmPrimitiveTypeKind.Int64) {
      underlyingType = EdmPrimitiveTypeFactory.getInstance(underlyingTypeKind);
    } else {
      throw new EdmException("Not allowed as underlying type: " + underlyingTypeKind);
    }
  }

  this.enumType = enumType;
  this.enumName = enumName;
}
 
Example 2
Source File: ExpressionParser.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private Expression parsePrimitive(final TokenKind primitiveTokenKind) throws UriParserException {
  final String primitiveValueLiteral = tokenizer.getText();
  if (primitiveTokenKind == TokenKind.EnumValue) {
    return createEnumExpression(primitiveValueLiteral);
  } else {
    EdmPrimitiveTypeKind primitiveTypeKind = ParserHelper.tokenToPrimitiveType.get(primitiveTokenKind);
    if (primitiveTypeKind == EdmPrimitiveTypeKind.Int64) {
      primitiveTypeKind = determineIntegerType(primitiveValueLiteral);
    }

    final EdmPrimitiveType type = primitiveTypeKind == null ?
        // Null handling
        null :
        odata.createPrimitiveTypeInstance(primitiveTypeKind);
    return new LiteralImpl(primitiveValueLiteral, type);
  }
}
 
Example 3
Source File: ExpressionParser.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private EdmPrimitiveTypeKind determineIntegerType(final String intValueAsString) throws UriParserSyntaxException {
  EdmPrimitiveTypeKind typeKind = null;
  try {
    final long value = Long.parseLong(intValueAsString);
    if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) {
      typeKind = EdmPrimitiveTypeKind.SByte;
    } else if (value >= 0 && value <= 255) {
      typeKind = EdmPrimitiveTypeKind.Byte;
    } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) {
      typeKind = EdmPrimitiveTypeKind.Int16;
    } else if (value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE) {
      typeKind = EdmPrimitiveTypeKind.Int32;
    } else {
      typeKind = EdmPrimitiveTypeKind.Int64;
    }
  } catch (final NumberFormatException e) {
    // The number cannot be formatted wrongly because the tokenizer already checked the format
    // but it is too large for Long and therefore too large for Edm.Int64.
    typeKind = EdmPrimitiveTypeKind.Decimal;
  }
  return typeKind;
}
 
Example 4
Source File: EdmTypeInfo.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public static EdmPrimitiveTypeKind determineTypeKind(final Object value) {
  if (value == null) {
    return null;
  } else if (value instanceof Boolean) {
    return EdmPrimitiveTypeKind.Boolean;
  } else if (value instanceof String) {
    return EdmPrimitiveTypeKind.String;
  } else if (value instanceof UUID) {
    return EdmPrimitiveTypeKind.Guid;
  } else if (value instanceof Long || value instanceof BigInteger) {
    return EdmPrimitiveTypeKind.Int64;
  } else if (value instanceof Integer) {
    return EdmPrimitiveTypeKind.Int32;
  } else if (value instanceof Short) {
    return EdmPrimitiveTypeKind.Int16;
  } else if (value instanceof Byte) {
    return EdmPrimitiveTypeKind.SByte;
  } else if (value instanceof BigDecimal) {
    return EdmPrimitiveTypeKind.Decimal;
  } else if (value instanceof Double) {
    return EdmPrimitiveTypeKind.Double;
  } else if (value instanceof Float) {
    return EdmPrimitiveTypeKind.Single;
  } else if (value instanceof Calendar || value instanceof Date || value instanceof java.sql.Timestamp) {
    return EdmPrimitiveTypeKind.DateTimeOffset;
  } else if (value instanceof java.sql.Date) {
    return EdmPrimitiveTypeKind.Date;
  } else if (value instanceof java.sql.Time) {
    return EdmPrimitiveTypeKind.TimeOfDay;
  } else if (value instanceof byte[] || value instanceof Byte[]) {
    return EdmPrimitiveTypeKind.Binary;
  }
  return null;
}
 
Example 5
Source File: JsonSerializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
protected void primitiveValue(final JsonGenerator jgen, final EdmTypeInfo typeInfo, final Object value)
    throws IOException, EdmPrimitiveTypeException {

  final EdmPrimitiveTypeKind kind = typeInfo == null ?
      EdmTypeInfo.determineTypeKind(value) :
      typeInfo.getPrimitiveTypeKind();

  if (value == null) {
    jgen.writeNull();
  } else if (kind == EdmPrimitiveTypeKind.Boolean) {
    jgen.writeBoolean((Boolean) value);
  } else if (kind == null) {
    if (serverMode) {
      throw new EdmPrimitiveTypeException("The primitive type could not be determined.");
    } else {
      jgen.writeString(value.toString()); // This might not be valid OData.
    }
  } else {
    // TODO: add facets
    final String serialized = EdmPrimitiveTypeFactory.getInstance(kind)
        .valueToString(value, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null);

    if (isIEEE754Compatible && (kind == EdmPrimitiveTypeKind.Int64 || kind == EdmPrimitiveTypeKind.Decimal)
        || !NUMBER_TYPES.contains(kind)) {
      jgen.writeString(serialized);
    } else {
      jgen.writeNumber(serialized);
    }
  }
}
 
Example 6
Source File: JsonDeserializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private EdmPrimitiveTypeKind guessPrimitiveTypeKind(final JsonNode node) {
  return node.isShort() ? EdmPrimitiveTypeKind.Int16 :
    node.isInt() ? EdmPrimitiveTypeKind.Int32 :
      node.isLong() ? EdmPrimitiveTypeKind.Int64 :
        node.isBoolean() ? EdmPrimitiveTypeKind.Boolean :
          node.isFloat() ? EdmPrimitiveTypeKind.Single :
            node.isDouble() ? EdmPrimitiveTypeKind.Double :
              node.isBigDecimal() ? EdmPrimitiveTypeKind.Decimal :
                EdmPrimitiveTypeKind.String;
}
 
Example 7
Source File: ODataJsonDeserializer.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
private boolean matchIEEENumberCase(final JsonNode node, final EdmPrimitiveTypeKind primKind) {
  return (isIEEE754Compatible ? node.isTextual() : node.isNumber())
      && (primKind == EdmPrimitiveTypeKind.Int64 || primKind == EdmPrimitiveTypeKind.Decimal);
}