Class EntityUtils
java.lang.Object
com.foreach.across.modules.entity.util.EntityUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <Y> List<Y>static <Y> org.springframework.data.domain.Page<Y>Create aPagefrom anyIterable.static StringcombineDisplayNames(String first, String... propertyNames) static org.springframework.data.domain.SortcombineSortSpecifiers(org.springframework.data.domain.Sort... sorts) Merge any number ofSortinstances into a single instance.static StringgenerateDisplayName(String propertyName) static StringgenerateEntityName(Class<?> entityType) Generate a default entity name for an entity type.static EntityTypeDescriptorresolveEntityTypeDescriptor(org.springframework.core.convert.TypeDescriptor typeDescriptor, EntityRegistry entityRegistry) Inspects aTypeDescriptorto retrieve the targetTypeDescriptorif possible.static org.springframework.data.domain.PageabletranslateSort(org.springframework.data.domain.Pageable pageable, EntityPropertyRegistry propertyRegistry) Translates theSortproperty attached to this pageable.static org.springframework.data.domain.SorttranslateSort(org.springframework.data.domain.Sort sort, EntityPropertyRegistry propertyRegistry) Translates theSortinstance based on the specifiedEntityPropertyRegistry.
-
Constructor Details
-
EntityUtils
public EntityUtils()
-
-
Method Details
-
generateEntityName
Generate a default entity name for an entity type.- Parameters:
entityType- for which to generate the name- Returns:
- default name
-
resolveEntityTypeDescriptor
public static EntityTypeDescriptor resolveEntityTypeDescriptor(org.springframework.core.convert.TypeDescriptor typeDescriptor, EntityRegistry entityRegistry) Inspects aTypeDescriptorto retrieve the targetTypeDescriptorif possible. This method is meant to determine the target entity type of for example a collection or array descriptor. In the latter case the target type would usually be the member type of the descriptor. If the type descriptor is neither array nor collection, the original type descriptor is considered to be the target. If the type descriptor is representing a class that extends any of the collection types, its member will be used. In case of a genericMap, no target type can be resolved. If the type extends a collection type but theEntityRegistrycontains an entry for that specific type, that target type will be returned. Else the member will still be resolved. If the type isOptional, the member will be returned. Ifnullis passed as the argument for a type descriptor, a generic descriptor for aObjectwill be returned.- Parameters:
typeDescriptor- to inspect for the target type- Returns:
- resolved descriptor
-
generateDisplayName
-
combineDisplayNames
-
translateSort
public static org.springframework.data.domain.Pageable translateSort(org.springframework.data.domain.Pageable pageable, EntityPropertyRegistry propertyRegistry) Translates theSortproperty attached to this pageable. Will create a newPageableif sorting is modified. SeetranslateSort(Sort, EntityPropertyRegistry)for more details.- Parameters:
pageable- instance to be translatedpropertyRegistry- to be used for looking up matching properties- Returns:
- modified instance or same if unmodified
-
translateSort
@NonNull public static org.springframework.data.domain.Sort translateSort(org.springframework.data.domain.Sort sort, EntityPropertyRegistry propertyRegistry) Translates the
Sortinstance based on the specifiedEntityPropertyRegistry. For everySort.Orderentry a property will be looked up in the registry. If a property is found, theSort.Orderattribute of the property will be fetched and if one is specified, it will be used as the basis for the new entry. Especially theSort.Order.getNullHandling()andSort.Order.isIgnoreCase()settings will be copied. In case null handling is native, a fixed null handling will be applied depending on the direction.Order entries for which no property or property attribute can be found, will be left unchanged.
- Parameters:
sort- instance to be translatedpropertyRegistry- to be used for looking up matching properties- Returns:
- modified or possibly same instance if unmodified
-
combineSortSpecifiers
public static org.springframework.data.domain.Sort combineSortSpecifiers(org.springframework.data.domain.Sort... sorts) Merge any number ofSortinstances into a single instance. Properties will only be applied once, the first time they are encountered.- Parameters:
sorts- to combine- Returns:
- combined sort or
nullif no sort orders were specified
-
asPage
Create aPagefrom anyIterable.- Parameters:
collection- contains the items in the page- Returns:
- Page instance
-
asList
Create aListfrom anyIterable. If the iterable is a list the same instance will be returned. In all other cases a new instance will be created from the elements of the iterable.- Type Parameters:
Y- element type- Parameters:
iterable- containing the elements- Returns:
- List instance
-