org.clazzes.jdbc2xml.sax
Class JDBCToSAXWriter

java.lang.Object
  extended by org.clazzes.jdbc2xml.sax.JDBCToSAXWriter

public class JDBCToSAXWriter
extends Object

This class writes a series of JDBC select queries to an XML document using a SAX ContentHandler instance.

Author:
wglas

Constructor Summary
JDBCToSAXWriter()
          Create an uninitialized instance.
JDBCToSAXWriter(Connection connection, TimeZone timeZone, ContentHandler contentHandler)
           
JDBCToSAXWriter(ISchemaEngine schemaEngine, ContentHandler contentHandler)
           
 
Method Summary
 void addQueries(Collection<String> queries)
          Add the given list of queries to the data being dumped.
 void addQuery(String sql)
          Add the given SQL select query to the data being dumped.
 void addRestrictedTable(String table, String sql)
          Add the given database table and a query, which selects a subset of the table data to the data being dumped.
 void addTable(String table)
          Add the given database table to the data being dumped.
 void addTable(TableInfo tableInfo)
          Add the given database table to the data being dumped.
 void addTables(Collection<String> tables)
          Add the given list of database tables to the data being dumped.
 Connection getConnection()
           
 ContentHandler getContentHandler()
           
 ProcessRestrictionFilter getProcessRestrictionFilter()
           
 String getSchema()
           
 TimeZone getTimeZone()
           
 void processData()
          Proceed by executing all SQL statement and writing the resulting data to the ContentHandler.
 void setConnection(Connection connection)
           
 void setContentHandler(ContentHandler contentHandler)
           
 void setProcessRestrictionFilter(ProcessRestrictionFilter processFilter)
           
 void setSchema(String schema)
           
 void setTimeZone(TimeZone timeZone)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDBCToSAXWriter

public JDBCToSAXWriter()
Create an uninitialized instance. Use setConnection(Connection), setContentHandler(ContentHandler) and setTimeZone(TimeZone) in order to initialize this instance.


JDBCToSAXWriter

public JDBCToSAXWriter(Connection connection,
                       TimeZone timeZone,
                       ContentHandler contentHandler)
                throws SQLException
Parameters:
connection - The database connection to use.
timeZone - The time zone used to process date values.
contentHandler - The SAX content handler which drives the XML output.
Throws:
SQLException - Upon errors when inspecting the database.

JDBCToSAXWriter

public JDBCToSAXWriter(ISchemaEngine schemaEngine,
                       ContentHandler contentHandler)
                throws SQLException
Parameters:
schemaEngine - The initialized SchemaEngine carrying the database connection and default time zone.
contentHandler - The SAX content handler which drives the XML output.
Throws:
SQLException - Upon errors when inspecting the database.
Method Detail

getConnection

public Connection getConnection()
Returns:
the connection

setConnection

public void setConnection(Connection connection)
                   throws SQLException
Parameters:
connection - the connection to set
Throws:
SQLException

getContentHandler

public ContentHandler getContentHandler()
Returns:
the contentHandler

setContentHandler

public void setContentHandler(ContentHandler contentHandler)
Parameters:
contentHandler - the contentHandler to set

getTimeZone

public TimeZone getTimeZone()
Returns:
The default time zone for parsing date values.

setTimeZone

public void setTimeZone(TimeZone timeZone)
Parameters:
timeZone - the timeZone to set

getSchema

public String getSchema()
Returns:
The schema to which the written tables belong.

setSchema

public void setSchema(String schema)
Parameters:
schema - The schema to which the written tables belong to set.

addTables

public void addTables(Collection<String> tables)
               throws SQLException
Add the given list of database tables to the data being dumped.

Parameters:
tables - A list of database table names.
Throws:
SQLException

addTable

public void addTable(String table)
              throws SQLException
Add the given database table to the data being dumped.

Parameters:
table - A database table name.
Throws:
SQLException

addTable

public void addTable(TableInfo tableInfo)
              throws SQLException
Add the given database table to the data being dumped. The caller is responsible for assuring, that the passed table description is actually in sync with the database.

Parameters:
tableInfo - A database table description.
Throws:
SQLException

addRestrictedTable

public void addRestrictedTable(String table,
                               String sql)
                        throws SQLException
Add the given database table and a query, which selects a subset of the table data to the data being dumped.

Parameters:
table - A database table name.
sql - A query that selects data from this table, but restrict the returned row to a subset of the whole table. Typically, such a query looks like
   select a.* from account a, person p where a.person_id=p.id and person.name='Me';
 
assuming that table account has a foreign key to table person.
Throws:
SQLException

addQueries

public void addQueries(Collection<String> queries)
Add the given list of queries to the data being dumped.

Parameters:
queries - A list of SQL queries.

addQuery

public void addQuery(String sql)
Add the given SQL select query to the data being dumped.

Parameters:
sql - An SQL query statement.

processData

public void processData()
                 throws SQLException,
                        SAXException
Proceed by executing all SQL statement and writing the resulting data to the ContentHandler.

Throws:
SQLException
SAXException

getProcessRestrictionFilter

public ProcessRestrictionFilter getProcessRestrictionFilter()
Returns:
The processRestrictionFilter, which carries all configurable settings for the data export.

setProcessRestrictionFilter

public void setProcessRestrictionFilter(ProcessRestrictionFilter processFilter)
Parameters:
processFilter - The processRestrictionFilter to set.


Copyright © 2012. All Rights Reserved.