Class VdmObject<ObjectT>

java.lang.Object
com.sap.cloud.sdk.datamodel.odatav4.core.VdmObject<ObjectT>
Type Parameters:
ObjectT - The type of the implementing object.
Direct Known Subclasses:
VdmComplex, VdmEntity

public abstract class VdmObject<ObjectT> extends Object
Superclass of all entities which contains common elements such as a generic representation of custom fields.
  • Field Details

    • ODATA_TYPE_ANNOTATIONS

      public static final String[] ODATA_TYPE_ANNOTATIONS
      The OData V4 JSON key to access an entity EDM type definition.
    • ODATA_VERSION_ANNOTATIONS

      public static final String[] ODATA_VERSION_ANNOTATIONS
      The OData V4 JSON key to access an entity version identifier.
    • changedOriginalFields

      @Nonnull protected final transient Map<String,Object> changedOriginalFields
      A mapping of the OData field name to the original value.

      This should be updated via rememberChangedField(String, Object) on every set call of a property.

  • Constructor Details

    • VdmObject

      public VdmObject()
  • Method Details

    • getCustomFieldNames

      @Nonnull public Set<String> getCustomFieldNames()
      Returns the names of the custom fields of this object.
      Returns:
      The names of the custom fields of this object.
    • getCustomFields

      @Nonnull public Map<String,Object> getCustomFields()
      Returns the names and values of a custom field.
      Returns:
      All of the names & values of custom fields as a map.
    • setCustomField

      public void setCustomField(@Nonnull String customFieldName, @Nullable Object value)
      Sets the value of a single custom field.
      Parameters:
      customFieldName - Name of the custom field.
      value - Value of the custom field.
    • setCustomField

      public <FieldT> void setCustomField(@Nonnull SimpleProperty<ObjectT> customField, @Nullable FieldT value)
      Sets the value of a single custom field. If the EntityField passed as parameter holds a TypeConverter, the value will be converted before it's stored.
      Type Parameters:
      FieldT - The type of the custom field to set.
      Parameters:
      customField - Name of the custom field, represented as an EntityField object.
      value - Value of the custom field.
    • hasCustomField

      public boolean hasCustomField(@Nonnull String customFieldName)
      Checks whether this object contains a custom field with the given name.
      Parameters:
      customFieldName - Name of the custom field to check for
      Returns:
      true if this entity has a custom field with the given name, false otherwise.
    • hasCustomField

      public boolean hasCustomField(@Nonnull SimpleProperty<ObjectT> customField)
      Checks whether this object contains a value for the given custom field.
      Parameters:
      customField - Custom field to check for, represented as an EntityField object.
      Returns:
      true if this object has a custom field with the name of the given field, false otherwise.
    • getCustomField

      @Nullable public <FieldT> FieldT getCustomField(@Nonnull String customFieldName) throws NoSuchElementException
      This method allows for retrieval of custom fields that are added to the underlying OData services.
      Type Parameters:
      FieldT - The type of the returned field.
      Parameters:
      customFieldName - Name of the field returned by the underlying OData service.
      Returns:
      The value of the custom field. Actual type will depend on the type configured in the underlying OData service.
      Throws:
      NoSuchElementException - if no field with the given name could be found.
    • getCustomField

      @Nullable public <FieldT> FieldT getCustomField(@Nonnull SimpleProperty<ObjectT> customField) throws NoSuchElementException
      This method allows for retrieval of custom fields that are added to the underlying OData services. If the EntityField passed as parameter holds a TypeConverter, the value will be converted before it's returned.
      Type Parameters:
      FieldT - The type of the returned field.
      Parameters:
      customField - Field returned by the underlying OData service.
      Returns:
      The value of the custom field. Actual type will depend on the type configured in the underlying OData service.
      Throws:
      NoSuchElementException - if no field with the given name could be found.
    • getAnnotationProperties

      @Nonnull public Map<String,String> getAnnotationProperties()
      Returns the annotation properties.
      Returns:
      List of OData annotation properties.
    • getOdataType

      @Nonnull public abstract String getOdataType()
      Returns the EDMX type of this entity.
      Returns:
      The EDMX type of this entity.
    • getType

      @Nonnull public abstract Class<ObjectT> getType()
      Returns the class of this object.
      Returns:
      The class of this object.
    • getKey

      @Nonnull protected ODataEntityKey getKey()
      Returns the compound key of this object.
      Returns:
      The compound key of this object.
    • fromMap

      protected void fromMap(Map<String,Object> values)
      Read entity data from generic map.
      Parameters:
      values - The key-value map.
    • toMapOfCustomFields

      @Nonnull protected Map<String,Object> toMapOfCustomFields()
      Get the custom fields as value map.
      Returns:
      The custom fields.
    • getSetOfCustomFields

      @Nonnull protected Set<String> getSetOfCustomFields()
      Get the custom field names.
      Returns:
      The custom field names.
    • toMapOfFields

      @Nonnull protected Map<String,Object> toMapOfFields()
      Get all fields as map.
      Returns:
      The fields as map.
    • getSetOfFields

      @Nonnull protected Set<String> getSetOfFields()
      Get the field names.
      Returns:
      The field names.
    • toMapOfNavigationProperties

      @Nonnull protected Map<String,Object> toMapOfNavigationProperties()
      Get navigation properties as map.
      Returns:
      The navigation properties.
    • getSetOfNavigationProperties

      @Nonnull protected Set<String> getSetOfNavigationProperties()
      Get navigation property names as set.
      Returns:
      The navigation property names.
    • toMap

      @Nonnull protected Map<String,Object> toMap()
      Translate the entity data to key-value map.
      Returns:
      The map representation of the entity.
    • getChangedFields

      @Nonnull public Map<String,Object> getChangedFields()
      Returns map of all fields which have been changed on this entity along with their updated values.
      Returns:
      Map containing all changed fields with their current value.
    • rememberChangedField

      protected void rememberChangedField(@Nonnull String fieldName, @Nullable Object valueBeforeChange)
      Remembers the original value of a changed field.
      Parameters:
      fieldName - The name of the field that is changed.
      valueBeforeChange - The original value before the change.
    • resetChangedFields

      public void resetChangedFields()
      Resets the map of all fields which have been changed on this entity.

      After calling this method, no field is considered changed, until you change the value of fields on this entity afterwards.

    • toString

      @Nonnull public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(@Nullable Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object