Package org.opencms.setup
Class CmsSetupDb
java.lang.Object
org.opencms.setup.CmsSetupDb
Helper class to call database setup scripts.
- Since:
- 6.0.0
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncheckVariables
(String db) Returns an optional warning message if needed,null
if not.void
Clears the error messages stored internally.void
Closes the internal connection to the database.void
createDatabase
(String database, Map<String, String> replacer) Calls the create database script for the given database.void
createDatabase
(String database, Map<String, String> replacer, boolean abortOnError) Calls the create database script for the given database.void
createTables
(String database, Map<String, String> replacer) Calls the create tables script for the given database.void
createTables
(String database, Map<String, String> replacer, boolean abortOnError) Calls the create tables script for the given database.void
dropDatabase
(String database, Map<String, String> replacer) Calls the drop script for the given database.void
dropDatabase
(String database, Map<String, String> replacer, boolean abortOnError) Calls the drop script for the given database.void
dropTables
(String database) Calls the drop tables script for the given database.void
dropTables
(String database, Map<String, String> replacer) Calls the drop tables script for the given database.void
dropTables
(String database, Map<String, String> replacer, boolean abortOnError) Calls the drop tables script for the given database.executeSqlStatement
(String query, Map<String, String> replacer) Creates and executes a database statement from a String returning the result set.Creates and executes a database statement from a String returning the result set.Returns the connection.Returns a Vector of Error messages.boolean
hasTableOrColumn
(String table, String column) Checks if the given table, column or combination of both is available in the database in case insensitive way.boolean
hasTableOrColumnCaseSensitive
(String table, String column) Checks if the given table, column or combination of both is available in the database in a case sensitive way.boolean
noErrors()
Checks if internal errors occurred.void
Creates a new internal connection to the database.void
setConnection
(String DbDriver, String DbConStr, String DbConStrParams, String DbUser, String DbPwd, boolean logErrors) Creates a new internal connection to the database.void
setConnection
(Connection conn) Sets a new internal connection to the database.void
updateDatabase
(String updateScript, Map<String, String> replacers) Calls an update script.void
updateDatabase
(String updateScript, Map<String, String> replacers, boolean abortOnError) Calls an update script.int
Creates and executes a database statment from a String.
-
Field Details
-
SETUP_DATA_FOLDER
The folder where to read the setup data from.- See Also:
-
SETUP_FOLDER
The folder where the setup wizard is located.
-
-
Constructor Details
-
CmsSetupDb
Creates a new CmsSetupDb object.- Parameters:
basePath
- the location of the setup scripts
-
-
Method Details
-
checkVariables
Returns an optional warning message if needed,null
if not.- Parameters:
db
- the selected database key- Returns:
- html warning, or
null
if no warning
-
clearErrors
Clears the error messages stored internally. -
closeConnection
Closes the internal connection to the database. -
createDatabase
Calls the create database script for the given database.- Parameters:
database
- the name of the databasereplacer
- the replacements to perform in the drop script
-
createDatabase
Calls the create database script for the given database.- Parameters:
database
- the name of the databasereplacer
- the replacements to perform in the drop scriptabortOnError
- indicates if the script is aborted if an error occurs
-
createTables
Calls the create tables script for the given database.- Parameters:
database
- the name of the databasereplacer
- the replacements to perform in the drop script
-
createTables
Calls the create tables script for the given database.- Parameters:
database
- the name of the databasereplacer
- the replacements to perform in the drop scriptabortOnError
- indicates if the script is aborted if an error occurs
-
dropDatabase
Calls the drop script for the given database.- Parameters:
database
- the name of the databasereplacer
- the replacements to perform in the drop script
-
dropDatabase
Calls the drop script for the given database.- Parameters:
database
- the name of the databasereplacer
- the replacements to perform in the drop scriptabortOnError
- indicates if the script is aborted if an error occurs
-
dropTables
Calls the drop tables script for the given database.- Parameters:
database
- the name of the database
-
dropTables
Calls the drop tables script for the given database.- Parameters:
database
- the name of the databasereplacer
- the replacements to perform in the drop script
-
dropTables
Calls the drop tables script for the given database.- Parameters:
database
- the name of the databasereplacer
- the replacements to perform in the drop scriptabortOnError
- indicates if the script is aborted if an error occurs
-
executeSqlStatement
public CmsSetupDBWrapper executeSqlStatement(String query, Map<String, String> replacer) throws SQLExceptionCreates and executes a database statement from a String returning the result set.- Parameters:
query
- the query to executereplacer
- the replacements to perform in the script- Returns:
- the result set of the query
- Throws:
SQLException
- if something goes wrong
-
executeSqlStatement
public CmsSetupDBWrapper executeSqlStatement(String query, Map<String, String> replacer, List<Object> params) throws SQLExceptionCreates and executes a database statement from a String returning the result set.- Parameters:
query
- the query to executereplacer
- the replacements to perform in the scriptparams
- the list of parameters for the statement- Returns:
- the result set of the query
- Throws:
SQLException
- if something goes wrong
-
getConnection
Returns the connection.- Returns:
- the connection
-
getErrors
Returns a Vector of Error messages.- Returns:
- all error messages collected internally
-
hasTableOrColumn
Checks if the given table, column or combination of both is available in the database in case insensitive way.- Parameters:
table
- the sought tablecolumn
- the sought column- Returns:
- true if the requested table/column is available, false if not
-
hasTableOrColumnCaseSensitive
Checks if the given table, column or combination of both is available in the database in a case sensitive way.- Parameters:
table
- the sought tablecolumn
- the sought column- Returns:
- true if the requested table/column is available, false if not
-
noErrors
Checks if internal errors occurred.- Returns:
- true if internal errors occurred
-
setConnection
Sets a new internal connection to the database.- Parameters:
conn
- the connection to use
-
setConnection
public void setConnection(String DbDriver, String DbConStr, String DbConStrParams, String DbUser, String DbPwd) Creates a new internal connection to the database.- Parameters:
DbDriver
- JDBC driver class nameDbConStr
- JDBC connect URLDbConStrParams
- JDBC connect URL params, or nullDbUser
- JDBC database userDbPwd
- JDBC database password
-
setConnection
public void setConnection(String DbDriver, String DbConStr, String DbConStrParams, String DbUser, String DbPwd, boolean logErrors) Creates a new internal connection to the database.- Parameters:
DbDriver
- JDBC driver class nameDbConStr
- JDBC connect URLDbConStrParams
- JDBC connect URL params, or nullDbUser
- JDBC database userDbPwd
- JDBC database passwordlogErrors
- if set to 'true', errors are written to the log file
-
updateDatabase
Calls an update script.- Parameters:
updateScript
- the update script codereplacers
- the replacers to use in the script code
-
updateDatabase
Calls an update script.- Parameters:
updateScript
- the update script codereplacers
- the replacers to use in the script codeabortOnError
- indicates if the script is aborted if an error occurs
-
updateSqlStatement
public int updateSqlStatement(String query, Map<String, String> replacer, List<Object> params) throws SQLExceptionCreates and executes a database statment from a String.- Parameters:
query
- the query to executereplacer
- the replacements to perform in the scriptparams
- the list of parameters for the statement- Returns:
- the result set of the query
- Throws:
SQLException
- if something goes wrong
-