Class RelationshipUtils

java.lang.Object
dev.daymor.sakuraboot.util.RelationshipUtils

public class RelationshipUtils extends Object
Utility class for relationship in entity or DTO.
Since:
0.1.1
  • Constructor Details

    • RelationshipUtils

      public RelationshipUtils()
  • Method Details

    • isRelationship

      public boolean isRelationship(AnnotatedElement field)
      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

      public boolean isAnyToOneRelationship(AnnotatedElement field)
      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

      public boolean isAnyToManyRelationship(AnnotatedElement field)
      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

      public boolean isRelationshipExcludeMappedBy(AnnotatedElement field)
      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

      public boolean isNotRelationWithMappedBy(AnnotatedElement field)
      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

      public List<Class<?>> getRelationClass(Class<?> clazz)
      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

      public List<Class<?>> getMappedByRelationClass(Class<?> clazz)
      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

      public Class<?> getRelationalType(Field field, GlobalSpecification globalSpecification)
      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 - The GlobalSpecification 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 - The GlobalSpecification 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 - The GlobalSpecification 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 - The GlobalSpecification 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 - The GlobalSpecification 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 - The GlobalSpecification 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 - The GlobalSpecification help to get the entity and dto package.