Interface EdmPrimitiveType
- All Known Subinterfaces:
EdmEnumType
,EdmTypeDefinition
EdmPrimitiveType is a primitive type as defined in the Entity Data Model (EDM).
There are methods to convert EDM primitive types from and to Java objects, respectively. The following Java types are supported:
There are methods to convert EDM primitive types from and to Java objects, respectively. The following Java types are supported:
EDM primitive type | Java types |
---|---|
Binary | byte[], Byte [] |
Boolean | Boolean |
Byte | Short , Byte , Integer , Long , BigInteger
|
Date | Calendar , Date , Timestamp ,
Time , Long |
DateTimeOffset | Timestamp , Calendar , Date ,
Time , Long |
Decimal | BigDecimal , BigInteger , Double , Float ,
Byte , Short , Integer , Long |
Double | Double , Float , BigDecimal , Byte , Short ,
Integer , Long |
Duration | BigDecimal , BigInteger , Double , Float ,
Byte , Short , Integer , Long |
Guid | UUID |
Int16 | Short , Byte , Integer , Long , BigInteger
|
Int32 | Integer , Byte , Short , Long , BigInteger
|
Int64 | Long , Byte , Short , Integer , BigInteger
|
SByte | Byte , Short , Integer , Long , BigInteger
|
Single | Float , Double , BigDecimal , Byte , Short ,
Integer , Long |
String | String |
TimeOfDay | Calendar , Date , Timestamp ,
Time , Long |
The first Java type is the default type for the respective EDM primitive type.
For all EDM primitive types, the Nullable
facet is taken into account. For Binary
and
String
, MaxLength
is also applicable. For String
, the facet
Unicode
is considered additionally. The EDM primitive types DateTimeOffset
,
Decimal
, Duration
, and TimeOfDay
can have a Precision
facet.
Additionally, Decimal
can have the facet Scale
.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionfromUriLiteral
(String literal) Converts URI literal representation to default literal representation.Class<?>
Returns the default Java type for this EDM primitive type as described in the documentation ofEdmPrimitiveType
.boolean
isCompatible
(EdmPrimitiveType primitiveType) Checks type compatibility.toUriLiteral
(String literal) Converts default literal representation to URI literal representation.boolean
validate
(String value, Boolean isNullable, Integer maxLength, Integer precision, Integer scale, Boolean isUnicode) Validates literal value.default boolean
validateDecimals
(String value, Boolean isNullable, Integer maxLength, Integer precision, String scale, Boolean isUnicode) Validates literal value for Decimal values in V4.01<T> T
valueOfString
(String value, Boolean isNullable, Integer maxLength, Integer precision, Integer scale, Boolean isUnicode, Class<T> returnType) Converts literal representation of value to system data type.valueToString
(Object value, Boolean isNullable, Integer maxLength, Integer precision, Integer scale, Boolean isUnicode) Converts system data type to literal representation of value.Methods inherited from interface org.apache.olingo.commons.api.edm.EdmType
getFullQualifiedName, getKind, getNamespace
-
Field Details
-
EDM_NAMESPACE
- See Also:
-
-
Method Details
-
isCompatible
Checks type compatibility.- Parameters:
primitiveType
- theEdmPrimitiveType
to be tested for compatibility- Returns:
true
if the provided type is compatible to this type
-
getDefaultType
Class<?> getDefaultType()Returns the default Java type for this EDM primitive type as described in the documentation ofEdmPrimitiveType
.- Returns:
- the default Java type
-
validate
boolean validate(String value, Boolean isNullable, Integer maxLength, Integer precision, Integer scale, Boolean isUnicode) Validates literal value.- Parameters:
value
- the literal valueisNullable
- whether thenull
value is allowedmaxLength
- the maximum lengthprecision
- the precisionscale
- the scaleisUnicode
- whether non-ASCII characters are allowed (relevant only for Edm.String)- Returns:
true
if the validation is successful
-
valueOfString
<T> T valueOfString(String value, Boolean isNullable, Integer maxLength, Integer precision, Integer scale, Boolean isUnicode, Class<T> returnType) throws EdmPrimitiveTypeException Converts literal representation of value to system data type.- Parameters:
value
- the literal representation of valueisNullable
- whether thenull
value is allowedmaxLength
- the maximum lengthprecision
- the precisionscale
- the scaleisUnicode
- whether non-ASCII characters are allowed (relevant only for Edm.String)returnType
- the class of the returned value; it must be one of the list in the documentation ofEdmPrimitiveType
- Returns:
- the value as an instance of the class the parameter
returnType
indicates - Throws:
EdmPrimitiveTypeException
-
valueToString
String valueToString(Object value, Boolean isNullable, Integer maxLength, Integer precision, Integer scale, Boolean isUnicode) throws EdmPrimitiveTypeException Converts system data type to literal representation of value.Returns
null
if value isnull
andnull
is an allowed value.- Parameters:
value
- the Java value as Object; its type must be one of the list in the documentation ofEdmPrimitiveType
isNullable
- whether thenull
value is allowedmaxLength
- the maximum lengthprecision
- the precisionscale
- the scaleisUnicode
- whether non-ASCII characters are allowed (relevant only for Edm.String)- Returns:
- literal representation as String
- Throws:
EdmPrimitiveTypeException
-
toUriLiteral
Converts default literal representation to URI literal representation.Returns
null
if the literal isnull
. Does not perform any validation.- Parameters:
literal
- the literal in default representation- Returns:
- URI literal representation as String
-
fromUriLiteral
Converts URI literal representation to default literal representation.Returns
null
if the literal isnull
. Checks the presence of a required prefix and of required surrounding quotation marks but does not perform any further validation.- Parameters:
literal
- the literal in URI representation- Returns:
- default literal representation as String
- Throws:
EdmPrimitiveTypeException
- if a required prefix or required surrounding quotation marks are missing
-
validateDecimals
default boolean validateDecimals(String value, Boolean isNullable, Integer maxLength, Integer precision, String scale, Boolean isUnicode) Validates literal value for Decimal values in V4.01- Parameters:
value
- the literal valueisNullable
- whether thenull
value is allowedmaxLength
- the maximum lengthprecision
- the precisionscale
- the scale (could be variable or floating)isUnicode
- whether non-ASCII characters are allowed (relevant only for Edm.String)- Returns:
true
if the validation is successful
-