Package tigase.db.util
Class DBSchemaLoader
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
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 ClassesModifier and TypeClassDescriptionstatic interfaceDBSchemaLoader.ExceptionHandler<T extends Exception,R> static classstatic enumstatic interfaceNested classes/interfaces inherited from class tigase.db.util.SchemaLoader
SchemaLoader.Result, SchemaLoader.TypeInfo -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddXmppAdminAccount(SchemaManager.SchemaInfo schemaInfo) Method attempts to add XMPP admin user account to the database usingAuthRepository.voidexecute(SchemaLoader.Parameters params) Executes set ofDBSchemaLoader.TigaseDBTasktasks selected based on set on passed propertiesprotected SchemaLoader.ResultexecuteSingleQuery(String query) Method checks whether the connection to the database is possible and that database of specified name exists.getComponentVersionFromDb(String component) getDBUri()getDBUri(boolean debug) getSchemaFileNames(String schemaId) voidinit(DBSchemaLoader.Parameters params, Optional<SchemaManager.RootCredentialsCache> rootCredentialsCache) loadSchema(SchemaManager.SchemaInfo schema, String version) loadSchemaFile(String fileName) Method checks whether the connection to the database is possible and that database of specified name exists.static voidMain method allowing pass arguments to the class and setting all logging to be printed to console.Method performs post-installation action using using*-installer-post.sqlschema file substituting it's variables with ones provided.Method performs post-installation action using using*-installer-post.sqlschema file substituting it's variables with ones provided.setComponentVersion(String component, String version) Methods attempt to write to database loaded schema version for particular componentshutdown()Method validates whether the connection can at least be eI stablished.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, getDefaultSupportedTypeForName, getInitializedDataSourceAwareForSchemaInfo, getMainCommandlineParameters, getSupportedTypeForName, getType, init, initializeAuthRepository, initializeDataSourceAwareFunction, instantiateClass, isSupported, loadCommonSchema, newInstance, newInstanceForURI
-
Constructor Details
-
DBSchemaLoader
public DBSchemaLoader()
-
-
Method Details
-
main
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:
initin classSchemaLoader<DBSchemaLoader.Parameters>
-
getSupportedTypes
- Specified by:
getSupportedTypesin classSchemaLoader<DBSchemaLoader.Parameters>
-
getSchemaFileNames
-
createParameters
- Specified by:
createParametersin classSchemaLoader<DBSchemaLoader.Parameters>
-
execute
Executes set ofDBSchemaLoader.TigaseDBTasktasks selected based on set on passed properties- Specified by:
executein classSchemaLoader<DBSchemaLoader.Parameters>- Parameters:
params- set of configuration parameters.
-
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
- Specified by:
shutdownin classSchemaLoader<DBSchemaLoader.Parameters>
-
shutdownDerby
-
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
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
Method performs post-installation action using using*-installer-post.sqlschema file substituting it's variables with ones provided.- Overrides:
printInfoin classSchemaLoader<DBSchemaLoader.Parameters>
-
addXmppAdminAccount
Description copied from class:SchemaLoaderMethod attempts to add XMPP admin user account to the database usingAuthRepository.- Specified by:
addXmppAdminAccountin classSchemaLoader<DBSchemaLoader.Parameters>
-
setComponentVersion
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
- Specified by:
getComponentVersionFromDbin classSchemaLoader<DBSchemaLoader.Parameters>
-
getMinimalRequiredComponentVersionForUpgrade
public Optional<Version> getMinimalRequiredComponentVersionForUpgrade(SchemaManager.SchemaInfo schema) - Specified by:
getMinimalRequiredComponentVersionForUpgradein classSchemaLoader<DBSchemaLoader.Parameters>
-
loadSchema
- Specified by:
loadSchemain classSchemaLoader<DBSchemaLoader.Parameters>
-
loadSchemaFile
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
- Specified by:
destroyDataSourcein classSchemaLoader<DBSchemaLoader.Parameters>
-
getDBUri
- Specified by:
getDBUriin classSchemaLoader<DBSchemaLoader.Parameters>
-
getDBUri
-
getCommandlineParameters
- Specified by:
getCommandlineParametersin classSchemaLoader<DBSchemaLoader.Parameters>
-
getSetupOptions
- Specified by:
getSetupOptionsin classSchemaLoader<DBSchemaLoader.Parameters>
-
executeSingleQuery
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
-