java.lang.Object
org.gcube.informationsystem.resourceregistry.persistence.orientdb.types.RegistryMetadataManagement

public class RegistryMetadataManagement extends Object
Reads and persists the RegistryMetadata singleton, stored as a document of a plain OrientDB class of its own (no superclass).
Author:
Luca Frosini (ISTI - CNR)
  • Constructor Summary

    Constructors
    Constructor
    Description
    RegistryMetadataManagement(com.orientechnologies.orient.core.db.document.ODatabaseDocument db)
    Creates a new instance of RegistryMetadataManagement.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    alignType(String modelName, String typeName, String version)
    Sets the version of a model's type, only if the model holds it, with a single server-side update.
    boolean
    Reports whether the singleton class exists, tolerating a stale per-session schema cache.
    void
    Creates the OrientDB class holding the singleton, if it does not exist.
    org.gcube.informationsystem.registry.RegistryMetadata
    get()
    Retrieves the current RegistryMetadata document from the database.
    Advances the global revisionCount and the given model's by one, with a single server-side update, atomic in OrientDB, so that concurrent increments from different instances cannot lose each other.
    boolean
    putType(String modelName, String typeName, String version)
    Adds a type to a model, or sets its version, with a single server-side update.
    Reads revisionCount alone.
    boolean
    removeType(String modelName, String typeName)
    Removes a type from a model, if the model holds it, with a single server-side update.
    void
    save(org.gcube.informationsystem.registry.RegistryMetadata metadata)
    Persists the whole RegistryMetadata singleton document.

    Methods inherited from class java.lang.Object

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

    • RegistryMetadataManagement

      public RegistryMetadataManagement(com.orientechnologies.orient.core.db.document.ODatabaseDocument db)
      Creates a new instance of RegistryMetadataManagement.
      Parameters:
      db - the active OrientDB database session
  • Method Details

    • createClassIfMissing

      public void createClassIfMissing()
      Creates the OrientDB class holding the singleton, if it does not exist. Schema changes are not transactional: call it outside any transaction.
    • get

      public org.gcube.informationsystem.registry.RegistryMetadata get()
      Retrieves the current RegistryMetadata document from the database. If none exists, returns null.
      Returns:
      the RegistryMetadata singleton, or null if not initialized
    • save

      public void save(org.gcube.informationsystem.registry.RegistryMetadata metadata)
      Persists the whole RegistryMetadata singleton document. Only for bootstrap, migration and System Restore: at runtime the record is changed field by field, by the server-side updates below, so that concurrent instances cannot overwrite each other.
      Parameters:
      metadata - the RegistryMetadata document to save
    • classExists

      public boolean classExists()
      Reports whether the singleton class exists, tolerating a stale per-session schema cache.

      Sessions come from long-lived pools, so one opened before the class was created -- possibly by another service instance -- still caches a schema without it. The cache is reloaded once before concluding, only on the apparent-absence path.

      Returns:
      true if the class exists
    • incrementRevisionCount

      public Long incrementRevisionCount(String modelName)
      Advances the global revisionCount and the given model's by one, with a single server-side update, atomic in OrientDB, so that concurrent increments from different instances cannot lose each other.
      Parameters:
      modelName - the model the written type belongs to, or null to advance the global counter alone
      Returns:
      the new global value, or null when no record exists
    • readRevisionCount

      public Long readRevisionCount()
      Reads revisionCount alone.
      Returns:
      the current value, or null when the class or the record does not exist
    • putType

      public boolean putType(String modelName, String typeName, String version)
      Adds a type to a model, or sets its version, with a single server-side update.
      Parameters:
      modelName - the model name
      typeName - the type name
      version - the type version
      Returns:
      true if the record was updated, false when no record exists
    • alignType

      public boolean alignType(String modelName, String typeName, String version)
      Sets the version of a model's type, only if the model holds it, with a single server-side update.
      Parameters:
      modelName - the model name
      typeName - the type name
      version - the type version
      Returns:
      true if the model holds the type and its version was set
    • removeType

      public boolean removeType(String modelName, String typeName)
      Removes a type from a model, if the model holds it, with a single server-side update.
      Parameters:
      modelName - the model name
      typeName - the type name
      Returns:
      true if the model held the type and it was removed