net.sourceforge.sqlunit
Class SymbolTable

java.lang.Object
  extended by net.sourceforge.sqlunit.SymbolTable

public final class SymbolTable
extends java.lang.Object

Models a HashMap as a symbol table to store temporary variables and their values that are needed for a SQLUnit test case.

Version:
$Revision: 1.44 $
Author:
Sujit Pal (spal@users.sourceforge.net)

Field Summary
static java.lang.String CURRENT_COL_KEY
          Keeps track of current column in row
static java.lang.String CURRENT_RESULTSET_KEY
          Keeps track of current resultset
static java.lang.String CURRENT_ROW_KEY
          Keeps track of current row in resultset
static java.lang.String DEBUG_LOGGER
          Contains the debugging logger if set
static java.lang.String FAILURE_MESSAGE_OBJ
          Contains the failure message if available
static java.lang.String FILE_HEADER
          Indicates that the value is a LOB file name
static java.lang.String JAVA_OBJECT_SUPPORT
          Indicates if Java Object Support is enabled
static java.lang.String OUT_PARAM
          Contains outparam index mapping header
static java.lang.String REPORTER_KEY
          Holds a reference to the Reporter object
static java.lang.String SKIP_REASON
          Holds a reference to the most recent skipped reason
static java.lang.String TEST_ELAPSED_TIME
          Contains elapsed time for a test in milliseconds
 
Method Summary
static void dump()
          Dumps the contents of the symbol table for inspection.
static java.lang.String getCurrentResultKey()
          Returns the current result key as a String.
static java.lang.Object getObject(java.lang.String param)
          Returns an object keyed by the param string from the symbol table.
static java.util.Iterator getSymbols()
          Returns an Iterator containing all the symbols in the Symbol table.
static java.lang.String getValue(java.lang.String param)
          Returns the value of the named variable.
static boolean isVariableName(java.lang.String str)
          By definition, a string which matches the pattern ${var} is considered to be a variable name in SQLUnit.
static java.lang.String removeSymbol(java.lang.String param)
          Removes a symbol from the symbol table.
static void removeUserVariables()
          Removes the references to the user variables set in a test after all tests are completed.
static java.lang.String replaceVariables(java.lang.String text)
          Replaces all variables in a string from the symbol table.
static void setCurrentCol(java.lang.String colId)
          Sets the current col for the test.
static void setCurrentResultSet(java.lang.String resultSetId)
          Sets the current resultset for the test.
static void setCurrentRow(java.lang.String rowId)
          Sets the current row for the test.
static void setObject(java.lang.String param, java.lang.Object obj)
          Sets an object keyed by the param string into the symbol table.
static void setSymbols(DatabaseResult target, DatabaseResult source, java.lang.String namespace)
          Updates the symbol table with variables from a target resultset that are populated by a SQL or stored procedure call.
static void setValue(java.lang.String param, java.lang.String value)
          Updates the symbol table with the symbol's value if it exists or creates a new entry in tha table with the given value if it does not.
static void update(DatabaseResult target, DatabaseResult source)
          Scans the source DatabaseResult and the symbol table and updates the target DatabaseResult object in place.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JAVA_OBJECT_SUPPORT

public static final java.lang.String JAVA_OBJECT_SUPPORT
Indicates if Java Object Support is enabled

See Also:
Constant Field Values

FAILURE_MESSAGE_OBJ

public static final java.lang.String FAILURE_MESSAGE_OBJ
Contains the failure message if available

See Also:
Constant Field Values

DEBUG_LOGGER

public static final java.lang.String DEBUG_LOGGER
Contains the debugging logger if set

See Also:
Constant Field Values

FILE_HEADER

public static final java.lang.String FILE_HEADER
Indicates that the value is a LOB file name

See Also:
Constant Field Values

OUT_PARAM

public static final java.lang.String OUT_PARAM
Contains outparam index mapping header

See Also:
Constant Field Values

TEST_ELAPSED_TIME

public static final java.lang.String TEST_ELAPSED_TIME
Contains elapsed time for a test in milliseconds

See Also:
Constant Field Values

CURRENT_RESULTSET_KEY

public static final java.lang.String CURRENT_RESULTSET_KEY
Keeps track of current resultset

See Also:
Constant Field Values

CURRENT_ROW_KEY

