Class EntityRelationsUtils
java.lang.Object
io.github.blyznytsiaorg.bibernate.utils.EntityRelationsUtils
Utility class for handling entity relationships in Bibernate.
- Since:
- 1.0
- Author:
- Blyzhnytsia Team
-
Field Summary
Modifier and TypeFieldDescriptionprivate final List
<Class<? extends Annotation>> private final List
<Class<? extends Annotation>> private static final String
private static final String
static final String
private static final String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbidirectionalRelations
(Class<?> entityClass, Field field) Retrieves the names of bidirectional relations for a given many-to-many association field of an entity.static List
<CascadeType> getCascadeTypesFromAnnotation
(Annotation annotation) Retrieves the CascadeType values specified in the cascade attribute of a given annotation.getMappedByColumnName
(String mappedByName, Class<?> collectionGenericType) Retrieves the name of the column associated with a mapped-by field in a collection.boolean
isCollectionField
(Field field) Checks if a field is a collection field.boolean
isEntityField
(Field field) Checks if a field is an entity field.static boolean
isInverseSide
(Field field) Checks if a field is an inverse side in a ManyToMany relationship.boolean
isManyToMany
(Field field) Checks if a field is annotated with @ManyToMany.boolean
isOneToMany
(Field field) Checks if a field is annotated with @OneToMany.boolean
isRegularField
(Field field) Checks if a field is a regular field (neither an entity nor a collection).static String
mappedByJoinColumnName
(Field field) Gets the join column name based on the 'mappedBy' attribute of the OneToMany annotation.static Field
owningFieldByInverse
(Field field) Gets the owning field from an inverse field in a ManyToMany relationship.
-
Field Details
-
FIELD_WITH_ANNOTATION_NOT_APPLICABLE_FOR_COLLECTIONS
- See Also:
-
FIELD_WITH_ANNOTATION_APPLICABLE_ONLY_FOR_COLLECTIONS
- See Also:
-
UNABLE_TO_GET_OWNING_FIELD_FROM_INVERSE_FIELD
- See Also:
-
UNABLE_TO_GET_MAPPED_BY_FIELD_IN_OWNING_ENTITY
- See Also:
-
entityAnnotations
-
collectionAnnotations
-
-
Constructor Details
-
EntityRelationsUtils
public EntityRelationsUtils()
-
-
Method Details
-
isRegularField
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
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
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
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
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
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
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
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
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
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.
-