Quadcap Embeddable Database

com.quadcap.sql.tools.XmlDump Class Reference

Inheritance diagram for com.quadcap.sql.tools.XmlDump:

com.quadcap.sql.Backup List of all members.

Detailed Description

Dump an SQL database in an XML representation.

The XML document has an outer tag of <database>. Each child element then contains one table row, where the tag name specifies the table name; each child element of this tag contains one column value where the tag name specifies the column name. Most object are represented in their standard Java toString style representation, except binary objects, which are dumped in hexadecimal. (Base-64 would probably be better...)

Author:
Stan Bailes

Definition at line 98 of file XmlDump.java.

Public Member Functions

 XmlDump ()
 No-argument constructor.

 XmlDump (Connection conn)
 Construct an XmlDump object bound to the specified connection.

 XmlDump (Connection conn, int indentLevel)
 Construct an XmlDump object bound to the specified connection, and with a specified initial indent level.

void setConnection (Connection conn)
 Set the dumper's database connection.

Connection getConnection ()
 Get the dumper's database connection.

void dumpTableForeignKeys (Writer w, String tableName) throws SQLException, IOException
 Dump the SQL foreign key constraints for the specified table.

void dumpTableDefinition (Writer w, String tableName) throws SQLException, IOException
 Dump the SQL table definition for the specified table.

void dumpTable (Writer w, String tableName) throws IOException, SQLException
 Dump the rows of the specified table to the output stream in XML format.

void dumpTables (Writer w) throws IOException, SQLException
 Dump all of the tables in the database which is referenced by the current connection object to the specified output stream.

void backup (java.sql.Connection conn, Writer w) throws IOException, SQLException
 A convenience function that sets the current connection and dumps the database in one go.


Static Public Member Functions

Connection makeConnection () throws Exception
 Establish a database connection based on the settings of system properties.

void main (String[] args)
 A main program which allows this function to be run as a command-line application for doing an off-line dump.


Package Functions

final void beginTag (Writer w, String tag) throws IOException
final void endTag (Writer w, String tag) throws IOException
final void writeString (Writer w, String str) throws IOException
final void writeBinaryStream (Writer w, InputStream is) throws IOException
final void writeCharacterStream (Writer w, Reader r) throws IOException
final void writeBinary (Writer w, Object obj) throws IOException
final void writeValue (Writer w, Object obj, int jdbcType) throws SQLException, IOException
List parseViewDef (String s)
void dumpViewDefinitions (Writer w) throws SQLException, IOException
void dumpIndexDefinitions (Writer w, String tableName) throws SQLException, IOException
final Iterator orderTables () throws SQLException
Hashtable getTypes () throws SQLException
DbType getType (int type) throws SQLException

Package Attributes

Connection conn
int indentLevel = 0
String lineSep
boolean wasBegin = false
boolean wasEnd = false
Hashtable types = null

Static Package Attributes

final String charsLt = "&lt;"
final String charsGt = "&gt;"
final String charsAmp = "&amp;"
final char[] hexBytes


Constructor & Destructor Documentation

com.quadcap.sql.tools.XmlDump.XmlDump  ) 
 

No-argument constructor.

The object so constructed needs a Connection in order to do anything useful.

Definition at line 109 of file XmlDump.java.

References com.quadcap.sql.tools.XmlDump.lineSep.

Referenced by com.quadcap.sql.tools.XmlDump.main().

com.quadcap.sql.tools.XmlDump.XmlDump Connection  conn  ) 
 

Construct an XmlDump object bound to the specified connection.

Parameters:
conn the database connection

Definition at line 118 of file XmlDump.java.

References com.quadcap.sql.tools.XmlDump.lineSep.

com.quadcap.sql.tools.XmlDump.XmlDump Connection  conn,
int  indentLevel
 

Construct an XmlDump object bound to the specified connection, and with a specified initial indent level.

