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 Object
getAttributeValue
(FieldSpecification<?, ?> attribute, Object instance) Gets value of the specified attribute.static Object
getFieldValue
(Field field, Object instance) Gets value of the specified field from the specified instance.static URI
getIdentifier
(Object entity, Metamodel metamodel) Extracts primary key from the specifiedentity
and returns it.static <T> URI
getIdentifier
(T entity, EntityType<?> et) Extracts entity's identifier according to the specified entity type.static URI
getValueAsURI
(Object value) Transforms the specified value to URI (if possible).static boolean
isFieldStatic
(Field field) Returns true if the specified field is static.static boolean
isFieldTransient
(Field field) Checks whether the specified field should not be persisted, i.e.static void
setFieldValue
(Field field, Object instance, Object value) Sets value of the specified field.static <T> void
setIdentifier
(Object identifier, T entity, EntityType<T> et) Sets the specified identifier on the specified entity.static void
verifyIdentifierIsGenerated
(Object instance, EntityType<?> entityType) Verifies, that the primary key (identifier) of the specified instance is generated.
-
Method Details
-
getIdentifier
Extracts primary key from the specifiedentity
and 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
- Ifentity
ormetamodel
is nullOWLPersistenceException
- Ifentity
is 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 benull
for 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
- Ifvalue
isnull
IllegalArgumentException
- Ifvalue
cannot 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
Transient
annotation
- 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
-