|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sourceforge.jdbdump.connect.DatabaseConnector
public abstract class DatabaseConnector
A DatabaseConnector is an object handling connection to the database which will be backed up.
It manages the Connection object, performs all queries and updates and creates a Dump object.
It is the only point of entry to the database in the system, so no other object has to run
any queries, updates, etc.
This is an abstract class, because it is impossible to write a single universal method which
will make a complete backup of any possible database. Those parts of the backup which are
characteristic only to some database engines will have to be done in specific connectors.
A generic DatabaseConnector can only supply default ways of doing some backup parts, because
many of them will be identical for most database types.
Connectors are created using a DatabaseConnectorFactory. A dump object uses the connector with
which it was created to download the tables' data, so you may disconnect() a connector only when
all the work is finished.
Example code:
DatabaseConnectorFactory factory = DatabaseConnectorFactory.getInstance(); String[] connectorTypes = factory.listPlugins(); if (connectorTypes.length > 0) { DatabaseConnector connector = factory.createConnector(connectorTypes[0]); connector.connect(url, login, pass); Dump dump = connector.dump(); // process the dump and its data... connector.disconnect(); } else { // error - no connectors }
Field Summary | |
---|---|
protected java.sql.Connection |
connection
An object providing direct access to the database through JDBC. |
protected java.sql.DatabaseMetaData |
meta
An object providing access to information about database structure, for example a list of all tables with their attributes, columns, etc. |
Constructor Summary | |
---|---|
DatabaseConnector()
|
Method Summary | |
---|---|
abstract void |
connect(java.lang.String url,
java.lang.String user,
java.lang.String pass)
Opens a connection to the database, using the provided connection data. |
protected void |
connect(java.lang.String url,
java.lang.String user,
java.lang.String pass,
java.lang.String driver)
Opens a connection to the database, using the provided connection data and the specified JDBC driver. |
abstract java.lang.String |
createURL(DatabaseConnectionData data)
Creates a database-specific JDBC connection url (usually, although not always, it has the form: jdbc:dbmstype://host:port/database). |
void |
disconnect()
Closes the database connection. |
abstract Dump |
dump()
Creates a backup of the structure of the entire database. |
protected void |
dumpColumn(Column column,
java.sql.ResultSet rsColumns)
Downloads the structure of a single table column from the database. |
protected void |
dumpTable(Table table)
Downloads the structure of a single table from the database. |
protected void |
dumpTableForeignKeys(Table table)
Downloads the table's foreign (imported) keys from the database. |
protected void |
dumpTablePrimaryKeys(Table table)
Downloads the table's primary key from the database. |
protected void |
dumpTables(Dump dump)
Downloads the structure of all tables in the database. |
abstract java.lang.String[] |
getTableDataLine()
Downloads one record of data from the previously initialized table in database. |
abstract void |
initializeTableData(java.lang.String tableName)
Prepares the given table for downloading its data. |
static void |
printResultSet(java.sql.ResultSet rs)
A debugging method used to print the entire result set (all rows, all fields in them, also with field names). |
abstract void |
restore(Dump dump)
Restores the structure of the database from a Dump object loaded from a previously created backup file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.sql.Connection connection
protected java.sql.DatabaseMetaData meta
Constructor Detail |
---|
public DatabaseConnector()
Method Detail |
---|
public abstract void connect(java.lang.String url, java.lang.String user, java.lang.String pass) throws java.sql.SQLException, java.lang.ClassNotFoundException
url
- a correct connection URLuser
- user's login in the databasepass
- user's password
java.sql.SQLException
- if the connection is not possible
java.lang.ClassNotFoundException
- if there is a problem with loading a driverprotected void connect(java.lang.String url, java.lang.String user, java.lang.String pass, java.lang.String driver) throws java.sql.SQLException, java.lang.ClassNotFoundException
url
- a correct connection URLuser
- user's login in the databasepass
- user's passworddriver
- full name of the JDBC driver class
java.sql.SQLException
- if the connection is not possible
java.lang.ClassNotFoundException
- if there is a problem with loading a driverpublic void disconnect()
public abstract Dump dump() throws java.sql.SQLException
java.sql.SQLException
- if the backup process is interrupted by a critical errorpublic abstract void restore(Dump dump) throws java.sql.SQLException
dump
- a Dump object containing information about database structure
java.sql.SQLException
- if the restore process is interrupted by a critical errorpublic abstract java.lang.String createURL(DatabaseConnectionData data)
data
- an object providing all the data necessary to open the connection
protected void dumpTables(Dump dump)
dump
- a dump to which the downloaded tables should be added
java.sql.SQLException
- if the backup process is interrupted by a critical errorprotected void dumpTable(Table table)
table
- a chosen table in the dump, to which the downloaded information should be assigned
java.sql.SQLException
- if the backup process is interrupted by a critical errorprotected void dumpTablePrimaryKeys(Table table) throws java.sql.SQLException
table
- a table which should be checked for primary keys
java.sql.SQLException
- if the backup process is interrupted by a critical errorprotected void dumpTableForeignKeys(Table table) throws java.sql.SQLException
table
- a table which should be checked for foreign keys
java.sql.SQLException
- if the backup process is interrupted by a critical errorprotected void dumpColumn(Column column, java.sql.ResultSet rsColumns) throws java.sql.SQLException
column
- a column which should have its parameters downloadedrsColumns
- a ResultSet returned by DatabaseMetaData.getColumns(),
set on this column's record
java.sql.SQLException
- if the backup process is interrupted by a critical errorpublic static void printResultSet(java.sql.ResultSet rs) throws java.sql.SQLException
rs
- the ResultSet to be printed
java.sql.SQLException
- if there is something wrong with the resultsetpublic abstract void initializeTableData(java.lang.String tableName) throws java.sql.SQLException
tableName
- name of the table from which data should be downloaded
java.sql.SQLException
public abstract java.lang.String[] getTableDataLine() throws java.sql.SQLException
java.sql.SQLException
- if data record can't be downloaded because of a connection error
or an error in the database
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |