Class DataUtils

java.lang.Object
com.sap.cds.util.DataUtils

public class DataUtils extends Object
  • Method Details

    • create

      public static DataUtils create(Supplier<SessionContext> session, int timestampPrecision)
    • isDeep

      public static boolean isDeep(CdsStructuredType type, Collection<Map<String,Object>> entries)
    • hasNonKeyValues

      public static boolean hasNonKeyValues(CdsStructuredType type, Map<String,Object> data)
    • uniformData

      public static boolean uniformData(CdsStructuredType type, Collection<Map<String,Object>> entries)
    • prepareForInsert

      public void prepareForInsert(CdsStructuredType struct, List<? extends Map<String,Object>> entries)
    • prepareForUpdate

      public void prepareForUpdate(CdsStructuredType struct, List<? extends Map<String,Object>> entries)
    • processOnInsert

      public void processOnInsert(CdsStructuredType struct, Iterable<? extends Map<String,Object>> data)
    • processOnUpdate

      public void processOnUpdate(CdsStructuredType struct, Iterable<? extends Map<String,Object>> data, boolean deep)
    • resolvePaths

      public static void resolvePaths(CdsEntity entity, List<? extends Map<String,Object>> entries)
    • hasDefaultValue

      public static boolean hasDefaultValue(CdsElement element, CdsType type)
    • defaultValue

      public Object defaultValue(CdsElement e)
    • resolvePathAndAdd

      public static void resolvePathAndAdd(Map<String,Object> map, String key, Object value)
    • putPath

      public static Object putPath(Map<String,Object> map, String key, Object value)
    • putPath

      public static Object putPath(Map<String,Object> map, String key, Object value, boolean createMaps)
    • createPath

      public static void createPath(Map<String,Object> map, String path, boolean notNull)
    • dateTimeValues

      public static List<Instant> dateTimeValues(List<Instant> instants)
    • timestampValues

      public static List<Instant> timestampValues(List<Instant> instants, int precision)
    • generateUuidKeys

      public static boolean generateUuidKeys(CdsStructuredType struct, Map<String,Object> data)
    • hasManagedUuidValue

      public static boolean hasManagedUuidValue(CdsElement element)
    • normalizedUuidKeys

      public static void normalizedUuidKeys(CdsStructuredType type, Iterable<? extends Map<String,Object>> entries)
    • copyMap

      public static Map<String,Object> copyMap(Map<String,?> original)
    • copyGenericList

      public static List<CdsData> copyGenericList(List original)
    • removeVirtualElements

      public void removeVirtualElements(CdsStructuredType struct, List<? extends Map<String,Object>> data)
    • removeOpenTypeElements

      public void removeOpenTypeElements(CdsStructuredType struct, Iterable<? extends Map<String,Object>> data)
    • merge

      public static void merge(List<? extends Map<String,Object>> source, List<? extends Map<String,Object>> target, String expRefName, Map<String,String> mapping, String fkPrefix, boolean addCount)
    • addCounts

      public static void addCounts(List<? extends Map<String,Object>> rows, List<? extends Map<String,Object>> counts, String expRefName, Map<String,String> mapping)
    • countName

      public static String countName(String name)
    • deepMapKeys

      public static Stream<String> deepMapKeys(Map<String,?> map)
    • keyValues

      public static Map<String,Object> keyValues(CdsEntity entity, Map<String,Object> data)
      Extracts the key values for the given entity from the data map. If data does not contain a value for a key, it is mapped to null. For association keys, fk values can be extracted from nested maps in data.
      Parameters:
      entity - the entity
      data - the data map
      Returns:
      the key values of the entity
    • getOrDefault

      public static <T> T getOrDefault(Map<String,Object> data, String path, T defaultValue)
      Returns the value to which the specified key is mapped. The key can be a path separated by '.' to extract values from nested maps. If no value is found, defaultValue is returned.
      Type Parameters:
      T - the type to which the value is casted
      Parameters:
      data - the data map
      path - the path or key whose associated value is to be returned
      defaultValue - the default mapping of the key
      Returns:
      the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key
    • getPathOrDefault

      public static <T> T getPathOrDefault(Map<String,Object> data, String path, T defaultValue)
      Returns the value to which the specified path is mapped. If no value is found, defaultValue is returned.
      Type Parameters:
      T - the type to which the value is casted
      Parameters:
      data - the data map
      path - the path with dot separator whose associated value is to be returned
      defaultValue - the default mapping of the key
      Returns:
      the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key
    • getPathOrDefault

      public static <T> T getPathOrDefault(T defaultValue, Map<String,Object> d, String[] segment)
    • getPath

      public static <T> T getPath(Map<String,Object> d, String[] segment)
    • removePath

      public static <T> T removePath(Map<String,Object> data, String path, boolean removeEmptyMaps)
    • containsKey

      public static boolean containsKey(Map<String,Object> data, String path)
      Returns true if the specified key is present in the map. The key can be a path separated by '.' to check keys in nested maps.
      Parameters:
      data - the data map
      path - the path or key to be checked
      Returns:
      true if the specified key is present
    • containsKey

      public static boolean containsKey(Map<String,Object> data, String path, boolean propagateNull)
      Returns true if the specified key is present in the map. The key can be a path separated by '.' to check keys in nested maps.
      Parameters:
      data - the data map
      path - the path or key to be checked
      propagateNull - true, if explicit null values should be considered propagating, meaning all values from that key-level on are considered explicitly set to null
      Returns:
      true if the specified key is present
    • isFkUpdate

      public static boolean isFkUpdate(CdsElement assoc, Map<String,Object> data, SessionContext session)