Class ModelUtils
- java.lang.Object
-
- net.lecousin.reactive.data.relational.model.ModelUtils
-
public class ModelUtils extends Object
Utility methods.- Author:
- Guillaume Le Cousin
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddToCollectionField(Field field, Object collectionOwnerInstance, Object elementToAdd)static List<Field>getAllFields(Class<?> cl)Retrieve all fields from the class and its super classes.static <T> Collection<T>getAsCollection(Object value)Return the given object as a collection.static Class<?>getCollectionType(Field field)Get the type of elements in a collection field.static ObjectgetFieldValue(Object instance, Field field)static ObjectgetId(org.springframework.data.relational.core.mapping.RelationalPersistentEntity<?> entityType, PropertiesSource source)static ObjectgetPersistedDatabaseValue(EntityState state, PropertyMetadata property)static List<org.springframework.data.relational.core.mapping.RelationalPersistentProperty>getProperties(org.springframework.data.relational.core.mapping.RelationalPersistentEntity<?> entityType, String... names)static Class<?>getRequiredCollectionType(Field field)Get the type of elements in a collection field.static booleanhasCascadeDeleteImpacts(Class<?> entityType)static Function<PropertiesSource,Object>idGetter(org.springframework.data.relational.core.mapping.RelationalPersistentEntity<?> entityType)static Function<PropertiesSource,Object>idGetterFromIdProperty(org.springframework.data.relational.core.mapping.RelationalPersistentEntity<?> entityType)static Function<PropertiesSource,Object>idGetterFromProperties(Iterable<org.springframework.data.relational.core.mapping.RelationalPersistentProperty> properties)static booleanisCollection(Field field)Check if the given field is a collection.static booleanisCollectionType(Class<?> type)Check if the given type is a collection.static booleanisPropertyPartOfCompositeId(org.springframework.data.relational.core.mapping.RelationalPersistentProperty property)static voidremoveFromCollectionField(Field field, Object collectionOwnerInstance, Object elementToRemove)static voidsetFieldValue(Object instance, Field field, Object value)static voidsetReverseLink(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.
-
-
-
Method Detail
-
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 fieldlinkedInstance- entity having the foreign keylinkedProperty- 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
-
addToCollectionField
public static void addToCollectionField(Field field, Object collectionOwnerInstance, Object elementToAdd) throws IllegalAccessException
- Throws:
IllegalAccessException
-
removeFromCollectionField
public static void removeFromCollectionField(Field field, Object collectionOwnerInstance, Object elementToRemove) throws IllegalAccessException
- Throws:
IllegalAccessException
-
getPersistedDatabaseValue
public static Object getPersistedDatabaseValue(EntityState state, PropertyMetadata property)
-
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)
-
-