public static final java.lang.String CURRENT_ROW_KEY
Keeps track of current row in resultset

See Also:
Constant Field Values

CURRENT_COL_KEY

public static final java.lang.String CURRENT_COL_KEY
Keeps track of current column in row

See Also:
Constant Field Values

REPORTER_KEY

public static final java.lang.String REPORTER_KEY
Holds a reference to the Reporter object

See Also:
Constant Field Values

SKIP_REASON

public static final java.lang.String SKIP_REASON
Holds a reference to the most recent skipped reason

See Also:
Constant Field Values
Method Detail

getObject

public static java.lang.Object getObject(java.lang.String param)
Returns an object keyed by the param string from the symbol table.

Parameters:
param - the key into the symbol table.
Returns:
an Object at that position, null if none is available.

setObject

public static void setObject(java.lang.String param,
                             java.lang.Object obj)
Sets an object keyed by the param string into the symbol table.

Parameters:
param - the key into the symbol table.
obj - the object keyed by the param value.

getValue

public static java.lang.String getValue(java.lang.String param)
Returns the value of the named variable. The variable should look like ${varname}.

Parameters:
param - the key into the symbol table.
Returns:
the value of the named variable, or null if the variable does not exist in the symbol table.

setValue

public static void setValue(java.lang.String param,
                            java.lang.String value)
Updates the symbol table with the symbol's value if it exists or creates a new entry in tha table with the given value if it does not.

Parameters:
param - the variable name.
value - the value of the variable.

getSymbols

public static java.util.Iterator getSymbols()
Returns an Iterator containing all the symbols in the Symbol table.

Returns:
an Iterator.

removeSymbol

public static java.lang.String removeSymbol(java.lang.String param)
Removes a symbol from the symbol table.

Parameters:
param - the variable name to remove.
Returns:
the value of the variable, may be null if symbol does not exist.

setSymbols

public static void setSymbols(DatabaseResult target,
                              DatabaseResult source,
                              java.lang.String namespace)
                       throws SQLUnitException
Updates the symbol table with variables from a target resultset that are populated by a SQL or stored procedure call. The variables will be prefixed by the value of namespace.

Parameters:
target - the target DatabaseResult containing variables.
source - the source DatabaseResult generated by a SQL or stored procedure call.
namespace - the namespace in which the variables will be stored.
Throws:
SQLUnitException - if there was a problem.

update

public static void update(DatabaseResult target,
                          DatabaseResult source)
                   throws SQLUnitException
Scans the source DatabaseResult and the symbol table and updates the target DatabaseResult object in place. The client will have access to the updated target DatabaseResult since it is passed by reference. The variables to be substituted will need to be specified in the form ${variable}.

Parameters:
source - the source DatabaseResult returned from the SQL call.
target - the target DatabaseResult to update.
Throws:
SQLUnitException - if a variable does not appear in either the source or the symbol table.

isVariableName

public static boolean isVariableName(java.lang.String str)
By definition, a string which matches the pattern ${var} is considered to be a variable name in SQLUnit.

Parameters:
str - the String to check if it is a symbol.
Returns:
true if the str is a symbol, false if not.

replaceVariables

public static java.lang.String replaceVariables(java.lang.String text)
                                         throws SQLUnitException
Replaces all variables in a string from the symbol table.

Parameters:
text - the text with replaceable variables.
Returns:
the text with the variables replaced with the values.
Throws:
SQLUnitException - if one or more variables is not found.

setCurrentResultSet

public static void setCurrentResultSet(java.lang.String resultSetId)
Sets the current resultset for the test.

Parameters:
resultSetId - the id of the resultset tag.

setCurrentRow

public static void setCurrentRow(java.lang.String rowId)
Sets the current row for the test.

Parameters:
rowId - the id of the row tag.

setCurrentCol

public static void setCurrentCol(java.lang.String colId)
Sets the current col for the test.

Parameters:
colId - the id of the col tag.

getCurrentResultKey

public static java.lang.String getCurrentResultKey()
Returns the current result key as a String. The format of the String is result[resultsetId,rowId,colId].

Returns:
the current result as String.

removeUserVariables

public static void removeUserVariables()
Removes the references to the user variables set in a test after all tests are completed.


dump

public static void dump()
Dumps the contents of the symbol table for inspection.