Class EntityRelationsUtils

java.lang.Object
io.github.blyznytsiaorg.bibernate.utils.EntityRelationsUtils

public class EntityRelationsUtils extends Object
Utility class for handling entity relationships in Bibernate.
Since:
1.0
Author:
Blyzhnytsia Team
  • Field Details

    • FIELD_WITH_ANNOTATION_NOT_APPLICABLE_FOR_COLLECTIONS

      private static final String FIELD_WITH_ANNOTATION_NOT_APPLICABLE_FOR_COLLECTIONS
      See Also:
    • FIELD_WITH_ANNOTATION_APPLICABLE_ONLY_FOR_COLLECTIONS

      private static final String FIELD_WITH_ANNOTATION_APPLICABLE_ONLY_FOR_COLLECTIONS
      See Also:
    • UNABLE_TO_GET_OWNING_FIELD_FROM_INVERSE_FIELD

      private static final String UNABLE_TO_GET_OWNING_FIELD_FROM_INVERSE_FIELD
      See Also:
    • UNABLE_TO_GET_MAPPED_BY_FIELD_IN_OWNING_ENTITY

      public static final String UNABLE_TO_GET_MAPPED_BY_FIELD_IN_OWNING_ENTITY
      See Also:
    • entityAnnotations

      private final List<Class<? extends Annotation>> entityAnnotations
    • collectionAnnotations

      private final List<Class<? extends Annotation>> collectionAnnotations
  • Constructor Details

    • EntityRelationsUtils

      public EntityRelationsUtils()
  • Method Details

    • isRegularField

      public boolean isRegularField(Field field)
      Checks if a field is a regular field (neither an entity nor a collection).
      Parameters:
      field - The field to check.
      Returns:
      true if the field is a regular field, false otherwise.
    • isEntityField

      public boolean isEntityField(Field field)
      Checks if a field is an entity field.
      Parameters:
      field - The field to check.
      Returns:
      true if the field is an entity field, false otherwise.
      Throws:
      BibernateGeneralException - If the field is annotated with an entity annotation but is a collection.
    • isCollectionField

      public boolean isCollectionField(Field field)
      Checks if a field is a collection field.
      Parameters:
      field - The field to check.
      Returns:
      true if the field is a collection field, false otherwise.
      Throws:
      BibernateGeneralException - If the field is annotated with a collection annotation but is not a supported Collection.
    • isInverseSide

      public static boolean isInverseSide(Field field)
      Checks if a field is an inverse side in a ManyToMany relationship.
      Parameters:
      field - The field to check.
      Returns:
      true if the field is an inverse side, false otherwise.
    • owningFieldByInverse

      public static Field owningFieldByInverse(Field field)
      Gets the owning field from an inverse field in a ManyToMany relationship.
      Parameters:
      field - The inverse field.
      Returns:
      The owning field.
      Throws:
      BibernateGeneralException - If the owning field cannot be obtained.
    • mappedByJoinColumnName

      public static String mappedByJoinColumnName(Field field)
      Gets the join column name based on the 'mappedBy' attribute of the OneToMany annotation.
      Parameters:
      field - The field annotated with OneToMany.
      Returns:
      The join column name.
    • getMappedByColumnName

      private static Optional<String> getMappedByColumnName(String mappedByName, Class<?> collectionGenericType)
      Retrieves the name of the column associated with a mapped-by field in a collection.
      Parameters:
      mappedByName - The name of the field that is mapped by another field.
      collectionGenericType - The type of the collection.
      Returns:
      An Optional containing the name of the column associated with the mapped-by field, or an empty Optional if no matching field is found.
    • bidirectionalRelations

      public static List<String> bidirectionalRelations(Class<?> entityClass, Field field)
      Retrieves the names of bidirectional relations for a given many-to-many association field of an entity.
      Parameters:
      entityClass - The class of the entity.
      field - The field representing the many-to-many association.
      Returns:
      A list of names of bidirectional relations for the given field.
    • getCascadeTypesFromAnnotation

      public static List<CascadeType> getCascadeTypesFromAnnotation(Annotation annotation)
      Retrieves the CascadeType values specified in the cascade attribute of a given annotation.
      Parameters:
      annotation - The annotation from which to retrieve cascade types.
      Returns:
      A list of CascadeType values specified in the cascade attribute of the annotation, or an empty list if the cascade attribute is not present or cannot be accessed.
    • isOneToMany

      public boolean isOneToMany(Field field)
      Checks if a field is annotated with @OneToMany.
      Parameters:
      field - The field to check.
      Returns:
      True if the field is annotated with @OneToMany, false otherwise.
    • isManyToMany

      public boolean isManyToMany(Field field)
      Checks if a field is annotated with @ManyToMany.
      Parameters:
      field - The field to check.
      Returns:
      True if the field is annotated with @ManyToMany, false otherwise.