Package dev.daymor.sakuraboot.util
Class RelationshipUtils
java.lang.Object
dev.daymor.sakuraboot.util.RelationshipUtils
Utility class for relationship in entity or DTO.
- Since:
- 0.1.1
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
doWithIdRelationFields
(Object data, BiConsumer<Field, Object> consumer, GlobalSpecification globalSpecification) Util method to perform an action to all the ID of the relationship fields in an entity or a DTO object.void
doWithIdRelationFields
(Object data, BiConsumer<Field, Object> consumer, BiConsumer<Field, Collection<?>> consumerCollection, GlobalSpecification globalSpecification) Util method to perform an action to all the ID of the relationship fields in an entity or a DTO object.void
doWithRelationFields
(Object data, BiConsumer<Field, Object> consumer, GlobalSpecification globalSpecification) Util method to perform an action to all the relationship fields in an entity or a DTO object.void
doWithRelationFields
(Object data, BiConsumer<Field, Object> consumer, BiConsumer<Field, Collection<?>> consumerCollection, GlobalSpecification globalSpecification) Util method to perform an action to all the relationship fields in an entity or a DTO object.getEntityFieldFromDto
(Member field, Class<?> dtoClass, String entityPackage, String dtoPackage) Util method to get the entity field from a DTO field.getMappedByRelationClass
(Class<?> clazz) Util method to get the class of all the relationship fields in an entity with mappedBy attribute in the mapping annotation.Class
<?> getRelationalType
(Field field, GlobalSpecification globalSpecification) Util method to get the class of a relationship field.getRelationClass
(Class<?> clazz) Util method to get the class of all the relationship fields in an entity.boolean
Util method to check if a field is an any to many relationship in an entity.boolean
Util method to check if a field is an any to one relationship in an entity.boolean
Util method to check if a field is not a relation with mappedBy attribute in the mapping annotation.boolean
isRelationship
(AnnotatedElement field) Util method to check if a field is a relationship in an entity.boolean
Util method to check if a field is a relationship in an entity.void
updateRelationFields
(Object data, BiFunction<Field, Object, Object> function, GlobalSpecification globalSpecification) Util method to update the value to all the relationship fields in an entity or a DTO object.void
updateRelationFields
(Object data, BiFunction<Field, Object, Object> function, BiFunction<Field, Collection<?>, Collection<?>> functionCollection, GlobalSpecification globalSpecification) Util method to update the value to all the relationship fields in an entity or a DTO object.
-
Constructor Details
-
RelationshipUtils
public RelationshipUtils()
-
-
Method Details
-
isRelationship
Util method to check if a field is a relationship in an entity.- Parameters:
field
- The field to check.- Returns:
- True if the field is a relationship, false otherwise.
-
isAnyToOneRelationship
Util method to check if a field is an any to one relationship in an entity.- Parameters:
field
- The field to check.- Returns:
- True if the field is a relationship, false otherwise.
-
isAnyToManyRelationship
Util method to check if a field is an any to many relationship in an entity.- Parameters:
field
- The field to check.- Returns:
- True if the field is a relationship, false otherwise.
-
getEntityFieldFromDto
@Nullable public AnnotatedElement getEntityFieldFromDto(Member field, Class<?> dtoClass, String entityPackage, String dtoPackage) Util method to get the entity field from a DTO field.- Parameters:
field
- The field of the DTO.dtoClass
- The DTO class.entityPackage
- The entity package.dtoPackage
- The DTO package.- Returns:
- The field of the entity.
-
isRelationshipExcludeMappedBy
Util method to check if a field is a relationship in an entity. Exclude the field with mappedBy attribute in the mapping annotation.- Parameters:
field
- The field to check.- Returns:
- True if the field is a relationship, false otherwise.
-
isNotRelationWithMappedBy
Util method to check if a field is not a relation with mappedBy attribute in the mapping annotation. Help to not include this field in other methods.- Parameters:
field
- The field to check.- Returns:
- True if the field is not a relation with mappedBy attribute, false otherwise.
-
getRelationClass
Util method to get the class of all the relationship fields in an entity. Exclude the field with mappedBy attribute in the mapping annotation.- Parameters:
clazz
- The entity class.- Returns:
- The class of all the relationship fields.
-
getMappedByRelationClass
Util method to get the class of all the relationship fields in an entity with mappedBy attribute in the mapping annotation.- Parameters:
clazz
- The entity class.- Returns:
- The class of all the relationship fields.
-
getRelationalType
Util method to get the class of a relationship field. The entity class will be returned if the field is for a DTO. If the field is a collection, the class of the element in the collection is returned.- Parameters:
field
- The relationship field.globalSpecification
- TheGlobalSpecification
help to get the entity class from the DTO class.- Returns:
- The class of the relationship field.
-
doWithRelationFields
public void doWithRelationFields(Object data, BiConsumer<Field, Object> consumer, @Nullable GlobalSpecification globalSpecification) Util method to perform an action to all the relationship fields in an entity or a DTO object. Include all the objects inside a collection.- Parameters:
data
- The entity or DTO object.consumer
- The action to perform.globalSpecification
- TheGlobalSpecification
help to get the entity and dto package.
-
doWithRelationFields
public void doWithRelationFields(Object data, BiConsumer<Field, Object> consumer, BiConsumer<Field, Collection<?>> consumerCollection, @Nullable GlobalSpecification globalSpecification) Util method to perform an action to all the relationship fields in an entity or a DTO object. Don't include all the objects inside a collection but perform an action on the collection.- Parameters:
data
- The entity or DTO object.consumer
- The action to perform.consumerCollection
- The action to perform to a collection.globalSpecification
- TheGlobalSpecification
help to get the entity and dto package.
-
doWithIdRelationFields
public void doWithIdRelationFields(Object data, BiConsumer<Field, Object> consumer, @Nullable GlobalSpecification globalSpecification) Util method to perform an action to all the ID of the relationship fields in an entity or a DTO object. Include all the IDs inside a collection.- Parameters:
data
- The entity or DTO object.consumer
- The action to perform.globalSpecification
- TheGlobalSpecification
help to get the entity and dto package.
-
doWithIdRelationFields
public void doWithIdRelationFields(Object data, BiConsumer<Field, Object> consumer, BiConsumer<Field, Collection<?>> consumerCollection, @Nullable GlobalSpecification globalSpecification) Util method to perform an action to all the ID of the relationship fields in an entity or a DTO object. Don't include all the IDs inside a collection but perform an action on the collection.- Parameters:
data
- The entity or DTO object.consumer
- The action to perform.consumerCollection
- The action to perform to a collection.globalSpecification
- TheGlobalSpecification
help to get the entity and dto package.
-
updateRelationFields
public void updateRelationFields(Object data, BiFunction<Field, Object, Object> function, @Nullable GlobalSpecification globalSpecification) Util method to update the value to all the relationship fields in an entity or a DTO object. Include all the objects inside a collection.- Parameters:
data
- The entity or DTO object.function
- The function to update the value.globalSpecification
- TheGlobalSpecification
help to get the entity and dto package.
-
updateRelationFields
public void updateRelationFields(Object data, BiFunction<Field, Object, Object> function, BiFunction<Field, Collection<?>, Collection<?>> functionCollection, @Nullable GlobalSpecification globalSpecification) Util method to update the value to all the relationship fields in an entity or a DTO object. Don't include all the objects inside a collection but update the value of the collection.- Parameters:
data
- The entity or DTO object.function
- The function to update the value.functionCollection
- The function to update the collection.globalSpecification
- TheGlobalSpecification
help to get the entity and dto package.
-