com.mockrunner.jdbc
Class AbstractParameterResultSetHandler

java.lang.Object
  extended bycom.mockrunner.jdbc.AbstractResultSetHandler
      extended bycom.mockrunner.jdbc.AbstractParameterResultSetHandler
Direct Known Subclasses:
AbstractOutParameterResultSetHandler, PreparedStatementResultSetHandler

public abstract class AbstractParameterResultSetHandler
extends AbstractResultSetHandler

Abstract base class for all statement types that support parameters, i.e. PreparedStatement and CallableStatement.


Constructor Summary
AbstractParameterResultSetHandler()
           
 
Method Summary
 void addParameterMapForExecutedStatement(java.lang.String sql, java.util.Map parameters)
          Collects all SQL strings that were executed.
 void clearResultSets()
          Clears the ResultSet objects.
 void clearThrowsSQLException()
          Clears the list of statements that should throw an exception
 void clearUpdateCounts()
          Clears the update counts.
protected  boolean doParameterMatch(java.util.Map expectedParameters, java.util.Map actualParameters)
           
 java.util.Map getExecutedStatementParameter()
          Returns the Map of executed SQL strings.
 ParameterSets getParametersForExecutedStatement(java.lang.String sql)
          Returns the ParameterSets for a specified SQL string.
 MockResultSet getResultSet(java.lang.String sql, java.util.Map parameters)
          Returns the first ResultSet that matches the specified SQL string and the specified parameters.
 boolean getThrowsSQLException(java.lang.String sql, java.util.Map parameters)
          Returns if the specified SQL string with the specified parameters should raise an exception.
 java.lang.Integer getUpdateCount(java.lang.String sql, java.util.Map parameters)
          Returns the first update count that matches the specified SQL string and the specified parameters.
 void prepareResultSet(java.lang.String sql, MockResultSet resultSet, java.util.List parameters)
          Prepare a ResultSet for a specified SQL string and the specified parameters.
 void prepareResultSet(java.lang.String sql, MockResultSet resultSet, java.util.Map parameters)
          Prepare a ResultSet for a specified SQL string and the specified parameters.
 void prepareResultSet(java.lang.String sql, MockResultSet resultSet, java.lang.Object[] parameters)
          Prepare a ResultSet for a specified SQL string and the specified parameters.
 void prepareThrowsSQLException(java.lang.String sql, java.util.List parameters)
          Prepare if the specified SQL string with the specified parameters should raise an exception.
 void prepareThrowsSQLException(java.lang.String sql, java.util.Map parameters)
          Prepare if the specified SQL string with the specified parameters should raise an exception.
 void prepareThrowsSQLException(java.lang.String sql, java.lang.Object[] parameters)
          Prepare if the specified SQL string with the specified parameters should raise an exception.
 void prepareUpdateCount(java.lang.String sql, int updateCount, java.util.List parameters)
          Prepare the update count for execute update calls for a specified SQL string and the specified parameters.
 void prepareUpdateCount(java.lang.String sql, int updateCount, java.util.Map parameters)
          Prepare the update count for execute update calls for a specified SQL string and the specified parameters.
 void prepareUpdateCount(java.lang.String sql, int updateCount, java.lang.Object[] parameters)
          Prepare the update count for execute update calls for a specified SQL string and the specified parameters.
 void setExactMatchParameter(boolean exactMatchParameter)
          Sets if the specified parameters must match exactly in order and number.
 
Methods inherited from class com.mockrunner.jdbc.AbstractResultSetHandler
addExecutedStatement, addReturnedResultSet, clearGlobalResultSet, clearReturnsResultSet, createResultSet, createResultSet, createResultSet, createResultSet, getCaseSensitive, getExactMatch, getExecutedStatements, getGlobalResultSet, getGlobalUpdateCount, getResultSet, getResultSetMap, getReturnedResultSets, getReturnsResultSet, getThrowsSQLException, getUpdateCount, getUpdateCountMap, getUseRegularExpressions, prepareGlobalResultSet, prepareGlobalUpdateCount, prepareResultSet, prepareReturnsResultSet, prepareThrowsSQLException, prepareUpdateCount, setCaseSensitive, setExactMatch, setUseRegularExpressions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractParameterResultSetHandler

public AbstractParameterResultSetHandler()
Method Detail

addParameterMapForExecutedStatement

public void addParameterMapForExecutedStatement(java.lang.String sql,
                                                java.util.Map parameters)
Collects all SQL strings that were executed.

Parameters:
sql - the SQL string
parameters - a copy of the corresponding parameter map

getParametersForExecutedStatement

public ParameterSets getParametersForExecutedStatement(java.lang.String sql)
Returns the ParameterSets for a specified SQL string.

Parameters:
sql - the SQL string
Returns:
the Map of parameters

getExecutedStatementParameter

public java.util.Map getExecutedStatementParameter()
Returns the Map of executed SQL strings. Each string maps to the corresponding ParameterSets object.

