java.lang.Object
org.gcube.informationsystem.resourceregistry.persistence.orientdb.base.OrientDBUtility

public class OrientDBUtility extends Object
Author:
Luca Frosini (ISTI - CNR)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The OrientDB metadata class attribute property name.
    static final String
    The standard error message used for unexpected or fatal errors that should not occur.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    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 String
    getAsStringForException(com.orientechnologies.orient.core.record.ORecord oRecord)
    Formats and returns the OrientDB record representation as a JSON string for exception messages.
    static String
    getAsStringForLogging(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>
    El
    getElementByUUID(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>
    El
    getElementByUUID(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>
    El
    getElementByUUIDAsAdmin(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>
    El
    getElementByUUIDAsAdmin(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>
    P
    getPropertyDocument(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 String
    Replaces the OrientDB class attribute key with the standard element type property key.
    static org.gcube.com.fasterxml.jackson.databind.JsonNode
    toJsonNode(com.orientechnologies.orient.core.record.OElement element)
    Converts the specified OrientDB element into a Jackson JsonNode.
    static org.gcube.com.fasterxml.jackson.databind.JsonNode
    toJsonNode(com.orientechnologies.orient.core.record.ORecord oRecord)
    Converts the specified OrientDB record into a Jackson JsonNode.
    static String
    toJsonString(com.orientechnologies.orient.core.record.ORecord oRecord)
    Converts the specified OrientDB record into a serialized JSON string.
    static String
    toJsonString(com.orientechnologies.orient.core.sql.executor.OResult oResult)
    Converts the specified OrientDB query result into a serialized JSON string.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ORIENTDB_CLASS_PROPERTY

      public static final String ORIENTDB_CLASS_PROPERTY
      The OrientDB metadata class attribute property name.
      See Also:
    • SHOULD_NOT_OCCUR_ERROR_MESSAGE

      public static final String 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 Jackson JsonNode.
      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 Jackson JsonNode.
      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

      public static String formatDateTime(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.
      Parameters:
      date - the Date to format
      Returns:
      the formatted Date
    • replaceType

      public static String replaceType(String s)
      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

      public static String toJsonString(com.orientechnologies.orient.core.sql.executor.OResult oResult)
      Converts the specified OrientDB query result into a serialized JSON string.
      Parameters:
      oResult - the query result to convert
      Returns:
      the JSON string representation
    • toJsonString

      public static String toJsonString(com.orientechnologies.orient.core.record.ORecord oRecord)
      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 element
      uuid - the UUID of the element to resolve
      clz - the class of the element
      Returns:
      the resolved element
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException - if the element does not exist
      org.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 element
      uuid - the UUID of the element to resolve
      clz - the class of the element
      polymorphic - whether registered subtypes may match elementType
      Returns:
      the resolved element
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException - if the element does not exist
      org.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 session
      elementType - the class type name of the element
      uuid - the UUID of the element to resolve
      clz - the class of the element
      Returns:
      the resolved element
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException - if the element does not exist
      org.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 session
      elementType - the class type name of the element
      uuid - the UUID of the element to resolve
      clz - the class of the element
      polymorphic - whether registered subtypes may match elementType
      Returns:
      the resolved element
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException - if the element does not exist
      org.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 element
      element - the parent OrientDB element
      property - the property key name
      Returns:
      the deserialized property element instance
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if deserialization fails