org.opencms.setup
Class CmsSetupDb

java.lang.Object
  extended by org.opencms.setup.CmsSetupDb

public class CmsSetupDb
extends java.lang.Object

Helper class to call database setup scripts.

Since:
6.0.0
Version:
$Revision: 1.27 $
Author:
Thomas Weckert, Carsten Weinholz

Field Summary
static java.lang.String SETUP_DATA_FOLDER
          The folder where to read the setup data from.
static java.lang.String SETUP_FOLDER
          The folder where the setup wizard is located.
 
Constructor Summary
CmsSetupDb(java.lang.String basePath)
          Creates a new CmsSetupDb object.
 
Method Summary
 java.lang.String checkVariables(java.lang.String db)
          Returns an optional warning message if needed, null if not.
 void clearErrors()
          Clears the error messages stored internally.
 void closeConnection()
          Closes the internal connection to the database.
 void createDatabase(java.lang.String database, java.util.Map replacer)
          Calls the create database script for the given database.
 void createDatabase(java.lang.String database, java.util.Map replacer, boolean abortOnError)
          Calls the create database script for the given database.
 void createTables(java.lang.String database, java.util.Map replacer)
          Calls the create tables script for the given database.
 void createTables(java.lang.String database, java.util.Map replacer, boolean abortOnError)
          Calls the create tables script for the given database.
 void dropDatabase(java.lang.String database, java.util.Map replacer)
          Calls the drop script for the given database.
 void dropDatabase(java.lang.String database, java.util.Map replacer, boolean abortOnError)
          Calls the drop script for the given database.
 void dropTables(java.lang.String database)
          Calls the drop tables script for the given database.
 void dropTables(java.lang.String database, java.util.Map replacer)
          Calls the drop tables script for the given database.
 void dropTables(java.lang.String database, java.util.Map replacer, boolean abortOnError)
          Calls the drop tables script for the given database.
 java.sql.ResultSet executeSqlStatement(java.lang.String query, java.util.Map replacer)
          Creates and executes a database statment from a String returning the result set.
 java.sql.ResultSet executeSqlStatement(java.lang.String query, java.util.Map replacer, java.util.List params)
          Creates and executes a database statment from a String returning the result set.
protected  void finalize()
           
 java.sql.Connection getConnection()
          Returns the connection.
 java.util.Vector getErrors()
          Returns a Vector of Error messages.
 boolean hasTableOrColumn(java.lang.String table, java.lang.String column)
          Checks if the given table, column or combination of both is available in the database.
 boolean noErrors()
          Checks if internal errors occured.
 void setConnection(java.sql.Connection conn)
          Sets a new internal connection to teh database.
 void setConnection(java.lang.String DbDriver, java.lang.String DbConStr, java.lang.String DbConStrParams, java.lang.String DbUser, java.lang.String DbPwd)
          Creates a new internal connection to the database.
 void updateDatabase(java.lang.String updateScript, java.util.Map replacers)
          Calls an update script.
 void updateDatabase(java.lang.String updateScript, java.util.Map replacers, boolean abortOnError)
          Calls an update script.
 int updateSqlStatement(java.lang.String query, java.util.Map replacer, java.util.List params)
          Creates and executes a database statment from a String.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SETUP_DATA_FOLDER

public static final java.lang.String SETUP_DATA_FOLDER
The folder where to read the setup data from.

See Also:
Constant Field Values

SETUP_FOLDER

public static final java.lang.String SETUP_FOLDER
The folder where the setup wizard is located.

See Also:
Constant Field Values
Constructor Detail

CmsSetupDb

public CmsSetupDb(java.lang.String basePath)
Creates a new CmsSetupDb object.

Parameters:
basePath - the location of the setup scripts
Method Detail

checkVariables

public java.lang.String checkVariables(java.lang.String db)
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

public void clearErrors()
Clears the error messages stored internally.


closeConnection

public void closeConnection()
Closes the internal connection to the database.


createDatabase

public void createDatabase(java.lang.String database,
                           java.util.Map replacer)
Calls the create database script for the given database.

Parameters:
database - the name of the database
replacer - the replacements to perform in the drop script

createDatabase

public void createDatabase(java.lang.String database,
                           java.util.Map replacer,
                           boolean abortOnError)
Calls the create database script for the given database.

Parameters:
database - the name of the database
replacer - the replacements to perform in the drop script
abortOnError - indicates if the script is aborted if an error occurs

createTables

public void createTables(java.lang.String database,
                         java.util.Map replacer)
