net.sourceforge.sqlunit.test.mock
Class MockResultSetUtils

java.lang.Object
  extended by net.sourceforge.sqlunit.test.mock.MockResultSetUtils

public final class MockResultSetUtils
extends java.lang.Object

Collection of utility methods to manipulate MockResultSets.

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

Method Summary
static com.mockrunner.mock.jdbc.MockResultSetMetaData buildMetaData(ColumnMetaData[] cols)
          Convenience method to build a ResultSetMetaData object using data passed in through the array of ColumnMetaData objects.
static com.mockrunner.mock.jdbc.MockResultSet buildScalarOutParam(java.lang.String value)
          Convenience method to build a scalar out parameter as a resultset.
static com.mockrunner.mock.jdbc.MockResultSet buildSQLExceptionResultSet(int sqlCode, java.lang.String message)
          Convenience method for creating a ResultSet object with an embedded SQLException.
static com.mockrunner.mock.jdbc.MockResultSet buildZerothResultSet(int numResultSets)
          Convenience method to return the zero-th result set.
static com.mockrunner.mock.jdbc.MockResultSet buildZerothResultSetWithUpdateCount(int updateCount)
          Sets the update count as the second column in the mock resultset for returning number of results (position 0).
static int getNumberOfResultSets(com.mockrunner.mock.jdbc.MockResultSet mrs)
          Convenience method to return the number of resultsets available for this query by parsing the MockResultSet returned at index 0.
static java.lang.Object getOutParam(com.mockrunner.mock.jdbc.MockResultSet mrs, int sqlType)
          Convenience method to extract a scalar out parameter from a resultset.
static java.sql.SQLException getSQLExceptionFromResultSet(com.mockrunner.mock.jdbc.MockResultSet mrs)
          Convenience method to parse out and return the embedded SQLException object from the specified ResultSet object.
static int getUpdateCount(com.mockrunner.mock.jdbc.MockResultSet mrs)
          Parses the update count from the MockResultSet passed in.
static boolean isSQLException(com.mockrunner.mock.jdbc.MockResultSet mrs)
          Convenience method to determine if the ResultSet is an Exception resultset.
static java.lang.String replaceParameters(java.lang.String oldString, java.util.Map parameterMap)
          Replaces the positional parameters in a parameterized SQL string with appropriate values from the parameter map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

buildZerothResultSet

public static com.mockrunner.mock.jdbc.MockResultSet buildZerothResultSet(int numResultSets)
Convenience method to return the zero-th result set. We use this to keep the number of resultsets that must be returned from the method representing the SQL call. This method is expected to be called from subclasses of the AbstractMockDatabase class.

Parameters:
numResultSets - the number of result sets returned by this SQL.
Returns:
a MockResultSet object.

getNumberOfResultSets

public static int getNumberOfResultSets(com.mockrunner.mock.jdbc.MockResultSet mrs)
Convenience method to return the number of resultsets available for this query by parsing the MockResultSet returned at index 0. If the resultset is not a COUNT resultset, then it returns -1.

Parameters:
mrs - a MockResultSet object.
Returns:
the number of ResultSets available for this query.

buildZerothResultSetWithUpdateCount

public static com.mockrunner.mock.jdbc.MockResultSet buildZerothResultSetWithUpdateCount(int updateCount)
Sets the update count as the second column in the mock resultset for returning number of results (position 0).

Parameters:
updateCount - the count of the number of rows updated.
Returns:
a MockResultSet containing the update count.

getUpdateCount

public static int getUpdateCount(com.mockrunner.mock.jdbc.MockResultSet mrs)
Parses the update count from the MockResultSet passed in.

Parameters:
mrs - a MockResultSet object returned from the zeroth position.
Returns:
the update count.

buildScalarOutParam

public static com.mockrunner.mock.jdbc.MockResultSet buildScalarOutParam(java.lang.String value)
Convenience method to build a scalar out parameter as a resultset.

Parameters:
value - the String value of the parameter.
Returns:
a MockResultSet object.

getOutParam

public static java.lang.Object getOutParam(com.mockrunner.mock.jdbc.MockResultSet mrs,
                                           int sqlType)
Convenience method to extract a scalar out parameter from a resultset. The object is cast to the appropriate class based on the object's metadata.

Parameters:
mrs - a MockResult object.
sqlType - the SQL type of the object.
Returns:
an Object representing the out parameter at that position.

buildSQLExceptionResultSet

public static com.mockrunner.mock.jdbc.MockResultSet buildSQLExceptionResultSet(int sqlCode,
                                                                                java.lang.String message)
Convenience method for creating a ResultSet object with an embedded SQLException.

Parameters:
sqlCode - the SQLException sqlCode value.
message - the SQLException message value.
Returns:
a MockResultSet.

isSQLException

public static boolean isSQLException(com.mockrunner.mock.jdbc.MockResultSet mrs)
Convenience method to determine if the ResultSet is an Exception resultset.

Parameters:
mrs - the MockResultSet object.
Returns:
true if the resultset represents an SQLException, else false.

getSQLExceptionFromResultSet

public static java.sql.SQLException getSQLExceptionFromResultSet(com.mockrunner.mock.jdbc.MockResultSet mrs)
Convenience method to parse out and return the embedded SQLException object from the specified ResultSet object.

Parameters:
mrs - the MockResultSet object.
Returns:
an SQLException object.

buildMetaData

public static com.mockrunner.mock.jdbc.MockResultSetMetaData buildMetaData(ColumnMetaData[] cols)
Convenience method to build a ResultSetMetaData object using data passed in through the array of ColumnMetaData objects.

Parameters:
cols - an array of ColumnMetaData objects.
Returns:
a MockResultSetMetaData object.

replaceParameters

public static java.lang.String replaceParameters(java.lang.String oldString,
                                                 java.util.Map parameterMap)
Replaces the positional parameters in a parameterized SQL string with appropriate values from the parameter map.

Parameters:
oldString - the parameterized SQL string.
parameterMap - a Map of parameters.
Returns:
the unparameterized String.