Package tigase.db.util

## Class DBSchemaLoader

- java.lang.Object
- - tigase.db.util.SchemaLoader<DBSchemaLoader.Parameters>
  - - tigase.db.util.DBSchemaLoader

-     public class DBSchemaLoader
      extends SchemaLoader<DBSchemaLoader.Parameters>

  Simple utility class allowing various Database operations, including executing simple queries, loading specific schema files or performing complete load of all Tigase schema required to run the server.
  Following set of `Properties` is accepted:
  - `dbType` - type of the database, possible values are: `mysql`, `postgresql`, `derby`, `sqlserver`;
  - `schemaVersion` - schema version to be loaded, , possible values are: `7-2`, `7-1`, `5-1`, `5`, `4`;
  - `dbName` - name of the database to be created/used;
  - `dbHostname` - hostname of the database;
  - `dbUser` - username of the regular user;
  - `dbPass` - password of the regular user;
  - `rootUser` - username of the database administrator user;
  - `rootPass` - password of the database administrator user;
  - `query` - simple, single query to be executed;
  - `file` - path to the single schema file to be loaded to the database;
  - `adminJID` - JID address of the XMPP administrator account;
  - `adminJIDpass` - password of the XMPP administrator account.
  Author:
    wojtek

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static interface` | `DBSchemaLoader.ExceptionHandler<T extends java.lang.Exception,​R>` |
    `static class` | `DBSchemaLoader.Parameters` |
    `static class` | `DBSchemaLoader.PARAMETERS_ENUM` |
    `static interface` | `DBSchemaLoader.SQLCommand<C,​R>` |

    - ### Nested classes/interfaces inherited from class tigase.db.util.SchemaLoader

      `SchemaLoader.Result, SchemaLoader.TypeInfo`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `DBSchemaLoader()` |

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `SchemaLoader.Result` | `addXmppAdminAccount​(SchemaManager.SchemaInfo schemaInfo)` | Method attempts to add XMPP admin user account to the database using `AuthRepository`.
    `DBSchemaLoader.Parameters` | `createParameters()` |
    `SchemaLoader.Result` | `destroyDataSource()` |
    `void` | `execute​(SchemaLoader.Parameters params)` | Executes set of `DBSchemaLoader.TigaseDBTask` tasks selected based on set on passed properties
    `protected SchemaLoader.Result` | `executeSingleQuery​(java.lang.String query)` | Method checks whether the connection to the database is possible and that database of specified name exists.
    `java.util.List<CommandlineParameter>` | `getCommandlineParameters()` |
    `java.util.Optional<Version>` | `getComponentVersionFromDb​(java.lang.String component)` |
    `java.lang.String` | `getDBUri()` |
    `java.lang.String` | `getDBUri​(boolean debug)` |
    `java.util.Optional<Version>` | `getMinimalRequiredComponentVersionForUpgrade​(SchemaManager.SchemaInfo schema)` |
    `java.util.Map<Version,​java.nio.file.Path>` | `getSchemaFileNames​(java.lang.String schemaId)` |
    `java.util.List<CommandlineParameter>` | `getSetupOptions()` |
    `java.util.List<SchemaLoader.TypeInfo>` | `getSupportedTypes()` |
    `void` | `init​(DBSchemaLoader.Parameters params, java.util.Optional<SchemaManager.RootCredentialsCache> rootCredentialsCache)` |
    `SchemaLoader.Result` | `loadSchema​(SchemaManager.SchemaInfo schema, java.lang.String version)` |
    `SchemaLoader.Result` | `loadSchemaFile​(java.lang.String fileName)` | Method checks whether the connection to the database is possible and that database of specified name exists.
    `static void` | `main​(java.lang.String[] args)` | Main method allowing pass arguments to the class and setting all logging to be printed to console.
    `SchemaLoader.Result` | `postInstallation()` | Method performs post-installation action using using `*-installer-post.sql` schema file substituting it's variables with ones provided.
    `SchemaLoader.Result` | `printInfo()` | Method performs post-installation action using using `*-installer-post.sql` schema file substituting it's variables with ones provided.
    `SchemaLoader.Result` | `setComponentVersion​(java.lang.String component, java.lang.String version)` | Methods attempt to write to database loaded schema version for particular component
    `SchemaLoader.Result` | `shutdown()` |
    `SchemaLoader.Result` | `shutdownDerby()` |
    `SchemaLoader.Result` | `validateDBConnection()` | Method validates whether the connection can at least be eI stablished.
    `SchemaLoader.Result` | `validateDBExists()` | Method, if the connection is validated by `validateDBConnection`, checks whether desired database exists.

    - ### Methods inherited from class tigase.db.util.SchemaLoader

      `addUsersToRepository, addUsersToRepositoryFunction, getAllSupportedTypes, getAllSupportedTypesStream, getConfigString, getDataSourceAwareClassesForSchemaInfo, getInitializedDataSourceAwareForSchemaInfo, getMainCommandlineParameters, getType, init, initializeAuthRepository, initializeDataSourceAwareFunction, instantiateClass, isSupported, loadCommonSchema, newInstance, newInstanceForURI`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DBSchemaLoader

          public DBSchemaLoader()

  - ### Method Detail

    - #### main

          public static void main​(java.lang.String[] args)

      Main method allowing pass arguments to the class and setting all logging to be printed to console.
      Parameters:
        `args` - key-value (in the form of `"-<variable> value"`) parameters.

    - #### init

          public void init​(DBSchemaLoader.Parameters params,
                           java.util.Optional<SchemaManager.RootCredentialsCache> rootCredentialsCache)

      Specified by:
        `init` in class `SchemaLoader<DBSchemaLoader.Parameters>`

    - #### getSupportedTypes

          public java.util.List<SchemaLoader.TypeInfo> getSupportedTypes()

      Specified by:
        `getSupportedTypes` in class `SchemaLoader<DBSchemaLoader.Parameters>`

    - #### getSchemaFileNames

          public java.util.Map<Version,​java.nio.file.Path> getSchemaFileNames​(java.lang.String schemaId)

    - #### createParameters

          public DBSchemaLoader.Parameters createParameters()

      Specified by:
        `createParameters` in class `SchemaLoader<DBSchemaLoader.Parameters>`

    - #### execute

          public void execute​(SchemaLoader.Parameters params)

      Executes set of `DBSchemaLoader.TigaseDBTask` tasks selected based on set on passed properties
      Specified by:
        `execute` in class `SchemaLoader<DBSchemaLoader.Parameters>`
      Parameters:
        `params` - set of configuration parameters.

    - #### validateDBConnection

          public SchemaLoader.Result validateDBConnection()

      Description copied from class: `SchemaLoader`
      Method validates whether the connection can at least be eI stablished. If yes then appropriate flag is set.
      Specified by:
        `validateDBConnection` in class `SchemaLoader<DBSchemaLoader.Parameters>`

    - #### shutdown

          public SchemaLoader.Result shutdown()

      Specified by:
        `shutdown` in class `SchemaLoader<DBSchemaLoader.Parameters>`

    - #### shutdownDerby

          public SchemaLoader.Result shutdownDerby()

    - #### validateDBExists

          public SchemaLoader.Result validateDBExists()

      Description copied from class: `SchemaLoader`
      Method, if the connection is validated by `validateDBConnection`, checks whether desired database exists. If not it creates such database using `*-installer-create-db.sql` schema file substituting it's variables with ones provided.
      Specified by:
        `validateDBExists` in class `SchemaLoader<DBSchemaLoader.Parameters>`

    - #### postInstallation

          public SchemaLoader.Result postInstallation()

      Method performs post-installation action using using `*-installer-post.sql` schema file substituting it's variables with ones provided.
      Specified by:
        `postInstallation` in class `SchemaLoader<DBSchemaLoader.Parameters>`

    - #### printInfo

          public SchemaLoader.Result printInfo()

      Method performs post-installation action using using `*-installer-post.sql` schema file substituting it's variables with ones provided.
      Overrides:
        `printInfo` in class `SchemaLoader<DBSchemaLoader.Parameters>`

    - #### addXmppAdminAccount

          public SchemaLoader.Result addXmppAdminAccount​(SchemaManager.SchemaInfo schemaInfo)

      Description copied from class: `SchemaLoader`
      Method attempts to add XMPP admin user account to the database using `AuthRepository`.
      Specified by:
        `addXmppAdminAccount` in class `SchemaLoader<DBSchemaLoader.Parameters>`

    - #### setComponentVersion

          public SchemaLoader.Result setComponentVersion​(java.lang.String component,
                                                         java.lang.String version)

      Description copied from class: `SchemaLoader`
      Methods attempt to write to database loaded schema version for particular component
      Specified by:
        `setComponentVersion` in class `SchemaLoader<DBSchemaLoader.Parameters>`
      Parameters:
        `component` - name of the component for which version should be set
        `version` - value which should be associated with the component
      Returns:
        a `SchemaLoader.Result` object indicating whether the call was successful

    - #### getComponentVersionFromDb

          public java.util.Optional<Version> getComponentVersionFromDb​(java.lang.String component)

      Specified by:
        `getComponentVersionFromDb` in class `SchemaLoader<DBSchemaLoader.Parameters>`

    - #### getMinimalRequiredComponentVersionForUpgrade

          public java.util.Optional<Version> getMinimalRequiredComponentVersionForUpgrade​(SchemaManager.SchemaInfo schema)

      Specified by:
        `getMinimalRequiredComponentVersionForUpgrade` in class `SchemaLoader<DBSchemaLoader.Parameters>`

    - #### loadSchema

          public SchemaLoader.Result loadSchema​(SchemaManager.SchemaInfo schema,
                                                java.lang.String version)

      Specified by:
        `loadSchema` in class `SchemaLoader<DBSchemaLoader.Parameters>`

    - #### loadSchemaFile

          public SchemaLoader.Result loadSchemaFile​(java.lang.String fileName)

      Description copied from class: `SchemaLoader`
      Method checks whether the connection to the database is possible and that database of specified name exists. If yes then a schema file from properties is loaded.
      Specified by:
        `loadSchemaFile` in class `SchemaLoader<DBSchemaLoader.Parameters>`
      Parameters:
        `fileName` - set of `String` with path to file

    - #### destroyDataSource

          public SchemaLoader.Result destroyDataSource()

      Specified by:
        `destroyDataSource` in class `SchemaLoader<DBSchemaLoader.Parameters>`

    - #### getDBUri

          public java.lang.String getDBUri()

      Specified by:
        `getDBUri` in class `SchemaLoader<DBSchemaLoader.Parameters>`

    - #### getDBUri

          public java.lang.String getDBUri​(boolean debug)

    - #### getCommandlineParameters

          public java.util.List<CommandlineParameter> getCommandlineParameters()

      Specified by:
        `getCommandlineParameters` in class `SchemaLoader<DBSchemaLoader.Parameters>`

    - #### getSetupOptions

          public java.util.List<CommandlineParameter> getSetupOptions()

      Specified by:
        `getSetupOptions` in class `SchemaLoader<DBSchemaLoader.Parameters>`

    - #### executeSingleQuery

          protected SchemaLoader.Result executeSingleQuery​(java.lang.String query)

      Method checks whether the connection to the database is possible and that database of specified name exists. If yes then a single query is executed.
      Parameters:
        `query` - to execute