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
Modifier and TypeClassDescriptionstatic interface
DBSchemaLoader.ExceptionHandler<T extends Exception,
R> static class
static enum
static interface
Nested classes/interfaces inherited from class tigase.db.util.SchemaLoader
SchemaLoader.Result, SchemaLoader.TypeInfo
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddXmppAdminAccount
(SchemaManager.SchemaInfo schemaInfo) Method attempts to add XMPP admin user account to the database usingAuthRepository
.void
execute
(SchemaLoader.Parameters params) Executes set ofDBSchemaLoader.TigaseDBTask
tasks selected based on set on passed propertiesprotected SchemaLoader.Result
executeSingleQuery
(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) void
init
(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 void
Main 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.sql
schema file substituting it's variables with ones provided.Method performs post-installation action using using*-installer-post.sql
schema 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, getInitializedDataSourceAwareForSchemaInfo, getMainCommandlineParameters, 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:
init
in classSchemaLoader<DBSchemaLoader.Parameters>
-
getSupportedTypes
- Specified by:
getSupportedTypes
in classSchemaLoader<DBSchemaLoader.Parameters>
-
getSchemaFileNames
-
createParameters
- Specified by:
createParameters
in classSchemaLoader<DBSchemaLoader.Parameters>
-
execute
Executes set ofDBSchemaLoader.TigaseDBTask
tasks selected based on set on passed properties- Specified by:
execute
in classSchemaLoader<DBSchemaLoader.Parameters>
- Parameters:
params
- set of configuration parameters.
-
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 classSchemaLoader<DBSchemaLoader.Parameters>
-
shutdown
- Specified by:
shutdown
in classSchemaLoader<DBSchemaLoader.Parameters>
-
shutdownDerby
-
validateDBExists
Description copied from class:SchemaLoader
Method, if the connection is validated byvalidateDBConnection
, 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 classSchemaLoader<DBSchemaLoader.Parameters>
-
postInstallation
Method performs post-installation action using using*-installer-post.sql
schema file substituting it's variables with ones provided.- Specified by:
postInstallation
in classSchemaLoader<DBSchemaLoader.Parameters>
-
printInfo
Method performs post-installation action using using*-installer-post.sql
schema file substituting it's variables with ones provided.- Overrides:
printInfo
in classSchemaLoader<DBSchemaLoader.Parameters>
-
addXmppAdminAccount
Description copied from class:SchemaLoader
Method attempts to add XMPP admin user account to the database usingAuthRepository
.- Specified by:
addXmppAdminAccount
in classSchemaLoader<DBSchemaLoader.Parameters>
-
setComponentVersion
Description copied from class:SchemaLoader
Methods attempt to write to database loaded schema version for particular component- Specified by:
setComponentVersion
in 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.Result
object indicating whether the call was successful
-
getComponentVersionFromDb
- Specified by:
getComponentVersionFromDb
in classSchemaLoader<DBSchemaLoader.Parameters>
-
getMinimalRequiredComponentVersionForUpgrade
public Optional<Version> getMinimalRequiredComponentVersionForUpgrade(SchemaManager.SchemaInfo schema) - Specified by:
getMinimalRequiredComponentVersionForUpgrade
in classSchemaLoader<DBSchemaLoader.Parameters>
-
loadSchema
- Specified by:
loadSchema
in classSchemaLoader<DBSchemaLoader.Parameters>
-
loadSchemaFile
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 classSchemaLoader<DBSchemaLoader.Parameters>
- Parameters:
fileName
- set ofString
with path to file
-
destroyDataSource
- Specified by:
destroyDataSource
in classSchemaLoader<DBSchemaLoader.Parameters>
-
getDBUri
- Specified by:
getDBUri
in classSchemaLoader<DBSchemaLoader.Parameters>
-
getDBUri
-
getCommandlineParameters
- Specified by:
getCommandlineParameters
in classSchemaLoader<DBSchemaLoader.Parameters>
-
getSetupOptions
- Specified by:
getSetupOptions
in 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
-