Parameters:
conn the database connection
indentLevel the initial indent level (in units -- currently indent units are simple spaces

Definition at line 131 of file XmlDump.java.

References com.quadcap.sql.tools.XmlDump.lineSep.


Member Function Documentation

void com.quadcap.sql.tools.XmlDump.backup java.sql.Connection  conn,
Writer  w
throws IOException, SQLException
 

A convenience function that sets the current connection and dumps the database in one go.

Parameters:
conn the database connection
w the output stream
Exceptions:
IOException may be thrown
SQLException may be thrown

Definition at line 809 of file XmlDump.java.

References com.quadcap.sql.tools.XmlDump.backup(), and com.quadcap.sql.tools.XmlDump.conn.

Referenced by com.quadcap.sql.tools.XmlDump.backup().

final void com.quadcap.sql.tools.XmlDump.beginTag Writer  w,
String  tag
throws IOException [package]
 

Definition at line 155 of file XmlDump.java.

References com.quadcap.sql.tools.XmlDump.beginTag(), com.quadcap.sql.tools.XmlDump.indentLevel, com.quadcap.sql.tools.XmlDump.lineSep, com.quadcap.sql.tools.XmlDump.wasBegin, and com.quadcap.sql.tools.XmlDump.wasEnd.

Referenced by com.quadcap.sql.tools.XmlDump.beginTag().

void com.quadcap.sql.tools.XmlDump.dumpIndexDefinitions Writer  w,
String  tableName
throws SQLException, IOException [package]
 

Definition at line 374 of file XmlDump.java.

References com.quadcap.sql.tools.XmlDump.conn, and com.quadcap.sql.tools.XmlDump.dumpIndexDefinitions().

Referenced by com.quadcap.sql.tools.XmlDump.dumpIndexDefinitions().

void com.quadcap.sql.tools.XmlDump.dumpTable Writer  w,
String  tableName
throws IOException, SQLException
 

Dump the rows of the specified table to the output stream in XML format.

Each row is dumped as an XML element with the tag name equal to the table name. Each non-null column is dumped as a sub-element with the tag name equal to the column name.

Parameters:
w the output stream
tableName the name of the database table to dump.
Exceptions:
IOException may be thrown
SQLException may be thrown

Definition at line 711 of file XmlDump.java.

References com.quadcap.sql.tools.XmlDump.conn, and com.quadcap.sql.tools.XmlDump.dumpTable().

Referenced by com.quadcap.sql.tools.XmlDump.dumpTable().

void com.quadcap.sql.tools.XmlDump.dumpTableDefinition Writer  w,
String  tableName
throws SQLException, IOException
 

Dump the SQL table definition for the specified table.

Definition at line 602 of file XmlDump.java.

References com.quadcap.sql.tools.XmlDump.conn, com.quadcap.sql.tools.XmlDump.dumpTableDefinition(), com.quadcap.sql.tools.XmlDump.DbType.getCreateParams(), com.quadcap.sql.tools.XmlDump.DbType.getTypePrefix(), and com.quadcap.sql.tools.XmlDump.DbType.getTypeSuffix().

Referenced by com.quadcap.sql.tools.XmlDump.dumpTableDefinition().

void com.quadcap.sql.tools.XmlDump.dumpTableForeignKeys Writer  w,
String  tableName
throws SQLException, IOException
 

Dump the SQL foreign key constraints for the specified table.

Definition at line 532 of file XmlDump.java.

References com.quadcap.sql.tools.XmlDump.conn, and com.quadcap.sql.tools.XmlDump.dumpTableForeignKeys().

Referenced by com.quadcap.sql.tools.XmlDump.dumpTableForeignKeys().

void com.quadcap.sql.tools.XmlDump.dumpTables Writer  w  )  throws IOException, SQLException
 

Dump all of the tables in the database which is referenced by the current connection object to the specified output stream.

This routine writes a well-formed XML document, with a document element named <database>. Sub-elements correspond to indidivual table rows.

This routine first constructs a graph of the foreign table reference constraints, and attempts to output base tables before dependant tables, so that the resulting file can be imported without causing foreign key integrity violations.

Parameters:
w the output stream
Exceptions:
IOException may be thrown
SQLException may be thrown

Definition at line 765 of file XmlDump.java.

References com.quadcap.sql.tools.XmlDump.dumpTables(), and com.quadcap.sql.tools.XmlDump.orderTables().

Referenced by com.quadcap.sql.tools.XmlDump.dumpTables(), and com.quadcap.sql.tools.XmlDump.main().

void com.quadcap.sql.tools.XmlDump.dumpViewDefinitions Writer  w  )  throws SQLException, IOException [package]
 

Definition at line 333 of file XmlDump.java.

References com.quadcap.util.collections.DiGraph.addArc(), com.quadcap.sql.tools.XmlDump.conn, com.quadcap.sql.tools.XmlDump.dumpViewDefinitions(), and com.quadcap.util.collections.DiGraph.levelize().

Referenced by com.quadcap.sql.tools.XmlDump.dumpViewDefinitions().

final void com.quadcap.sql.tools.XmlDump.endTag Writer  w,
String  tag
throws IOException [package]
 

Definition at line 166 of file XmlDump.java.

References com.quadcap.sql.tools.XmlDump.endTag(), com.quadcap.sql.tools.XmlDump.indentLevel, com.quadcap.sql.tools.XmlDump.lineSep, com.quadcap.sql.tools.XmlDump.wasBegin, and com.quadcap.sql.tools.XmlDump.wasEnd.

Referenced by com.quadcap.sql.tools.XmlDump.endTag().

