Class EntityPropertiesUtils

java.lang.Object
cz.cvut.kbss.jopa.utils.EntityPropertiesUtils

public class EntityPropertiesUtils extends Object
Utility class for entity properties.
  • Method Details

    • getIdentifier

      public static URI getIdentifier(Object entity, Metamodel metamodel)
      Extracts primary key from the specified entity and returns it.
      Parameters:
      entity - The entity to extract primary key from
      metamodel - Metamodel
      Returns:
      IRI of the entity or null if it is not set
      Throws:
      NullPointerException - If entity or metamodel is null
      OWLPersistenceException - If entity is not an entity or if the identifier is of an unknown type
    • setFieldValue

      public static void setFieldValue(Field field, Object instance, Object value)
      Sets value of the specified field.
      Parameters:
      field - Field to set value on
      instance - Target instance (can be null for static fields)
      value - The value to set (can be null)
    • getFieldValue

      public static Object getFieldValue(Field field, Object instance)
      Gets value of the specified field from the specified instance.
      Parameters:
      field - Field to get value of
      instance - Instance that contains the field
      Returns:
      Field value
    • getAttributeValue

      public static Object getAttributeValue(FieldSpecification<?,?> attribute, Object instance)
      Gets value of the specified attribute.
      Parameters:
      attribute - Attribute to extract value of
      instance - Instance from which value will be extracted
      Returns:
      Attribute value
    • getIdentifier

      public static <T> URI getIdentifier(T entity, EntityType<?> et)
      Extracts entity's identifier according to the specified entity type.
      Type Parameters:
      T - Type of the entity
      Parameters:
      entity - Entity
      et - Entity type
      Returns:
      Identifier of the specified entity, possibly null
    • setIdentifier

      public static <T> void setIdentifier(Object identifier, T entity, EntityType<T> et)
      Sets the specified identifier on the specified entity.
      Type Parameters:
      T - Type of the entity
      Parameters:
      identifier - The identifier to set
      entity - Target entity
      et - Entity type
    • getValueAsURI

      public static URI getValueAsURI(Object value)
      Transforms the specified value to URI (if possible).
      Parameters:
      value - The value to transform
      Returns:
      URI
      Throws:
      NullPointerException - If value is null
      IllegalArgumentException - If value cannot be transformed to URI
    • getAllFields

      public static List<Field> getAllFields(Class<?> cls)
      Gets all instance fields of the specified class, including inherited ones.
      Parameters:
      cls - The class to search
      Returns:
      List of declared fields
    • verifyIdentifierIsGenerated

      public static void verifyIdentifierIsGenerated(Object instance, EntityType<?> entityType)
      Verifies, that the primary key (identifier) of the specified instance is generated.

      If not, an exception is thrown.

      Parameters:
      instance - The instance to verify
      entityType - Entity type of the instance, as specified by metamodel
      Throws:
      IdentifierNotSetException - If the identifier is not generated
    • isFieldTransient

      public static boolean isFieldTransient(Field field)
      Checks whether the specified field should not be persisted, i.e. whether it is transient in the persistence sense.

      A field is transient if it is:

      • static
      • or final
      • or transient
      • or annotated with the Transient annotation
      Parameters:
      field - The field to investigate
      Returns:
      Whether the field is transient
    • isFieldStatic

      public static boolean isFieldStatic(Field field)
      Returns true if the specified field is static.
      Parameters:
      field - The field to check
      Returns:
      True if field is static, false otherwise