Package tigase.db.util

## Class SchemaLoader<P extends SchemaLoader.Parameters>

- java.lang.Object
- - tigase.db.util.SchemaLoader<P>

- Direct Known Subclasses:
    `DBSchemaLoader`

      public abstract class SchemaLoader<P extends SchemaLoader.Parameters>
      extends java.lang.Object

  Author:
    andrzej

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static interface` | `SchemaLoader.Parameters` |
    `static class` | `SchemaLoader.Result` |
    `static class` | `SchemaLoader.TypeInfo` |

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected static java.util.logging.Logger` | `log` |

  - ### Constructor Summary

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

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `protected <T extends DataSource> SchemaLoader.Result` | `addUsersToRepository​(SchemaManager.SchemaInfo schemaInfo, T dataSource, java.lang.Class<T> dataSourceClass, java.util.List<BareJID> jids, java.lang.String password, java.util.logging.Logger log)` |
    `protected java.util.function.Function<AuthRepository,​SchemaLoader.Result>` | `addUsersToRepositoryFunction​(java.util.List<BareJID> jids, java.lang.String pwd, java.util.logging.Logger log)` |
    `abstract SchemaLoader.Result` | `addXmppAdminAccount​(SchemaManager.SchemaInfo schemaInfo)` | Method attempts to add XMPP admin user account to the database using `AuthRepository`.
    `abstract P` | `createParameters()` |
    `abstract SchemaLoader.Result` | `destroyDataSource()` |
    `abstract void` | `execute​(SchemaLoader.Parameters params)` |
    `static java.util.List<SchemaLoader.TypeInfo>` | `getAllSupportedTypes()` |
    `static java.util.stream.Stream<SchemaLoader.TypeInfo>` | `getAllSupportedTypesStream()` |
    `abstract java.util.List<CommandlineParameter>` | `getCommandlineParameters()` |
    `abstract java.util.Optional<Version>` | `getComponentVersionFromDb​(java.lang.String component)` |
    `protected java.lang.String` | `getConfigString()` |
    `protected <DS extends DataSource> java.util.stream.Stream<java.lang.Class<DataSourceAware<DS>>>` | `getDataSourceAwareClassesForSchemaInfo​(SchemaManager.SchemaInfo schema, java.lang.Class<DS> dataSourceIfc)` |
    `abstract java.lang.String` | `getDBUri()` |
    `protected <DSIFC extends DataSource,​DS extends DSIFC> java.util.stream.Stream<DataSourceAware>` | `getInitializedDataSourceAwareForSchemaInfo​(SchemaManager.SchemaInfo schema, java.lang.Class<DSIFC> dataSourceIfc, DS dataSource, java.util.logging.Logger log)` |
    `static java.util.List<CommandlineParameter>` | `getMainCommandlineParameters​(boolean forceNotRequired)` |
    `abstract java.util.Optional<Version>` | `getMinimalRequiredComponentVersionForUpgrade​(SchemaManager.SchemaInfo schema)` |
    `abstract java.util.List<CommandlineParameter>` | `getSetupOptions()` |
    `abstract java.util.List<SchemaLoader.TypeInfo>` | `getSupportedTypes()` |
    `protected java.lang.String` | `getType()` |
    `void` | `init​(P props)` |
    `abstract void` | `init​(P props, java.util.Optional<SchemaManager.RootCredentialsCache> rootCredentialsCache)` |
    `protected AuthRepository` | `initializeAuthRepository​(AuthRepository authRepository)` |
    `protected <T extends DataSource> java.util.function.Function<DataSourceAware<T>,​DataSourceAware<T>>` | `initializeDataSourceAwareFunction​(T dataSource, java.util.logging.Logger log)` |
    `protected <T> T` | `instantiateClass​(java.lang.Class<T> clazz)` |
    `boolean` | `isSupported​(java.lang.String dbType)` |
    `SchemaLoader.Result` | `loadCommonSchema()` |
    `abstract SchemaLoader.Result` | `loadSchema​(SchemaManager.SchemaInfo schemaInfo, java.lang.String version)` |
    `abstract 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.
    `static SchemaLoader` | `newInstance​(java.lang.String type)` |
    `static SchemaLoader` | `newInstanceForURI​(java.lang.String uri)` |
    `abstract SchemaLoader.Result` | `postInstallation()` |
    `SchemaLoader.Result` | `printInfo()` |
    `abstract SchemaLoader.Result` | `setComponentVersion​(java.lang.String component, java.lang.String version)` | Methods attempt to write to database loaded schema version for particular component
    `abstract SchemaLoader.Result` | `shutdown()` |
    `abstract SchemaLoader.Result` | `validateDBConnection()` | Method validates whether the connection can at least be eI stablished.
    `abstract SchemaLoader.Result` | `validateDBExists()` | Method, if the connection is validated by `validateDBConnection`, checks whether desired database exists.

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

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

- - ### Field Detail

    - #### log

          protected static final java.util.logging.Logger log

  - ### Constructor Detail

    - #### SchemaLoader

          public SchemaLoader()

  - ### Method Detail

    - #### getMainCommandlineParameters

          public static java.util.List<CommandlineParameter> getMainCommandlineParameters​(boolean forceNotRequired)

    - #### getAllSupportedTypesStream

          public static java.util.stream.Stream<SchemaLoader.TypeInfo> getAllSupportedTypesStream()

    - #### getAllSupportedTypes

          public static java.util.List<SchemaLoader.TypeInfo> getAllSupportedTypes()

    - #### 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.

    - #### newInstance

          public static SchemaLoader newInstance​(java.lang.String type)

    - #### newInstanceForURI

          public static SchemaLoader newInstanceForURI​(java.lang.String uri)

    - #### createParameters

          public abstract P createParameters()

    - #### execute

          public abstract void execute​(SchemaLoader.Parameters params)

    - #### init

          public abstract void init​(P props,
                                    java.util.Optional<SchemaManager.RootCredentialsCache> rootCredentialsCache)

    - #### init

          public void init​(P props)

    - #### getSupportedTypes

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

    - #### isSupported

          public boolean isSupported​(java.lang.String dbType)

    - #### getDBUri

          public abstract java.lang.String getDBUri()

    - #### getSetupOptions

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

    - #### getCommandlineParameters

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

    - #### validateDBConnection

          public abstract SchemaLoader.Result validateDBConnection()

      Method validates whether the connection can at least be eI stablished. If yes then appropriate flag is set.

    - #### validateDBExists

          public abstract SchemaLoader.Result validateDBExists()

      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.

    - #### postInstallation

          public abstract SchemaLoader.Result postInstallation()

    - #### getConfigString

          protected java.lang.String getConfigString()
                                              throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### printInfo

          public SchemaLoader.Result printInfo()

    - #### addXmppAdminAccount

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

      Method attempts to add XMPP admin user account to the database using `AuthRepository`.

    - #### setComponentVersion

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

      Methods attempt to write to database loaded schema version for particular component
      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 abstract java.util.Optional<Version> getComponentVersionFromDb​(java.lang.String component)

    - #### loadSchemaFile

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

      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.
      Parameters:
        `fileName` - set of `String` with path to file

    - #### shutdown

          public abstract SchemaLoader.Result shutdown()

    - #### loadCommonSchema

          public SchemaLoader.Result loadCommonSchema()

    - #### loadSchema

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

    - #### getMinimalRequiredComponentVersionForUpgrade

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

    - #### destroyDataSource

          public abstract SchemaLoader.Result destroyDataSource()

    - #### addUsersToRepository

          protected <T extends DataSource> SchemaLoader.Result addUsersToRepository​(SchemaManager.SchemaInfo schemaInfo,
                                                                                    T dataSource,
                                                                                    java.lang.Class<T> dataSourceClass,
                                                                                    java.util.List<BareJID> jids,
                                                                                    java.lang.String password,
                                                                                    java.util.logging.Logger log)

    - #### getDataSourceAwareClassesForSchemaInfo

          protected <DS extends DataSource> java.util.stream.Stream<java.lang.Class<DataSourceAware<DS>>> getDataSourceAwareClassesForSchemaInfo​(SchemaManager.SchemaInfo schema,
                                                                                                                                                 java.lang.Class<DS> dataSourceIfc)

    - #### getInitializedDataSourceAwareForSchemaInfo

          protected <DSIFC extends DataSource,​DS extends DSIFC> java.util.stream.Stream<DataSourceAware> getInitializedDataSourceAwareForSchemaInfo​(SchemaManager.SchemaInfo schema,
                                                                                                                                                          java.lang.Class<DSIFC> dataSourceIfc,
                                                                                                                                                          DS dataSource,
                                                                                                                                                          java.util.logging.Logger log)

    - #### initializeAuthRepository

          protected AuthRepository initializeAuthRepository​(AuthRepository authRepository)

    - #### initializeDataSourceAwareFunction

          protected <T extends DataSource> java.util.function.Function<DataSourceAware<T>,​DataSourceAware<T>> initializeDataSourceAwareFunction​(T dataSource,
                                                                                                                                                      java.util.logging.Logger log)

    - #### addUsersToRepositoryFunction

          protected java.util.function.Function<AuthRepository,​SchemaLoader.Result> addUsersToRepositoryFunction​(java.util.List<BareJID> jids,
                                                                                                                       java.lang.String pwd,
                                                                                                                       java.util.logging.Logger log)

    - #### instantiateClass

          protected <T> T instantiateClass​(java.lang.Class<T> clazz)

    - #### getType

          protected java.lang.String getType()