Returns:
the Map of parameters

setExactMatchParameter

public void setExactMatchParameter(boolean exactMatchParameter)
Sets if the specified parameters must match exactly in order and number. Defaults to false, i.e. the specified parameters must be present in the actual parameter list of the prepared statement with the correct index but it's ok if there are more actual parameters.

Parameters:
exactMatchParameter - must parameters match exactly

getUpdateCount

public java.lang.Integer getUpdateCount(java.lang.String sql,
                                        java.util.Map parameters)
Returns the first update count that matches the specified SQL string and the specified parameters. Please note that you can modify the match parameters with AbstractResultSetHandler.setCaseSensitive(boolean), AbstractResultSetHandler.setExactMatch(boolean) and AbstractResultSetHandler.setUseRegularExpressions(boolean) and the match parameters for the specified parameter list with setExactMatchParameter(boolean).

Parameters:
sql - the SQL string
parameters - the parameters
Returns:
the corresponding update count

getResultSet

public MockResultSet getResultSet(java.lang.String sql,
                                  java.util.Map parameters)
Returns the first ResultSet that matches the specified SQL string and the specified parameters. Please note that you can modify the match parameters with AbstractResultSetHandler.setCaseSensitive(boolean), AbstractResultSetHandler.setExactMatch(boolean) and AbstractResultSetHandler.setUseRegularExpressions(boolean) and the match parameters for the specified parameter list with setExactMatchParameter(boolean).

Parameters:
sql - the SQL string
parameters - the parameters
Returns:
the corresponding MockResultSet

getThrowsSQLException

public boolean getThrowsSQLException(java.lang.String sql,
                                     java.util.Map parameters)
Returns if the specified SQL string with the specified parameters should raise an exception. This can be used to simulate database exceptions. Please note that you can modify the match parameters with AbstractResultSetHandler.setCaseSensitive(boolean), AbstractResultSetHandler.setExactMatch(boolean) and AbstractResultSetHandler.setUseRegularExpressions(boolean) and the match parameters for the specified parameter list with setExactMatchParameter(boolean).

Parameters:
sql - the SQL string
parameters - the parameters
Returns:
true if the specified SQL string should raise an exception, false otherwise

doParameterMatch

protected boolean doParameterMatch(java.util.Map expectedParameters,
                                   java.util.Map actualParameters)

clearResultSets

public void clearResultSets()
Clears the ResultSet objects.

Overrides:
clearResultSets in class AbstractResultSetHandler

clearUpdateCounts

public void clearUpdateCounts()
Clears the update counts.

Overrides:
clearUpdateCounts in class AbstractResultSetHandler

clearThrowsSQLException

public void clearThrowsSQLException()
Clears the list of statements that should throw an exception

Overrides:
clearThrowsSQLException in class AbstractResultSetHandler

prepareResultSet

public void prepareResultSet(java.lang.String sql,
                             MockResultSet resultSet,
                             java.lang.Object[] parameters)
Prepare a ResultSet for a specified SQL string and the specified parameters. The specified parameters array must contain the parameters in the correct order starting with 0 as the first parameter. Please keep in mind that parameters in PreparedStatement objects start with 1 as the first parameter. So parameters[0] maps to the parameter with index 1. Please note that you can modify the match parameters with AbstractResultSetHandler.setCaseSensitive(boolean), AbstractResultSetHandler.setExactMatch(boolean) and AbstractResultSetHandler.setUseRegularExpressions(boolean) and the match parameters for the specified parameter list with setExactMatchParameter(boolean).

Parameters:
sql - the SQL string
resultSet - the corresponding MockResultSet
parameters - the parameters

prepareResultSet

public void prepareResultSet(java.lang.String sql,
                             MockResultSet resultSet,
                             java.util.List parameters)
Prepare a ResultSet for a specified SQL string and the specified parameters. The specified parameters List must contain the parameters in the correct order starting with 0 as the first parameter. Please keep in mind that parameters in PreparedStatement objects start with 1 as the first parameter. So parameters.get(0) maps to the parameter with index 1. Please note that you can modify the match parameters with AbstractResultSetHandler.setCaseSensitive(boolean), AbstractResultSetHandler.setExactMatch(boolean) and AbstractResultSetHandler.setUseRegularExpressions(boolean) and the match parameters for the specified parameter list with setExactMatchParameter(boolean).

Parameters:
sql - the SQL string
resultSet - the corresponding MockResultSet
parameters - the parameters

prepareResultSet

public void prepareResultSet(java.lang.String sql,
                             MockResultSet resultSet,
                             java.util.Map parameters)
Prepare a ResultSet for a specified SQL string and the specified parameters. The specified parameters Map must contain the parameters by mapping Integer objects to the corresponding parameter. The Integer object is the index of the parameter. In the case of a CallableStatement there are also allowed String keys for named parameters. Please note that you can modify the match parameters with AbstractResultSetHandler.setCaseSensitive(boolean), AbstractResultSetHandler.setExactMatch(boolean) and AbstractResultSetHandler.setUseRegularExpressions(boolean) and the match parameters for the specified parameter list with setExactMatchParameter(boolean).

