net.wgen.op.db.dbunit
Class DBUnitCapture

java.lang.Object
  extended bynet.wgen.op.db.dbunit.DBUnitCapture

public class DBUnitCapture
extends java.lang.Object

Event driven database data capturer. When registered in a DatabaseCall in the DBUnitHandlingOption.PROP_DBUNIT_CAPTURE option, the outputs of the call will be captured to a file within the /opt/op_data directory. This class uses a Transformer registered in the call's DBUnitHandlingOption.PROP_DBUNIT_CALL_FILE_TRANSFORM_CALLBACK option to determine the file to store the data. It uses Transformer registered in the call's DBUnitHandlingOption.PROP_DBUNIT_PARAM_TABLE_TRANSFORM_CALLBACK to determine the table name within that file. If no Transformer is registered in those options, the PathCallbackTransformer is used.

Version:
$Id: DBUnitCapture.html,v 1.2 2007/01/28 04:09:36 paulfeuer Exp $
Author:
Paul Feuer, Wireless Generation, Inc.
See Also:
PathCallbackTransformer

Field Summary
private  DatabaseCall _call
           
private  org.dbunit.dataset.DefaultDataSet _dataSet
           
static java.lang.String ROOT_DATA_DIR
           
static java.lang.String SINGLE_VALUE_COLUMN_NAME
           
 
Constructor Summary
DBUnitCapture(DatabaseCall call)
           
 
Method Summary
 void captureMetaData(int paramIdx, java.sql.ResultSet resultSet)
          Called at the beginning of a ResultSet capture to initialize the table within the DataSet.
 void captureRow(int paramIdx, java.lang.Object[] rowValues)
          Captures one row of a ResultSet or array and puts it into the table at the given index.
 void captureSingleOutputValue(int paramIdx, int jdbcType, java.lang.Object value)
          Captures a database call output.
static int findParamIndexTableNameForParam(DatabaseCall dbCall, java.lang.String tableName)
          Uses a Transformer registered in DBUnitHandlingOption.PROP_DBUNIT_PARAM_TABLE_TRANSFORM_CALLBACK to come up with the index associated with the discovered table name.
static java.io.File findPathForCall(DatabaseCall dbCall, HandlingOption option)
           
static java.lang.String findTableNameForParam(DatabaseCall dbCall, int idx)
          Uses a Transformer registered in DBUnitHandlingOption.PROP_DBUNIT_PARAM_TABLE_TRANSFORM_CALLBACK to come up with the name of the table for the given index.
 void writeOutputsToFileSystem()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROOT_DATA_DIR

public static final java.lang.String ROOT_DATA_DIR
See Also:
Constant Field Values

SINGLE_VALUE_COLUMN_NAME

public static final java.lang.String SINGLE_VALUE_COLUMN_NAME
See Also:
Constant Field Values

_call

private final DatabaseCall _call

_dataSet

private org.dbunit.dataset.DefaultDataSet _dataSet
Constructor Detail

DBUnitCapture

public DBUnitCapture(DatabaseCall call)
Method Detail

captureMetaData

public void captureMetaData(int paramIdx,
                            java.sql.ResultSet resultSet)
                     throws java.sql.SQLException,
                            DatabaseCallException
Called at the beginning of a ResultSet capture to initialize the table within the DataSet.

Parameters:
paramIdx - the parameter index of the ResultSet (use 0 for PreparedStatement queries)
resultSet - the resultSet to be captured
Throws:
java.sql.SQLException
DatabaseCallException

captureRow

public void captureRow(int paramIdx,
                       java.lang.Object[] rowValues)
                throws DatabaseCallException
Captures one row of a ResultSet or array and puts it into the table at the given index.

Parameters:
paramIdx - the index of the ResultSet return (use 0 for PreparedStatement queries)
rowValues - the values of the row
Throws:
DatabaseCallException

captureSingleOutputValue

public void captureSingleOutputValue(int paramIdx,
                                     int jdbcType,
                                     java.lang.Object value)
                              throws DatabaseCallException
Captures a database call output. This creates a single column table in the capture and writes a single row with a single value.

Parameters:
paramIdx - the index of the output being captured
jdbcType - the jdbcType of the output either from javax.sql.Types or oracle.jdbc.OracleTypes
value - the value to be captured
Throws:
DatabaseCallException

writeOutputsToFileSystem

public void writeOutputsToFileSystem()
                              throws java.io.IOException,
                                     org.dbunit.dataset.DataSetException,
                                     javax.xml.parsers.ParserConfigurationException,
                                     javax.xml.transform.TransformerException
Throws:
java.io.IOException
org.dbunit.dataset.DataSetException
javax.xml.parsers.ParserConfigurationException
javax.xml.transform.TransformerException

findPathForCall

public static java.io.File findPathForCall(DatabaseCall dbCall,
                                           HandlingOption option)
Parameters:
dbCall -
option - the name of the option holding the name of the set
Returns:
the File to be used for the capture within the /opt/wgen/dbunit ddirectory.

findTableNameForParam

public static java.lang.String findTableNameForParam(DatabaseCall dbCall,
                                                     int idx)
Uses a Transformer registered in DBUnitHandlingOption.PROP_DBUNIT_PARAM_TABLE_TRANSFORM_CALLBACK to come up with the name of the table for the given index. If no Transformer is registered, a PathCallbackTransformer is used.

Parameters:
dbCall - the call being captured
idx - the index of the parameter being captured
Returns:
the tableName generated by the Transformer handling tableName generations

findParamIndexTableNameForParam

public static int findParamIndexTableNameForParam(DatabaseCall dbCall,
                                                  java.lang.String tableName)
Uses a Transformer registered in DBUnitHandlingOption.PROP_DBUNIT_PARAM_TABLE_TRANSFORM_CALLBACK to come up with the index associated with the discovered table name. If no Transformer is registered, a PathCallbackTransformer is used.

Parameters:
dbCall - the call being captured
tableName - the name of the table that was found
Returns:
the tableName generated by the Transformer handling tableName generations