Class OrientDBUtility
java.lang.Object
org.gcube.informationsystem.resourceregistry.persistence.orientdb.base.OrientDBUtility
- Author:
- Luca Frosini (ISTI - CNR)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatDateTime(Date date) Formats a Date as every representation does: in the date-time format of the database,Element.DATETIME_PATTERN, the one the records are serialized with.static StringgetAsStringForException(com.orientechnologies.orient.core.record.ORecord oRecord) Formats and returns the OrientDB record representation as a JSON string for exception messages.static StringgetAsStringForLogging(com.orientechnologies.orient.core.record.ORecord oRecord) Formats and returns the OrientDB record representation as a JSON string for logging.static <El extends com.orientechnologies.orient.core.record.OElement>
ElgetElementByUUID(com.orientechnologies.orient.core.db.document.ODatabaseDocument oDatabaseDocument, String elementType, UUID uuid, Class<? extends El> clz) Resolves and returns the OrientDB element of the specified class and UUID, within the given database session.static <El extends com.orientechnologies.orient.core.record.OElement>
ElgetElementByUUID(com.orientechnologies.orient.core.db.document.ODatabaseDocument oDatabaseDocument, String elementType, UUID uuid, Class<? extends El> clz, boolean polymorphic) Resolves an element by Type and UUID with explicit subtype matching semantics.static <El extends com.orientechnologies.orient.core.record.OElement>
ElgetElementByUUIDAsAdmin(String elementType, UUID uuid, Class<? extends El> clz) Resolves and returns the OrientDB element of the specified class and UUID, using an admin database session.static <El extends com.orientechnologies.orient.core.record.OElement>
ElgetElementByUUIDAsAdmin(String elementType, UUID uuid, Class<? extends El> clz, boolean polymorphic) Resolves an element by Type and UUID with explicit subtype matching semantics, using an administrative database session.static <P extends org.gcube.informationsystem.base.reference.properties.PropertyElement>
PgetPropertyDocument(Class<P> clz, com.orientechnologies.orient.core.record.OElement element, String property) Deserializes and returns the property document of the specified class from the given OrientDB element.static StringReplaces the OrientDB class attribute key with the standard element type property key.static org.gcube.com.fasterxml.jackson.databind.JsonNodetoJsonNode(com.orientechnologies.orient.core.record.OElement element) Converts the specified OrientDB element into a JacksonJsonNode.static org.gcube.com.fasterxml.jackson.databind.JsonNodetoJsonNode(com.orientechnologies.orient.core.record.ORecord oRecord) Converts the specified OrientDB record into a JacksonJsonNode.static StringtoJsonString(com.orientechnologies.orient.core.record.ORecord oRecord) Converts the specified OrientDB record into a serialized JSON string.static StringtoJsonString(com.orientechnologies.orient.core.sql.executor.OResult oResult) Converts the specified OrientDB query result into a serialized JSON string.
-
Field Details
-
ORIENTDB_CLASS_PROPERTY
The OrientDB metadata class attribute property name.- See Also:
-
SHOULD_NOT_OCCUR_ERROR_MESSAGE
The standard error message used for unexpected or fatal errors that should not occur.- See Also:
-
-
Constructor Details
-
OrientDBUtility
public OrientDBUtility()
-
-
Method Details
-
toJsonNode
public static org.gcube.com.fasterxml.jackson.databind.JsonNode toJsonNode(com.orientechnologies.orient.core.record.OElement element) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException Converts the specified OrientDB element into a JacksonJsonNode.- Parameters:
element- the OrientDB element to convert- Returns:
- the converted JSON node representation
- Throws:
org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException- if serialization fails
-
toJsonNode
public static org.gcube.com.fasterxml.jackson.databind.JsonNode toJsonNode(com.orientechnologies.orient.core.record.ORecord oRecord) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException Converts the specified OrientDB record into a JacksonJsonNode.- Parameters:
oRecord- the OrientDB record to convert- Returns:
- the converted JSON node representation
- Throws:
org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException- if serialization fails
-
formatDateTime
Formats a Date as every representation does: in the date-time format of the database,Element.DATETIME_PATTERN, the one the records are serialized with.- Parameters:
date- the Date to format- Returns:
- the formatted Date
-
replaceType
Replaces the OrientDB class attribute key with the standard element type property key.- Parameters:
s- the JSON string to process- Returns:
- the processed JSON string
-
toJsonString
Converts the specified OrientDB query result into a serialized JSON string.- Parameters:
oResult- the query result to convert- Returns:
- the JSON string representation
-
toJsonString
Converts the specified OrientDB record into a serialized JSON string.- Parameters:
oRecord- the record to convert- Returns:
- the JSON string representation
-
getAsStringForLogging
public static String getAsStringForLogging(com.orientechnologies.orient.core.record.ORecord oRecord) Formats and returns the OrientDB record representation as a JSON string for logging.- Parameters:
oRecord- the record to format- Returns:
- the formatted logging string
-
getAsStringForException
public static String getAsStringForException(com.orientechnologies.orient.core.record.ORecord oRecord) Formats and returns the OrientDB record representation as a JSON string for exception messages.- Parameters:
oRecord- the record to format- Returns:
- the formatted exception string
-
getElementByUUIDAsAdmin
public static <El extends com.orientechnologies.orient.core.record.OElement> El getElementByUUIDAsAdmin(String elementType, UUID uuid, Class<? extends El> clz) throws org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException Resolves and returns the OrientDB element of the specified class and UUID, using an admin database session.- Type Parameters:
El- the element type- Parameters:
elementType- the class type name of the elementuuid- the UUID of the element to resolveclz- the class of the element- Returns:
- the resolved element
- Throws:
org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException- if the element does not existorg.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException- on database or lookup failure
-
getElementByUUIDAsAdmin
public static <El extends com.orientechnologies.orient.core.record.OElement> El getElementByUUIDAsAdmin(String elementType, UUID uuid, Class<? extends El> clz, boolean polymorphic) throws org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException Resolves an element by Type and UUID with explicit subtype matching semantics, using an administrative database session.- Type Parameters:
El- the element type- Parameters:
elementType- the class type name of the elementuuid- the UUID of the element to resolveclz- the class of the elementpolymorphic- whether registered subtypes may matchelementType- Returns:
- the resolved element
- Throws:
org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException- if the element does not existorg.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException- on database or lookup failure
-
getElementByUUID
public static <El extends com.orientechnologies.orient.core.record.OElement> El getElementByUUID(com.orientechnologies.orient.core.db.document.ODatabaseDocument oDatabaseDocument, String elementType, UUID uuid, Class<? extends El> clz) throws org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException Resolves and returns the OrientDB element of the specified class and UUID, within the given database session.- Type Parameters:
El- the element type- Parameters:
oDatabaseDocument- the database sessionelementType- the class type name of the elementuuid- the UUID of the element to resolveclz- the class of the element- Returns:
- the resolved element
- Throws:
org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException- if the element does not existorg.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException- on database or lookup failure
-
getElementByUUID
public static <El extends com.orientechnologies.orient.core.record.OElement> El getElementByUUID(com.orientechnologies.orient.core.db.document.ODatabaseDocument oDatabaseDocument, String elementType, UUID uuid, Class<? extends El> clz, boolean polymorphic) throws org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException Resolves an element by Type and UUID with explicit subtype matching semantics.- Type Parameters:
El- the element type- Parameters:
oDatabaseDocument- the database sessionelementType- the class type name of the elementuuid- the UUID of the element to resolveclz- the class of the elementpolymorphic- whether registered subtypes may matchelementType- Returns:
- the resolved element
- Throws:
org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException- if the element does not existorg.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException- on database or lookup failure
-
getPropertyDocument
public static <P extends org.gcube.informationsystem.base.reference.properties.PropertyElement> P getPropertyDocument(Class<P> clz, com.orientechnologies.orient.core.record.OElement element, String property) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException Deserializes and returns the property document of the specified class from the given OrientDB element.- Type Parameters:
P- the property element type- Parameters:
clz- the class of the property elementelement- the parent OrientDB elementproperty- the property key name- Returns:
- the deserialized property element instance
- Throws:
org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException- if deserialization fails
-