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 ofPropertiesis 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 interfaceDBSchemaLoader.ExceptionHandler<T extends java.lang.Exception,R>static classDBSchemaLoader.Parametersstatic classDBSchemaLoader.PARAMETERS_ENUMstatic interfaceDBSchemaLoader.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.ResultaddXmppAdminAccount(SchemaManager.SchemaInfo schemaInfo)Method attempts to add XMPP admin user account to the database usingAuthRepository.DBSchemaLoader.ParameterscreateParameters()SchemaLoader.ResultdestroyDataSource()voidexecute(SchemaLoader.Parameters params)Executes set ofDBSchemaLoader.TigaseDBTasktasks selected based on set on passed propertiesprotected SchemaLoader.ResultexecuteSingleQuery(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.StringgetDBUri()java.lang.StringgetDBUri(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()voidinit(DBSchemaLoader.Parameters params, java.util.Optional<SchemaManager.RootCredentialsCache> rootCredentialsCache)SchemaLoader.ResultloadSchema(SchemaManager.SchemaInfo schema, java.lang.String version)SchemaLoader.ResultloadSchemaFile(java.lang.String fileName)Method checks whether the connection to the database is possible and that database of specified name exists.static voidmain(java.lang.String[] args)Main method allowing pass arguments to the class and setting all logging to be printed to console.SchemaLoader.ResultpostInstallation()Method performs post-installation action using using*-installer-post.sqlschema file substituting it's variables with ones provided.SchemaLoader.ResultprintInfo()Method performs post-installation action using using*-installer-post.sqlschema file substituting it's variables with ones provided.SchemaLoader.ResultsetComponentVersion(java.lang.String component, java.lang.String version)Methods attempt to write to database loaded schema version for particular componentSchemaLoader.Resultshutdown()SchemaLoader.ResultshutdownDerby()SchemaLoader.ResultvalidateDBConnection()Method validates whether the connection can at least be eI stablished.SchemaLoader.ResultvalidateDBExists()Method, if the connection is validated byvalidateDBConnection, 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
-
-
-
-
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:
initin classSchemaLoader<DBSchemaLoader.Parameters>
-
getSupportedTypes
public java.util.List<SchemaLoader.TypeInfo> getSupportedTypes()
- Specified by:
getSupportedTypesin classSchemaLoader<DBSchemaLoader.Parameters>
-
getSchemaFileNames
public java.util.Map<Version,java.nio.file.Path> getSchemaFileNames(java.lang.String schemaId)
-
createParameters
public DBSchemaLoader.Parameters createParameters()
- Specified by:
createParametersin classSchemaLoader<DBSchemaLoader.Parameters>
-
execute
public void execute(SchemaLoader.Parameters params)
Executes set ofDBSchemaLoader.TigaseDBTasktasks selected based on set on passed properties- Specified by:
executein classSchemaLoader<DBSchemaLoader.Parameters>- Parameters:
params- set of configuration parameters.
-
validateDBConnection
public SchemaLoader.Result validateDBConnection()
Description copied from class:SchemaLoaderMethod validates whether the connection can at least be eI stablished. If yes then appropriate flag is set.- Specified by:
validateDBConnectionin classSchemaLoader<DBSchemaLoader.Parameters>
-
shutdown
public SchemaLoader.Result shutdown()
- Specified by:
shutdownin classSchemaLoader<DBSchemaLoader.Parameters>
-
shutdownDerby
public SchemaLoader.Result shutdownDerby()
-
validateDBExists
public SchemaLoader.Result validateDBExists()
Description copied from class:SchemaLoaderMethod, if the connection is validated byvalidateDBConnection, checks whether desired database exists. If not it creates such database using*-installer-create-db.sqlschema file substituting it's variables with ones provided.- Specified by:
validateDBExistsin classSchemaLoader<DBSchemaLoader.Parameters>
-
postInstallation
public SchemaLoader.Result postInstallation()
Method performs post-installation action using using*-installer-post.sqlschema file substituting it's variables with ones provided.- Specified by:
postInstallationin classSchemaLoader<DBSchemaLoader.Parameters>
-
printInfo
public SchemaLoader.Result printInfo()
Method performs post-installation action using using*-installer-post.sqlschema file substituting it's variables with ones provided.- Overrides:
printInfoin classSchemaLoader<DBSchemaLoader.Parameters>
-
addXmppAdminAccount
public SchemaLoader.Result addXmppAdminAccount(SchemaManager.SchemaInfo schemaInfo)
Description copied from class:SchemaLoaderMethod attempts to add XMPP admin user account to the database usingAuthRepository.- Specified by:
addXmppAdminAccountin classSchemaLoader<DBSchemaLoader.Parameters>
-
setComponentVersion
public SchemaLoader.Result setComponentVersion(java.lang.String component, java.lang.String version)
Description copied from class:SchemaLoaderMethods attempt to write to database loaded schema version for particular component- Specified by:
setComponentVersionin classSchemaLoader<DBSchemaLoader.Parameters>- Parameters:
component- name of the component for which version should be setversion- value which should be associated with the component- Returns:
- a
SchemaLoader.Resultobject indicating whether the call was successful
-
getComponentVersionFromDb
public java.util.Optional<Version> getComponentVersionFromDb(java.lang.String component)
- Specified by:
getComponentVersionFromDbin classSchemaLoader<DBSchemaLoader.Parameters>
-
getMinimalRequiredComponentVersionForUpgrade
public java.util.Optional<Version> getMinimalRequiredComponentVersionForUpgrade(SchemaManager.SchemaInfo schema)
- Specified by:
getMinimalRequiredComponentVersionForUpgradein classSchemaLoader<DBSchemaLoader.Parameters>
-
loadSchema
public SchemaLoader.Result loadSchema(SchemaManager.SchemaInfo schema, java.lang.String version)
- Specified by:
loadSchemain classSchemaLoader<DBSchemaLoader.Parameters>
-
loadSchemaFile
public SchemaLoader.Result loadSchemaFile(java.lang.String fileName)
Description copied from class:SchemaLoaderMethod 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:
loadSchemaFilein classSchemaLoader<DBSchemaLoader.Parameters>- Parameters:
fileName- set ofStringwith path to file
-
destroyDataSource
public SchemaLoader.Result destroyDataSource()
- Specified by:
destroyDataSourcein classSchemaLoader<DBSchemaLoader.Parameters>
-
getDBUri
public java.lang.String getDBUri()
- Specified by:
getDBUriin classSchemaLoader<DBSchemaLoader.Parameters>
-
getDBUri
public java.lang.String getDBUri(boolean debug)
-
getCommandlineParameters
public java.util.List<CommandlineParameter> getCommandlineParameters()
- Specified by:
getCommandlineParametersin classSchemaLoader<DBSchemaLoader.Parameters>
-
getSetupOptions
public java.util.List<CommandlineParameter> getSetupOptions()
- Specified by:
getSetupOptionsin classSchemaLoader<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
-
-