net.sourceforge.sqlunit.test.mock
Class SQLUnitMockPreparedStatement

java.lang.Object
  extended by com.mockrunner.mock.jdbc.MockStatement
      extended by com.mockrunner.mock.jdbc.MockPreparedStatement
          extended by net.sourceforge.sqlunit.test.mock.SQLUnitMockPreparedStatement
All Implemented Interfaces:
java.sql.PreparedStatement, java.sql.Statement

public class SQLUnitMockPreparedStatement
extends com.mockrunner.mock.jdbc.MockPreparedStatement

Overrides certain methods in the MockPreparedStatement class for mock testing of SQLUnit.

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

Field Summary
 
Fields inherited from interface java.sql.Statement
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO
 
Constructor Summary
SQLUnitMockPreparedStatement(java.sql.Connection conn, java.lang.String sql)
          Instantiate a SQLUnitMockPreparedStatement object using a Connection object and a SQL string.
 
Method Summary
 void addBatch()
          Parses and replaces positional parameters in the SQL string and adds it to the batch for executeBatch() to pick up.
 boolean execute()
          Invokes the named method on the MockDatabase using introspection.
 int[] executeBatch()
          Runs the batch list against the IntrospectingResultSetFactory to return an array of update counts.
 boolean getMoreResults()
          Returns true if there are more result sets available for this SQL.
 java.sql.ResultSet getResultSet()
          Returns the current result set from the SQL statement.
 int getUpdateCount()
          Returns the update count.
 void setObject(int index, java.lang.Object obj, int sqlType)
          Sets an object into the parameter map.
 void setResultSetHandler(com.mockrunner.jdbc.AbstractResultSetHandler aHandler)
          Sets the IntrospectingPreparedStatementResultSetHandler for the MockPreparedStatement.
 
Methods inherited from class com.mockrunner.mock.jdbc.MockPreparedStatement
clearParameters, executeBatch, executeQuery, executeQuery, executeUpdate, executeUpdate, getIndexedParameterMap, getMetaData, getParameter, getParameterMetaData, getSQL, setArray, setAsciiStream, setBigDecimal, setBinaryStream, setBlob, setBoolean, setByte, setBytes, setCharacterStream, setClob, setDate, setDate, setDouble, setFloat, setInt, setLong, setNull, setNull, setObject, setObject, setPreparedStatementResultSetHandler, setRef, setShort, setString, setTime, setTime, setTimestamp, setTimestamp, setUnicodeStream, setURL
 
Methods inherited from class com.mockrunner.mock.jdbc.MockStatement
addBatch, cancel, clearBatch, clearWarnings, cloneResultSet, close, execute, execute, execute, execute, executeQuery, executeUpdate, executeUpdate, executeUpdate, executeUpdate, getConnection, getCursorName, getFetchDirection, getFetchSize, getGeneratedKeys, getMaxFieldSize, getMaxRows, getMoreResults, getQueryTimeout, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getWarnings, isClosed, isQuery, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setMaxFieldSize, setMaxRows, setNextResultSet, setNextUpdateCount, setQueryTimeout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.sql.Statement
addBatch, cancel, clearBatch, clearWarnings, close, execute, execute, execute, execute, executeQuery, executeUpdate, executeUpdate, executeUpdate, executeUpdate, getConnection, getFetchDirection, getFetchSize, getGeneratedKeys, getMaxFieldSize, getMaxRows, getMoreResults, getQueryTimeout, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getWarnings, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setMaxFieldSize, setMaxRows, setQueryTimeout
 

Constructor Detail

SQLUnitMockPreparedStatement

public SQLUnitMockPreparedStatement(java.sql.Connection conn,
                                    java.lang.String sql)
Instantiate a SQLUnitMockPreparedStatement object using a Connection object and a SQL string.

Parameters:
conn - the Connection object.
sql - the SQL string.
Method Detail

setResultSetHandler

public final void setResultSetHandler(com.mockrunner.jdbc.AbstractResultSetHandler aHandler)
Sets the IntrospectingPreparedStatementResultSetHandler for the MockPreparedStatement.

Overrides:
setResultSetHandler in class com.mockrunner.mock.jdbc.MockStatement
Parameters:
aHandler - an IntrospectingPreparedStatementResultSetHandler object.

getMoreResults

public final boolean getMoreResults()
                             throws java.sql.SQLException
Returns true if there are more result sets available for this SQL.

Specified by:
getMoreResults in interface java.sql.Statement
Overrides:
getMoreResults in class com.mockrunner.mock.jdbc.MockStatement
Returns:
true if there are more result sets available, else false.
Throws:
java.sql.SQLException - if one is thrown.

getResultSet

public final java.sql.ResultSet getResultSet()
                                      throws java.sql.SQLException
Returns the current result set from the SQL statement.

Specified by:
getResultSet in interface java.sql.Statement
Overrides:
getResultSet in class com.mockrunner.mock.jdbc.MockStatement
Returns:
a MockResultSet object.
Throws:
java.sql.SQLException - if one is thrown.

execute

public final boolean execute()
                      throws java.sql.SQLException
Invokes the named method on the MockDatabase using introspection. The only method used to execute() a PreparedStatement is the execute. If other methods are used then we may want to override them too.

Specified by:
execute in interface java.sql.PreparedStatement
Overrides:
execute in class com.mockrunner.mock.jdbc.MockPreparedStatement
Returns:
true if the PreparedStatement contains a resultset.
Throws:
java.sql.SQLException - if there was a problem executing.

getUpdateCount

public final int getUpdateCount()
                         throws java.sql.SQLException
Returns the update count.

Specified by:
getUpdateCount in interface java.sql.Statement
Overrides:
getUpdateCount in class com.mockrunner.mock.jdbc.MockStatement
Returns:
the update count.
Throws:
java.sql.SQLException - if an error occurs.

setObject

public final void setObject(int index,
                            java.lang.Object obj,
                            int sqlType)
                     throws java.sql.SQLException
Sets an object into the parameter map.

Specified by:
setObject in interface java.sql.PreparedStatement
Overrides:
setObject in class com.mockrunner.mock.jdbc.MockPreparedStatement
Parameters:
index - the parameter index (1-based).
obj - the parameter Object.
sqlType - the SQL Type of the parameter.
Throws:
java.sql.SQLException - if an error occurs.

addBatch

public final void addBatch()
                    throws java.sql.SQLException
Parses and replaces positional parameters in the SQL string and adds it to the batch for executeBatch() to pick up.

Specified by:
addBatch in interface java.sql.PreparedStatement
Overrides:
addBatch in class com.mockrunner.mock.jdbc.MockPreparedStatement
Throws:
java.sql.SQLException - if there was a problem.

executeBatch

public final int[] executeBatch()
                         throws java.sql.SQLException
Runs the batch list against the IntrospectingResultSetFactory to return an array of update counts.

Specified by:
executeBatch in interface java.sql.Statement
Overrides:
executeBatch in class com.mockrunner.mock.jdbc.MockPreparedStatement
Returns:
an array of update counts.
Throws:
java.sql.SQLException - if there was a problem.