Class ModelUtils


  • public class ModelUtils
    extends Object
    Utility methods.
    Author:
    Guillaume Le Cousin
    • Method Detail

      • getFieldValue

        public static Object getFieldValue​(@NonNull
                                           Object instance,
                                           @NonNull
                                           Field field)
      • setFieldValue

        public static void setFieldValue​(@NonNull
                                         Object instance,
                                         @NonNull
                                         Field field,
                                         @Nullable
                                         Object value)
      • setReverseLink

        public static void setReverseLink​(Object instance,
                                          Object linkedInstance,
                                          org.springframework.data.relational.core.mapping.RelationalPersistentProperty linkedProperty)
        Set the foreign table field on the given instance to the given linkedInstance.
        Parameters:
        instance - entity having the foreign table field
        linkedInstance - entity having the foreign key
        linkedProperty - foreign key property
      • getAllFields

        public static List<Field> getAllFields​(Class<?> cl)
        Retrieve all fields from the class and its super classes.
        Parameters:
        cl - class
        Returns:
        fields
      • isCollection

        public static boolean isCollection​(Field field)
        Check if the given field is a collection.
        Parameters:
        field - field to check
        Returns:
        true if the field is an array or a Collection
      • isCollectionType

        public static boolean isCollectionType​(Class<?> type)
        Check if the given type is a collection.
        Parameters:
        type - type to check
        Returns:
        true if the type is an array or implements Collection
      • getAsCollection

        @Nullable
        public static <T> Collection<T> getAsCollection​(Object value)
        Return the given object as a collection.
        Parameters:
        value - the object
        Returns:
        a collection or null
      • getCollectionType

        @Nullable
        public static Class<?> getCollectionType​(Field field)
        Get the type of elements in a collection field.
        Parameters:
        field - field
        Returns:
        type of elements
      • getRequiredCollectionType

        public static Class<?> getRequiredCollectionType​(Field field)
        Get the type of elements in a collection field.
        Parameters:
        field - field
        Returns:
        type of elements
      • getProperties

        public static List<org.springframework.data.relational.core.mapping.RelationalPersistentProperty> getProperties​(org.springframework.data.relational.core.mapping.RelationalPersistentEntity<?> entityType,
                                                                                                                        String... names)
      • isPropertyPartOfCompositeId

        public static boolean isPropertyPartOfCompositeId​(org.springframework.data.relational.core.mapping.RelationalPersistentProperty property)
      • getId

        public static Object getId​(org.springframework.data.relational.core.mapping.RelationalPersistentEntity<?> entityType,
                                   PropertiesSource source)
      • idGetter

        public static Function<PropertiesSource,​Object> idGetter​(org.springframework.data.relational.core.mapping.RelationalPersistentEntity<?> entityType)
      • idGetterFromIdProperty

        public static Function<PropertiesSource,​Object> idGetterFromIdProperty​(org.springframework.data.relational.core.mapping.RelationalPersistentEntity<?> entityType)
      • idGetterFromProperties

        public static Function<PropertiesSource,​Object> idGetterFromProperties​(Iterable<org.springframework.data.relational.core.mapping.RelationalPersistentProperty> properties)
      • hasCascadeDeleteImpacts

        public static boolean hasCascadeDeleteImpacts​(Class<?> entityType)