Connection com.quadcap.sql.tools.XmlDump.getConnection  ) 
 

Get the dumper's database connection.

Returns:
the current database connection

Definition at line 151 of file XmlDump.java.

References com.quadcap.sql.tools.XmlDump.conn.

DbType com.quadcap.sql.tools.XmlDump.getType int  type  )  throws SQLException [package]
 

Definition at line 519 of file XmlDump.java.

References com.quadcap.sql.tools.XmlDump.getType(), com.quadcap.sql.tools.XmlDump.getTypes(), and com.quadcap.sql.tools.XmlDump.types.

Referenced by com.quadcap.sql.tools.XmlDump.getType().

Hashtable com.quadcap.sql.tools.XmlDump.getTypes  )  throws SQLException [package]
 

Definition at line 502 of file XmlDump.java.

References com.quadcap.sql.tools.XmlDump.conn, and com.quadcap.sql.tools.XmlDump.types.

Referenced by com.quadcap.sql.tools.XmlDump.getType().

void com.quadcap.sql.tools.XmlDump.main String[]  args  )  [static]
 

A main program which allows this function to be run as a command-line application for doing an off-line dump.

The name of the output file is specified as the argument. If the name of the output file ends with ".gz", the output is compressed using the gzip compression mechanism.

See also:
makeConnection for a description of the System properties used to establish the database connection.
Parameters:
args com.quadcap.sql.tools.XmlDump output file

Definition at line 895 of file XmlDump.java.

References com.quadcap.sql.Connection.close(), com.quadcap.sql.tools.XmlDump.dumpTables(), com.quadcap.sql.tools.XmlDump.main(), com.quadcap.sql.tools.XmlDump.makeConnection(), and com.quadcap.sql.tools.XmlDump.XmlDump().

Referenced by com.quadcap.sql.tools.XmlDump.main().

Connection com.quadcap.sql.tools.XmlDump.makeConnection  )  throws Exception [static]
 

Establish a database connection based on the settings of system properties.

The following system properties are used to establish the database connection:
jdbc.driver The name of the JDBC driver class (default com.quadcap.jdbc.JdbcDriver)
jdbc.url The JDBC URL used to establish the database connection.
jdbc.props The name of a properties file used to establish the connection. If this property is specified, jdbc.user and jdbc.password aren't used. If this property has the value "system", then the system properties are passed to the DriverManager.getConnection() method.
jdbc.user The user name used to establish the database connection. If neither jdbc.props nor jdbc.user is specified, the DriverManager.getConnection(String url) method is used to establish the connection.
jdbc.password The password used to establish the database connection.

Exceptions:
Exception may be thrown if there's a problem connecting to the database.

Definition at line 852 of file XmlDump.java.

Referenced by com.quadcap.sql.tools.XmlDump.main().

final Iterator com.quadcap.sql.tools.XmlDump.orderTables  )  throws SQLException [package]
 

Definition at line 427 of file XmlDump.java.

References com.quadcap.sql.tools.XmlDump.conn.

Referenced by com.quadcap.sql.tools.XmlDump.dumpTables().

List com.quadcap.sql.tools.XmlDump.parseViewDef String  s  )  [package]
 

Definition at line 307 of file XmlDump.java.

References com.quadcap.sql.tools.XmlDump.parseViewDef().

Referenced by com.quadcap.sql.tools.XmlDump.parseViewDef().

void com.quadcap.sql.tools.XmlDump.setConnection Connection  conn  ) 
 

Set the dumper's database connection.

Parameters:
conn the new database connection

Definition at line 142 of file XmlDump.java.

References com.quadcap.sql.tools.XmlDump.setConnection().

Referenced by com.quadcap.sql.tools.XmlDump.setConnection().

final void com.quadcap.sql.tools.XmlDump.writeBinary Writer  w,
Object  obj
throws IOException [package]
 

Definition at line 237 of file XmlDump.java.

References com.quadcap.sql.tools.XmlDump.hexBytes, and com.quadcap.sql.tools.XmlDump.writeBinary().

Referenced by com.quadcap.sql.tools.XmlDump.writeBinary().

final void com.quadcap.sql.tools.XmlDump.writeBinaryStream Writer  w,
InputStream  is
throws IOException [package]
 

Definition at line 209 of file XmlDump.java.

References com.quadcap.sql.tools.XmlDump.hexBytes, and com.quadcap.sql.tools.XmlDump.writeBinaryStream().

Referenced by com.quadcap.sql.tools.XmlDump.writeBinaryStream().

final void com.quadcap.sql.tools.XmlDump.writeCharacterStream Writer  w,
Reader  r
throws IOException [package]
 

Definition at line 217 of file XmlDump.java.

