java.lang.Object
org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment

public class DatabaseEnvironment extends Object
The OrientDB connection settings of the service and the one-time preparation of its database.

The settings (the database section of "service.yaml" on the classpath) and the database key are loaded once into static final fields the first time this class is loaded; that needs no database. The database itself is reached by ensureDatabase(), which every pool of ODatabasePoolManager calls before it opens a connection: it connects to OrientDB and, if the configured database does not exist yet, creates it, enables Record-Level Security (setRecordLevelSecurity(OMetadata)), sets up the administrative user and password, creates the AdminEnvironment, QueryTemplateEnvironment, TypeEnvironment and the Context partition tree (ContextEnvironment parent, then its LiveContextEnvironment and CemeteryContextEnvironment children: the parent must exist first so hierarchical role propagation applies at child creation), and finally runs IsModelBootstrap.bootstrap(boolean) to register every information-system-model type. When OrientDB does not answer, ensureDatabase() fails and the next call tries again, so a service started before its database works as soon as the database answers.

Author:
Luca Frosini (ISTI - CNR)
  • Field Details

    • DISCOVER_ALL_REGISTRATION_PROVIDERS

      public static final boolean DISCOVER_ALL_REGISTRATION_PROVIDERS
      Whether bootstrap Discovery scans packages contributed by external RegistrationProvider SPI implementations (e.g. gcube-model's), in addition to information-system-model's own intrinsic packages (always scanned regardless). Defaults to false when absent from "service.yaml" — harmless in production, where no such SPI-contributed provider is ever present on the classpath; test environments that rely on an external provider's types (e.g. gcube-model) must set this explicitly to true. It also decides whether the domain provider identifies the model (ModelIdentityResolver) and whether a migration realigns its types.
    • RUNTIME_MODEL_NAME

      public static final String RUNTIME_MODEL_NAME
      Operator-declared name of the runtime model, the one holding the types created through REST (see ModelIdentityResolver). null when absent from "service.yaml": the resolver's default applies.
    • DEFAULT_ADMIN_ROLE

      public static final String DEFAULT_ADMIN_ROLE
      The default administrative role name.
      See Also:
    • DEFAULT_PASSWORDS

      public static final Map<Environment.PermissionMode,String> DEFAULT_PASSWORDS
      Default passwords for the read/write database accounts.
    • DB_URI

      public static final String DB_URI
      The database server URI.
    • CONNECTION_STRATEGY_PARAMETER

      public static final com.orientechnologies.orient.client.remote.OStorageRemote.CONNECTION_STRATEGY CONNECTION_STRATEGY_PARAMETER
      The connection strategy parameter to use.
    • DB_KEY_FILENAME_VARNAME

      protected static final String DB_KEY_FILENAME_VARNAME
      INI variable name for key file.
      See Also:
    • DB_KEY_ALGORITHM_VARNAME

      protected static final String DB_KEY_ALGORITHM_VARNAME
      INI variable name for key algorithm.
      See Also:
    • VERTEX_CLASS_NAME

      public static final String VERTEX_CLASS_NAME
      OrientDB standard Vertex class name.
      See Also:
    • EDGE_CLASS_NAME

      public static final String EDGE_CLASS_NAME
      OrientDB standard Edge class name.
      See Also:
  • Constructor Details

    • DatabaseEnvironment

      public DatabaseEnvironment()
  • Method Details

    • ensureDatabase

      public static void ensureDatabase()
      Makes sure the database answers and, the first time, that it is prepared: creates it with its partitions and types when it does not exist yet. A failure is not remembered: the next call tries again.
      Throws:
      RuntimeException - when OrientDB does not answer or the database cannot be prepared
    • initDbKey

      protected static Key initDbKey(Map<String,String> dbSection)
      Initializes the database key.
      Parameters:
      dbSection - the database section of the configuration profile
      Returns:
      the initialized key
    • setDateTimeFormat

      protected static void setDateTimeFormat(com.orientechnologies.orient.core.db.document.ODatabaseDocument oDatabaseDocument)
      Sets the datetime format attribute for the given database connection.
      Parameters:
      oDatabaseDocument - the OrientDB database connection
    • setRecordLevelSecurity

      @Deprecated protected static void setRecordLevelSecurity(com.orientechnologies.orient.core.metadata.OMetadata oMetadata)
      Deprecated.
      This code must be removed for OrientDB versions higher than 3.2.X
      Configures Record-Level Security (RLS) on Vertex and Edge classes.
      Parameters:
      oMetadata - the OrientDB schema metadata
    • getDatabaseKey

      public static Key getDatabaseKey()
      Returns the initialized database cryptographic symmetric key.
      Returns:
      the symmetric database key
    • changeDefaultAdminPassword

      @Deprecated public static void changeDefaultAdminPassword(com.orientechnologies.orient.core.metadata.security.OSecurity oSecurity)
      Deprecated.
      This code must be removed for OrientDB versions higher than 3.2.X
      Changes the default passwords for database administrative accounts.
      Parameters:
      oSecurity - the OrientDB security context