com.arsdigita.developersupport
Class SQLDebugger

java.lang.Object
  extended bycom.arsdigita.developersupport.SQLDebugger

public final class SQLDebugger
extends Object

A helper class that lets you dump the contents of a table into a file in XML format.

Note that this uses direct JDBC calls bypassing persistence. Therefore, no additional persistence flushes are triggered by this class. The current API is very primitive.

Example usage:

 // specify the output file name
 SQLDebugger.startNewFile("txns");
 
 // select the specified columns from a table
 // and append the result set to /tmp/debug.xml
 SQLDebugger.dumpTable("after initializing obj and compObj",
                 new String[] {"transaction_id", "master_id", "object_id", "tag"},
                 "vcx_transactions");
 
 SQLDebugger.dumpTable("after initializing obj and compObj",
                 new String[] {"id", "j_big_integer", "j_big_decimal", "j_string"},
                 "tx_versioned_datatypes");
 
 // do some computations and dump the data again
 SQLDebugger.dumpTable("after setting obj to initVersionedTstObj",
                 new String[] {"transaction_id", "master_id", "object_id", "tag"},
                 "vcx_transactions");
 
 SQLDebugger.dumpTable("after setting obj to initVersionedTstObj",
                 new String[] {"id", "j_big_integer", "j_big_decimal", "j_string"},
                 "tx_versioned_datatypes");
 
 // close the file
 SQLDebugger.close();
 

The .xml files thus generated can be converted to HTML for easier viewing by using the sql-debugger.sh script. The script relies on the sql-debugger.xsl stylesheet. and requires xsltproc to be installed on your system.

Some of the known numerous shortcomings:

  1. Doesn't escape the selected values to ensure the well-formedness of the XML output.

Since:
2003/02/06
Version:
$Revision: #3 $ $Date: 2004/04/07 $
Author:
Vadim Nasardinov (vadimn@redhat.com)

Method Summary
static void close()
          Closes the output file previously opened with startNewFile(String).
static void dumpQuery(String debugMsg, String[] columns, String sqlQuery)
          Runs the query sqlQuery and dumps the result to the print writer in the following format:
static void dumpTable(String debugMsg, String[] columns, String tableName)
           
static void startNewFile(String prefix)
          Starts a new file for debug output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

startNewFile

public static void startNewFile(String prefix)
Starts a new file for debug output. The file name will start with the specified prefix. The file is created in the directory specified by the system property "java.io.tmpdir".

Parameters:
prefix - the prefix (initial characters) for the new file name. Must be at least three characters long.
See Also:
File.createTempFile(String, String)

close

public static void close()
Closes the output file previously opened with startNewFile(String). If you forget to call this method or if the application crashes before this method is called, the output file will miss a closing tag, thus rendering it ill-formed. You can add the missing tag manually, if you have to.


dumpTable

public static void dumpTable(String debugMsg,
                             String[] columns,
                             String tableName)
See Also:
dumpQuery(String, String[], String)

dumpQuery

public static void dumpQuery(String debugMsg,
                             String[] columns,
                             String sqlQuery)
Runs the query sqlQuery and dumps the result to the print writer in the following format:
 <tableName>
   <row>
     <column0>value00</column0>
     <column1>value01</column1>
     ...
   </row>
   <row>
     <column0>value10</column0>
     <column1>value11</column1>
     ...
   </row>
   ...
 </tableName>
 

Parameters:
debugMsg - a short message that explains the purpose or circumstances in which the results of this query were dumped.
columns - the names of columns returned by the query
sqlQuery - the query to execute


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 20 2004:2337 UTC