Calls the create tables script for the given database.

Parameters:
database - the name of the database
replacer - the replacements to perform in the drop script

createTables

public void createTables(java.lang.String database,
                         java.util.Map replacer,
                         boolean abortOnError)
Calls the create tables script for the given database.

Parameters:
database - the name of the database
replacer - the replacements to perform in the drop script
abortOnError - indicates if the script is aborted if an error occurs

dropDatabase

public void dropDatabase(java.lang.String database,
                         java.util.Map replacer)
Calls the drop script for the given database.

Parameters:
database - the name of the database
replacer - the replacements to perform in the drop script

dropDatabase

public void dropDatabase(java.lang.String database,
                         java.util.Map replacer,
                         boolean abortOnError)
Calls the drop script for the given database.

Parameters:
database - the name of the database
replacer - the replacements to perform in the drop script
abortOnError - indicates if the script is aborted if an error occurs

dropTables

public void dropTables(java.lang.String database)
Calls the drop tables script for the given database.

Parameters:
database - the name of the database

dropTables

public void dropTables(java.lang.String database,
                       java.util.Map replacer)
Calls the drop tables script for the given database.

Parameters:
database - the name of the database
replacer - the replacements to perform in the drop script

dropTables

public void dropTables(java.lang.String database,
                       java.util.Map replacer,
                       boolean abortOnError)
Calls the drop tables script for the given database.

Parameters:
database - the name of the database
replacer - the replacements to perform in the drop script
abortOnError - indicates if the script is aborted if an error occurs

executeSqlStatement

public java.sql.ResultSet executeSqlStatement(java.lang.String query,
                                              java.util.Map replacer)
                                       throws java.sql.SQLException
Creates and executes a database statment from a String returning the result set.

Parameters:
query - the query to execute
replacer - the replacements to perform in the script
Returns:
the result set of the query
Throws:
java.sql.SQLException - if something goes wrong

executeSqlStatement

public java.sql.ResultSet executeSqlStatement(java.lang.String query,
                                              java.util.Map replacer,
                                              java.util.List params)
                                       throws java.sql.SQLException
Creates and executes a database statment from a String returning the result set.

Parameters:
query - the query to execute
replacer - the replacements to perform in the script
params - the list of parameters for the statement
Returns:
the result set of the query
Throws:
java.sql.SQLException - if something goes wrong

getConnection

public java.sql.Connection getConnection()
Returns the connection.

Returns:
the connection

getErrors

public java.util.Vector getErrors()
Returns a Vector of Error messages.

Returns:
all error messages collected internally

hasTableOrColumn

public boolean hasTableOrColumn(java.lang.String table,
                                java.lang.String column)
Checks if the given table, column or combination of both is available in the database.

Parameters:
table - the sought table
column - the sought column
Returns:
true if the requested table/column is available, false if not

noErrors

public boolean noErrors()
Checks if internal errors occured.

Returns:
true if internal errors occured

setConnection

public void setConnection(java.sql.Connection conn)
Sets a new internal connection to teh database.

Parameters:
conn - the connection to use

setConnection

public void setConnection(java.lang.String DbDriver,
                          java.lang.String DbConStr,
                          java.lang.String DbConStrParams,
                          java.lang.String DbUser,
                          java.lang.String DbPwd)
Creates a new internal connection to the database.

Parameters:
DbDriver - JDBC driver class name
DbConStr - JDBC connect URL
DbConStrParams - JDBC connect URL params, or null
DbUser - JDBC database user
DbPwd - JDBC database password

updateDatabase

public void updateDatabase(java.lang.String updateScript,
                           java.util.Map replacers)
Calls an update script.

Parameters:
updateScript - the update script code
replacers - the replacers to use in the script code

updateDatabase

public void updateDatabase(java.lang.String updateScript,
                           java.util.Map replacers,
                           boolean abortOnError)
Calls an update script.

Parameters:
updateScript - the update script code
replacers - the replacers to use in the script code
abortOnError - indicates if the script is aborted if an error occurs

updateSqlStatement

public int updateSqlStatement(java.lang.String query,
                              java.util.Map replacer,
                              java.util.List params)
                       throws java.sql.SQLException
Creates and executes a database statment from a String.

Parameters:
query - the query to execute
replacer - the replacements to perform in the script
params - the list of parameters for the statement
Returns:
the result set of the query
Throws:
java.sql.SQLException - if something goes wrong

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable
See Also:
Object.finalize()