Object PersistenceUtils

  • All Implemented Interfaces:

    
    public class PersistenceUtils
    
                        

    This utility class provides methods for working with persistence-related operations, such as retrieving entity fields, finding entity types, determining attribute types, and performing other common tasks related to persistence.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Set<String> getEntityFields(Metamodel metamodel, Class<?> entityClass) Retrieves the set of field names for a given entity class from the metamodel.
      final EntityType<?> getEntityType(Metamodel metamodel, String entityName) Retrieves the entity type with the given name from the provided metamodel.
      final EntityType<?> getTargetEntityTypeForPluralAttribute(Metamodel metamodel, Attribute<?, ?> attribute) Retrieves the target entity type for a plural attribute.
      final Boolean isNumberType(Attribute<?, ?> attribute) Checks if the given attribute is a number type.
      final Boolean isBooleanType(Attribute<?, ?> attribute) Determines if the given attribute is of boolean type.
      final String getIdAttributeName(EntityType<?> entityType) Returns the name of the ID attribute for the given entity type.
      final Attribute<?, ?> findAttributeByPath(EntityType<?> entityType, String path) Finds an attribute by the given path in the provided entity type.
      final Boolean isValidPath(EntityType<?> entityType, String path) Checks if the given path is a valid path for the specified entity type.
      final Attribute<?, ?> getInverseAttribute(EntityType<?> sourceEntityType, Attribute<?, ?> sourceAttribute, EntityType<?> targetEntityType) Returns the inverse attribute for a given source attribute in a target entity.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • getEntityFields

         final Set<String> getEntityFields(Metamodel metamodel, Class<?> entityClass)

        Retrieves the set of field names for a given entity class from the metamodel.

        Parameters:
        metamodel - the metamodel instance to use for entity analysis
        entityClass - the class representing the entity
        Returns:

        a set of field names for the entity class

      • getEntityType

         final EntityType<?> getEntityType(Metamodel metamodel, String entityName)

        Retrieves the entity type with the given name from the provided metamodel.

        Parameters:
        metamodel - The metamodel containing the entities.
        entityName - The name of the entity type to retrieve.
        Returns:

        The EntityType representing the entity type with the given name, or null if no entity type with the given name is found.

      • getTargetEntityTypeForPluralAttribute

         final EntityType<?> getTargetEntityTypeForPluralAttribute(Metamodel metamodel, Attribute<?, ?> attribute)

        Retrieves the target entity type for a plural attribute.

        Parameters:
        metamodel - The metamodel containing entity type information.
        attribute - The attribute for which to retrieve the target entity type.
        Returns:

        The target entity type of the attribute.

      • isNumberType

         final Boolean isNumberType(Attribute<?, ?> attribute)

        Checks if the given attribute is a number type.

        Parameters:
        attribute - The attribute to check.
        Returns:

        True if the attribute is a number type, false otherwise.

      • isBooleanType

         final Boolean isBooleanType(Attribute<?, ?> attribute)

        Determines if the given attribute is of boolean type.

        Parameters:
        attribute - the attribute to check
        Returns:

        true if the attribute is of boolean type, false otherwise

      • getIdAttributeName

         final String getIdAttributeName(EntityType<?> entityType)

        Returns the name of the ID attribute for the given entity type.

        Parameters:
        entityType - the entity type
        Returns:

        the name of the ID attribute

      • findAttributeByPath

         final Attribute<?, ?> findAttributeByPath(EntityType<?> entityType, String path)

        Finds an attribute by the given path in the provided entity type.

        Parameters:
        entityType - the entity type to search for the attribute
        path - the path of the attribute separated by dots
        Returns:

        the found attribute or throws an exception if not found

      • isValidPath

         final Boolean isValidPath(EntityType<?> entityType, String path)

        Checks if the given path is a valid path for the specified entity type.

        Parameters:
        entityType - The entity type to validate against.
        path - The path to validate.
        Returns:

        True if the path is valid, false otherwise.

      • getInverseAttribute

         final Attribute<?, ?> getInverseAttribute(EntityType<?> sourceEntityType, Attribute<?, ?> sourceAttribute, EntityType<?> targetEntityType)

        Returns the inverse attribute for a given source attribute in a target entity.

        Parameters:
        sourceEntityType - The EntityType of the source entity.
        sourceAttribute - The source Attribute.
        targetEntityType - The EntityType of the target entity.
        Returns:

        The inverse Attribute in the target entity.