Parameters:
sql - the SQL string
resultSet - the corresponding MockResultSet
parameters - the parameters

prepareThrowsSQLException

public void prepareThrowsSQLException(java.lang.String sql,
                                      java.lang.Object[] parameters)
Prepare if the specified SQL string with the specified parameters should raise an exception. This can be used to simulate database exceptions. The specified parameters array must contain the parameters in the correct order starting with 0 as the first parameter. Please keep in mind that parameters in PreparedStatement objects start with 1 as the first parameter. So parameters[0] maps to the parameter with index 1. Please note that you can modify the match parameters with AbstractResultSetHandler.setCaseSensitive(boolean), AbstractResultSetHandler.setExactMatch(boolean) and AbstractResultSetHandler.setUseRegularExpressions(boolean) and the match parameters for the specified parameter list with setExactMatchParameter(boolean).

Parameters:
sql - the SQL string
parameters - the parameters

prepareThrowsSQLException

public void prepareThrowsSQLException(java.lang.String sql,
                                      java.util.List parameters)
Prepare if the specified SQL string with the specified parameters should raise an exception. This can be used to simulate database exceptions. The specified parameters List must contain the parameters in the correct order starting with 0 as the first parameter. Please keep in mind that parameters in PreparedStatement objects start with 1 as the first parameter. So parameters.get(0) maps to the parameter with index 1. Please note that you can modify the match parameters with AbstractResultSetHandler.setCaseSensitive(boolean), AbstractResultSetHandler.setExactMatch(boolean) and AbstractResultSetHandler.setUseRegularExpressions(boolean) and the match parameters for the specified parameter list with setExactMatchParameter(boolean).

Parameters:
sql - the SQL string
parameters - the parameters

prepareThrowsSQLException

public void prepareThrowsSQLException(java.lang.String sql,
                                      java.util.Map parameters)
Prepare if the specified SQL string with the specified parameters should raise an exception. This can be used to simulate database exceptions. Please note that you can modify the match parameters with AbstractResultSetHandler.setCaseSensitive(boolean), AbstractResultSetHandler.setExactMatch(boolean) and AbstractResultSetHandler.setUseRegularExpressions(boolean) and the match parameters for the specified parameter list with setExactMatchParameter(boolean).

Parameters:
sql - the SQL string
parameters - the parameters

prepareUpdateCount

public void prepareUpdateCount(java.lang.String sql,
                               int updateCount,
                               java.lang.Object[] parameters)
Prepare the update count for execute update calls for a specified SQL string and the specified parameters. The specified parameters array must contain the parameters in the correct order starting with 0 as the first parameter. Please keep in mind that parameters in PreparedStatement objects start with 1 as the first parameter. So parameters[0] maps to the parameter with index 1. Please note that you can modify the match parameters with AbstractResultSetHandler.setCaseSensitive(boolean), AbstractResultSetHandler.setExactMatch(boolean) and AbstractResultSetHandler.setUseRegularExpressions(boolean) and the match parameters for the specified parameter list with setExactMatchParameter(boolean).

Parameters:
sql - the SQL string
updateCount - the update count
parameters - the parameters

prepareUpdateCount

public void prepareUpdateCount(java.lang.String sql,
                               int updateCount,
                               java.util.List parameters)
Prepare the update count for execute update calls for a specified SQL string and the specified parameters. The specified parameters List must contain the parameters in the correct order starting with 0 as the first parameter. Please keep in mind that parameters in PreparedStatement objects start with 1 as the first parameter. So parameters.get(0) maps to the parameter with index 1. Please note that you can modify the match parameters with AbstractResultSetHandler.setCaseSensitive(boolean), AbstractResultSetHandler.setExactMatch(boolean) and AbstractResultSetHandler.setUseRegularExpressions(boolean) and the match parameters for the specified parameter list with setExactMatchParameter(boolean).

Parameters:
sql - the SQL string
updateCount - the update count
parameters - the parameters

prepareUpdateCount

public void prepareUpdateCount(java.lang.String sql,
                               int updateCount,
                               java.util.Map parameters)
Prepare the update count for execute update calls for a specified SQL string and the specified parameters. The specified parameters Map must contain the parameters by mapping Integer objects to the corresponding parameter. The Integer object is the index of the parameter. In the case of a CallableStatement there are also allowed String keys for named parameters. Please note that you can modify the match parameters with AbstractResultSetHandler.setCaseSensitive(boolean), AbstractResultSetHandler.setExactMatch(boolean) and AbstractResultSetHandler.setUseRegularExpressions(boolean) and the match parameters for the specified parameter list with setExactMatchParameter(boolean).

Parameters:
sql - the SQL string
updateCount - the update count
parameters - the parameters