public class DBSetup extends Object
| Constructor and Description |
|---|
DBSetup(Connection connection)
Creates a new instance with an already established connection.
|
DBSetup(String jdbc_url,
String username,
String password)
Creates a new
DBSetup object where this object is not in console mode (meaning messages will not be
emitted to the console). |
DBSetup(String jdbc_url,
String username,
String password,
boolean consoleMode)
Creates a new
DBSetup object where this object is in console mode (meaning messages will be emitted to
the console). |
| Modifier and Type | Method and Description |
|---|---|
boolean |
clear(String file_name)
Purges the entire schema of all existing data.
|
boolean |
clear(String file_name,
String table_name)
Purges data from the schema.
|
protected void |
doSQL(String sql)
Executes the given SQL.
|
protected Statement |
doSQL(String sql,
boolean returnPreparedStatement)
This method either executes the given SQL (if
returnPreparedStatement is false) or it
just prepares it in a statement and expects the caller to execute the statement. |
void |
export(String file)
Exports an existing schema to a DBSetup XML file.
|
protected Connection |
getConnection()
Gets the live connection that this object is using.
|
protected DatabaseType |
getDatabaseType()
Gets the database type information of the database this object is currently
connected
to. |
protected String |
getJdbcUser()
Returns the username that this object will use when connecting to the database.
|
static void |
main(String[] args)
A console application that can be used to run the DBSetup from a command line.
|
void |
setup(String file_name)
Performs the full database setup.
|
void |
setup(String file_name,
String table_name,
boolean data_only,
boolean do_delete)
Performs the actual database setup.
|
boolean |
uninstall(String file_name)
This is the reverse of setup - that is, it removes a schema from a database, deleting all data with it.
|
public DBSetup(String jdbc_url, String username, String password)
DBSetup object where this object is not in console mode (meaning messages will not be
emitted to the console).jdbc_url - the JDBC URL used to connect to the databaseusername - the user that will be logged into the databasepassword - user's credentialspublic DBSetup(String jdbc_url, String username, String password, boolean consoleMode)
DBSetup object where this object is in console mode (meaning messages will be emitted to
the console).jdbc_url - the JDBC URL used to connect to the databaseusername - the user that will be logged into the databasepassword - user's credentialsconsoleMode - indicates if messages should be emitted to the consolepublic DBSetup(Connection connection) throws Exception
connection - Exceptionpublic static void main(String[] args)
DBSetup -op=setup|clear|uninstall|uninstallsetup
-jdbcurl=<db-url> [-jdbcuser=<username>] [-jdbcpassword=<password>]
-file=<dbsetup-xml-file>
where:
args - see descriptionpublic void setup(String file_name) throws Exception
file_name - the path to the database setup XML fileExceptionsetup(String, String, boolean, boolean)public void setup(String file_name, String table_name, boolean data_only, boolean do_delete) throws Exception
file_name - the file that contains the DBSetup XML content.table_name - if not null, only this table will be setupdata_only - if true does not create the schema; only inserts data into an existing schemado_delete - if true, and table_name was specified, this will delete all rows
from that table before inserting the new data. The table must exist. It only makes sense to
use this with data_only set to true.Exceptionpublic boolean clear(String file_name) throws Exception
file_name - the path to the database setup XML filetrue if all data was successfully deleted; false if at least one failure
occurred when trying remove data from the tablesExceptionclear(String, String),
uninstall(String)public boolean clear(String file_name, String table_name) throws Exception
table is not null, only that table will be cleared of
data; the remaining tables will have their data remain as-is.file_name - the path to the database setup XML filetable_name - the table to clear, if null, then all tables are clearedtrue if all data was successfully deleted; false if at least one failure
occurred when trying remove data from the tablesExceptionuninstall(String)public boolean uninstall(String file_name) throws Exception
file_name - the file that contains the DBSetup XML content.true if all views and tables were successfully removed; false if at least one
failure occurred when trying remove views and tablesExceptionpublic void export(String file) throws Exception
NOTE: you cannot use the generated XML file for input into DBSetup. This exported XML file is only for reference purposes; it is not generated in a way that can be used to recreate the DB. Use your database vendor's backup/restore utilities to export databases for backup and recovery.
file - the XML file that will contain the exported schemaExceptionprotected void doSQL(String sql) throws SQLException
sql - SQLExceptionprotected Statement doSQL(String sql, boolean returnPreparedStatement) throws SQLException
returnPreparedStatement is false) or it
just prepares it in a statement and expects the caller to execute the statement. The caller must close the
returned prepared statement (which occurs if returnPreparedStatement is true)sql - an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE
or DELETE; or an SQL statement that returns nothing,
such as a DDL statementreturnPreparedStatement - if true, the SQL isn't executed; it is just preparedSQLExceptionprotected Connection getConnection()
null is
returned.protected DatabaseType getDatabaseType()
connected
to. If there is not a live connection to a database, null is returned.protected String getJdbcUser()
Copyright © 2008-2014 Red Hat, Inc.. All Rights Reserved.