net.sourceforge.sqlunit.test.mock
Class IntrospectingResultSetFactory

java.lang.Object
  extended by net.sourceforge.sqlunit.test.mock.IntrospectingResultSetFactory
All Implemented Interfaces:
com.mockrunner.jdbc.ResultSetFactory

public class IntrospectingResultSetFactory
extends java.lang.Object
implements com.mockrunner.jdbc.ResultSetFactory

Introspects a given IMockDataStore object and invokes the named method to return ResultSet objects.

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

Constructor Summary
IntrospectingResultSetFactory(java.lang.String mockDbClassName)
          Instantiate a Introspecting Result Set Factory using the classname of the IMockDataStore object.
 
Method Summary
 com.mockrunner.mock.jdbc.MockResultSet create(java.lang.String sql)
          Build a mockresultset object using the method id.
 com.mockrunner.mock.jdbc.MockResultSet create(java.lang.String sql, int rsIndex)
          Returns the resultset for the sql at the specified index.
 int getNumberOfResultSets(java.lang.String sql)
          Convenience method to return the number of result sets for a particular SQL query.
 java.lang.Object getOutParamValueAt(java.lang.String sql, int pIndex, int sqlType)
          Returns the outparam value at the specified position and converts to an object of the specified type.
 int getUpdateCount(java.lang.String sql)
          Convenience method to return the update count for an SQL which updates the database, such as INSERT, UPDATE or DELETE.
 int incrementIndex()
          Moves the resultset index up by 1.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IntrospectingResultSetFactory

public IntrospectingResultSetFactory(java.lang.String mockDbClassName)
Instantiate a Introspecting Result Set Factory using the classname of the IMockDataStore object.

Parameters:
mockDbClassName - the name of a class implementing the IMockDatabase interface and representing a particular database.
Method Detail

create

public final com.mockrunner.mock.jdbc.MockResultSet create(java.lang.String sql)
Build a mockresultset object using the method id. Delegates to the method and resultsetid in the IMockDatabase that was used for instantiating this factory.

Specified by:
create in interface com.mockrunner.jdbc.ResultSetFactory
Parameters:
sql - a string containing the sql to execute.
Returns:
a MockResultSet object.

create

public final com.mockrunner.mock.jdbc.MockResultSet create(java.lang.String sql,
                                                           int rsIndex)
Returns the resultset for the sql at the specified index.

Parameters:
sql - a string containing the sql to execute.
rsIndex - the index of the resultset to return.
Returns:
a MockResultSet object.

incrementIndex

public final int incrementIndex()
Moves the resultset index up by 1. If it is set to the default value of Integer.MIN_VALUE, then it is bumped up to 1 the first time.

Returns:
the new incremented index value.

getNumberOfResultSets

public final int getNumberOfResultSets(java.lang.String sql)
                                throws java.sql.SQLException
Convenience method to return the number of result sets for a particular SQL query. By convention, resultset 0 has a single row and column containing the number of resultsets to return.

Parameters:
sql - the string containing the SQL to execute.
Returns:
the number of resultsets for this query.
Throws:
java.sql.SQLException - if an error occurs.

getUpdateCount

public final int getUpdateCount(java.lang.String sql)
Convenience method to return the update count for an SQL which updates the database, such as INSERT, UPDATE or DELETE. If there is no update count declared in the procedure method, it will return -1.

Parameters:
sql - the string containing the SQL to execute.
Returns:
the update count for the SQL, or -1 if there was no updates.

getOutParamValueAt

public final java.lang.Object getOutParamValueAt(java.lang.String sql,
                                                 int pIndex,
                                                 int sqlType)
                                          throws java.sql.SQLException
Returns the outparam value at the specified position and converts to an object of the specified type.

Parameters:
sql - the SQL string to look up.
pIndex - the parameter index (1-based).
sqlType - the SQL Type to use for conversion.
Returns:
an Object representing the outparam.
Throws:
java.sql.SQLException - if an error occurs.