References com.quadcap.sql.tools.XmlDump.charsAmp, com.quadcap.sql.tools.XmlDump.charsGt, com.quadcap.sql.tools.XmlDump.charsLt, and com.quadcap.sql.tools.XmlDump.writeCharacterStream().

Referenced by com.quadcap.sql.tools.XmlDump.writeCharacterStream().

final void com.quadcap.sql.tools.XmlDump.writeString Writer  w,
String  str
throws IOException [package]
 

Definition at line 184 of file XmlDump.java.

References com.quadcap.sql.tools.XmlDump.charsAmp, com.quadcap.sql.tools.XmlDump.charsGt, com.quadcap.sql.tools.XmlDump.charsLt, com.quadcap.sql.tools.XmlDump.wasBegin, com.quadcap.sql.tools.XmlDump.wasEnd, and com.quadcap.sql.tools.XmlDump.writeString().

Referenced by com.quadcap.sql.tools.XmlDump.writeString().

final void com.quadcap.sql.tools.XmlDump.writeValue Writer  w,
Object  obj,
int  jdbcType
throws SQLException, IOException [package]
 

Definition at line 252 of file XmlDump.java.

References com.quadcap.sql.tools.XmlDump.writeValue().

Referenced by com.quadcap.sql.tools.XmlDump.writeValue().


Member Data Documentation

final String com.quadcap.sql.tools.XmlDump.charsAmp = "&amp;" [static, package]
 

Definition at line 182 of file XmlDump.java.

Referenced by com.quadcap.sql.tools.XmlDump.writeCharacterStream(), and com.quadcap.sql.tools.XmlDump.writeString().

final String com.quadcap.sql.tools.XmlDump.charsGt = "&gt;" [static, package]
 

Definition at line 181 of file XmlDump.java.

Referenced by com.quadcap.sql.tools.XmlDump.writeCharacterStream(), and com.quadcap.sql.tools.XmlDump.writeString().

final String com.quadcap.sql.tools.XmlDump.charsLt = "&lt;" [static, package]
 

Definition at line 180 of file XmlDump.java.

Referenced by com.quadcap.sql.tools.XmlDump.writeCharacterStream(), and com.quadcap.sql.tools.XmlDump.writeString().

Connection com.quadcap.sql.tools.XmlDump.conn [package]
 

Definition at line 99 of file XmlDump.java.

Referenced by com.quadcap.sql.tools.XmlDump.backup(), com.quadcap.sql.tools.XmlDump.dumpIndexDefinitions(), com.quadcap.sql.tools.XmlDump.dumpTable(), com.quadcap.sql.tools.XmlDump.dumpTableDefinition(), com.quadcap.sql.tools.XmlDump.dumpTableForeignKeys(), com.quadcap.sql.tools.XmlDump.dumpViewDefinitions(), com.quadcap.sql.tools.XmlDump.getConnection(), com.quadcap.sql.tools.XmlDump.getTypes(), and com.quadcap.sql.tools.XmlDump.orderTables().

final char [] com.quadcap.sql.tools.XmlDump.hexBytes [static, package]
 

Initial value:

{ '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' }

Definition at line 205 of file XmlDump.java.

Referenced by com.quadcap.sql.tools.XmlDump.writeBinary(), and com.quadcap.sql.tools.XmlDump.writeBinaryStream().

int com.quadcap.sql.tools.XmlDump.indentLevel = 0 [package]
 

Definition at line 100 of file XmlDump.java.

Referenced by com.quadcap.sql.tools.XmlDump.beginTag(), and com.quadcap.sql.tools.XmlDump.endTag().

String com.quadcap.sql.tools.XmlDump.lineSep [package]
 

Definition at line 101 of file XmlDump.java.

Referenced by com.quadcap.sql.tools.XmlDump.beginTag(), com.quadcap.sql.tools.XmlDump.endTag(), and com.quadcap.sql.tools.XmlDump.XmlDump().

Hashtable com.quadcap.sql.tools.XmlDump.types = null [package]
 

Definition at line 500 of file XmlDump.java.

Referenced by com.quadcap.sql.tools.XmlDump.getType(), and com.quadcap.sql.tools.XmlDump.getTypes().

boolean com.quadcap.sql.tools.XmlDump.wasBegin = false [package]
 

Definition at line 102 of file XmlDump.java.

Referenced by com.quadcap.sql.tools.XmlDump.beginTag(), com.quadcap.sql.tools.XmlDump.endTag(), and com.quadcap.sql.tools.XmlDump.writeString().

boolean com.quadcap.sql.tools.XmlDump.wasEnd = false [package]
 

Definition at line 103 of file XmlDump.java.

Referenced by com.quadcap.sql.tools.XmlDump.beginTag(), com.quadcap.sql.tools.XmlDump.endTag(), and com.quadcap.sql.tools.XmlDump.writeString().