Package cz.cvut.kbss.jopa.utils
Class EntityPropertiesUtils
java.lang.Object
cz.cvut.kbss.jopa.utils.EntityPropertiesUtils
Utility class for entity properties.
-
Method Summary
Modifier and TypeMethodDescriptiongetAllFields(Class<?> cls) Gets all instance fields of the specified class, including inherited ones.static ObjectgetAttributeValue(FieldSpecification<?, ?> attribute, Object instance) Gets value of the specified attribute.static ObjectgetFieldValue(Field field, Object instance) Gets value of the specified field from the specified instance.static URIgetIdentifier(Object entity, Metamodel metamodel) Extracts primary key from the specifiedentityand returns it.static <T> URIgetIdentifier(T entity, EntityType<?> et) Extracts entity's identifier according to the specified entity type.static URIgetValueAsURI(Object value) Transforms the specified value to URI (if possible).static booleanisFieldStatic(Field field) Returns true if the specified field is static.static booleanisFieldTransient(Field field) Checks whether the specified field should not be persisted, i.e.static voidsetFieldValue(Field field, Object instance, Object value) Sets value of the specified field.static <T> voidsetIdentifier(Object identifier, T entity, EntityType<T> et) Sets the specified identifier on the specified entity.static voidverifyIdentifierIsGenerated(Object instance, EntityType<?> entityType) Verifies, that the primary key (identifier) of the specified instance is generated.
-
Method Details
-
getIdentifier
Extracts primary key from the specifiedentityand returns it.- Parameters:
entity- The entity to extract primary key frommetamodel- Metamodel- Returns:
- IRI of the entity or null if it is not set
- Throws:
NullPointerException- Ifentityormetamodelis nullOWLPersistenceException- Ifentityis not an entity or if the identifier is of an unknown type
-
setFieldValue
Sets value of the specified field.- Parameters:
field- Field to set value oninstance- Target instance (can benullfor static fields)value- The value to set (can benull)
-
getFieldValue
Gets value of the specified field from the specified instance.- Parameters:
field- Field to get value ofinstance- Instance that contains the field- Returns:
- Field value
-
getAttributeValue
Gets value of the specified attribute.- Parameters:
attribute- Attribute to extract value ofinstance- Instance from which value will be extracted- Returns:
- Attribute value
-
getIdentifier
Extracts entity's identifier according to the specified entity type.- Type Parameters:
T- Type of the entity- Parameters:
entity- Entityet- Entity type- Returns:
- Identifier of the specified entity, possibly null
-
setIdentifier
Sets the specified identifier on the specified entity.- Type Parameters:
T- Type of the entity- Parameters:
identifier- The identifier to setentity- Target entityet- Entity type
-
getValueAsURI
Transforms the specified value to URI (if possible).- Parameters:
value- The value to transform- Returns:
URI- Throws:
NullPointerException- IfvalueisnullIllegalArgumentException- Ifvaluecannot be transformed to URI
-
getAllFields
Gets all instance fields of the specified class, including inherited ones.- Parameters:
cls- The class to search- Returns:
- List of declared fields
-
verifyIdentifierIsGenerated
Verifies, that the primary key (identifier) of the specified instance is generated.If not, an exception is thrown.
- Parameters:
instance- The instance to verifyentityType- Entity type of the instance, as specified by metamodel- Throws:
IdentifierNotSetException- If the identifier is not generated
-
isFieldTransient
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
Transientannotation
- Parameters:
field- The field to investigate- Returns:
- Whether the field is transient
-
isFieldStatic
Returns true if the specified field is static.- Parameters:
field- The field to check- Returns:
- True if field is static, false otherwise
-