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 Exception,R>`
  `static class`
  `DBSchemaLoader.Parameters`
  `static enum`
  `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

  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(String query)`
  Method checks whether the connection to the database is possible and that database of specified name exists.
  `List<CommandlineParameter>`
  `getCommandlineParameters()`
  `Optional<Version>`
  `getComponentVersionFromDb(String component)`
  `String`
  `getDBUri()`
  `String`
  `getDBUri(boolean debug)`
  `Optional<Version>`
  `getMinimalRequiredComponentVersionForUpgrade(SchemaManager.SchemaInfo schema)`
  `Map<Version,Path>`
  `getSchemaFileNames(String schemaId)`
  `List<CommandlineParameter>`
  `getSetupOptions()`
  `List<SchemaLoader.TypeInfo>`
  `getSupportedTypes()`
  `void`
  `init(DBSchemaLoader.Parameters params, Optional<SchemaManager.RootCredentialsCache> rootCredentialsCache)`
  `SchemaLoader.Result`
  `loadSchema(SchemaManager.SchemaInfo schema, String version)`
  `SchemaLoader.Result`
  `loadSchemaFile(String fileName)`
  Method checks whether the connection to the database is possible and that database of specified name exists.
  `static void`
  `main(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(String component, 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 Details

  - ### DBSchemaLoader

    public DBSchemaLoader()

- ## Method Details

  - ### main

    public static void main(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, Optional<SchemaManager.RootCredentialsCache> rootCredentialsCache)
    Specified by:
      `init` in class `SchemaLoader<DBSchemaLoader.Parameters>`

  - ### getSupportedTypes

    public List<SchemaLoader.TypeInfo> getSupportedTypes()
    Specified by:
      `getSupportedTypes` in class `SchemaLoader<DBSchemaLoader.Parameters>`

  - ### getSchemaFileNames

    public Map<Version,Path> getSchemaFileNames(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(String component, 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 Optional<Version> getComponentVersionFromDb(String component)
    Specified by:
      `getComponentVersionFromDb` in class `SchemaLoader<DBSchemaLoader.Parameters>`

  - ### getMinimalRequiredComponentVersionForUpgrade

    public Optional<Version> getMinimalRequiredComponentVersionForUpgrade(SchemaManager.SchemaInfo schema)
    Specified by:
      `getMinimalRequiredComponentVersionForUpgrade` in class `SchemaLoader<DBSchemaLoader.Parameters>`

  - ### loadSchema

    public SchemaLoader.Result loadSchema(SchemaManager.SchemaInfo schema, String version)
    Specified by:
      `loadSchema` in class `SchemaLoader<DBSchemaLoader.Parameters>`

  - ### loadSchemaFile

    public SchemaLoader.Result loadSchemaFile(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 String getDBUri()
    Specified by:
      `getDBUri` in class `SchemaLoader<DBSchemaLoader.Parameters>`

  - ### getDBUri

    public String getDBUri(boolean debug)

  - ### getCommandlineParameters

    public List<CommandlineParameter> getCommandlineParameters()
    Specified by:
      `getCommandlineParameters` in class `SchemaLoader<DBSchemaLoader.Parameters>`

  - ### getSetupOptions

    public List<CommandlineParameter> getSetupOptions()
    Specified by:
      `getSetupOptions` in class `SchemaLoader<DBSchemaLoader.Parameters>`

  - ### executeSingleQuery

    protected SchemaLoader.Result executeSingleQuery(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