|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.mockrunner.jdbc.AbstractResultSetHandler
Abstract base class for all ResultSet handlers.
Used to coordinate ResultSet objects for a
statement. You can use this class to prepare ResultSet
objects and update count values that are returned by the
execute method of a statement, if the current
SQL string matches.
Furthermore it can be used to create ResultSet objects.
Please note that the ResultSet objects you create and
prepare with this handler are cloned when executing statements.
So you cannot rely on object identity. You have to use the id
of the ResultSet to identify it.
The ResultSet objects returned by getReturnedResultSets()
are actually the instances the executed statements returned.
| Constructor Summary | |
AbstractResultSetHandler()
|
|
| Method Summary | |
void |
addExecutedStatement(java.lang.String sql)
Collects all SQL strings that were executed. |
void |
addReturnedResultSet(MockResultSet resultSet)
Collects all ResultSet objects that were returned by
a Statement, PreparedStatement or
CallableStatement. |
void |
clearGlobalResultSet()
Clears the global ResultSet. |
void |
clearResultSets()
Clears the ResultSet objects. |
void |
clearReturnsResultSet()
Clears the definitions if statements return ResultSet objects or update counts. |
void |
clearThrowsSQLException()
Clears the list of statements that should throw an exception. |
void |
clearUpdateCounts()
Clears the update counts. |
MockResultSet |
createResultSet()
Creates a new ResultSet with a
random id. |
MockResultSet |
createResultSet(ResultSetFactory factory)
Returns a new ResultSet created by
the specified factory. |
MockResultSet |
createResultSet(java.lang.String id)
Creates a new ResultSet with the specified id. |
MockResultSet |
createResultSet(java.lang.String id,
ResultSetFactory factory)
Returns a new ResultSet created by
the specified factory. |
protected boolean |
getCaseSensitive()
Returns if specified SQL strings should be handled case sensitive. |
protected boolean |
getExactMatch()
Returns if specified SQL statements must match exactly. |
java.util.List |
getExecutedStatements()
Returns the List of all executed SQL strings. |
MockResultSet |
getGlobalResultSet()
Returns the global ResultSet. |
int |
getGlobalUpdateCount()
Returns the global update count for executeUpdate
calls. |
MockResultSet |
getResultSet(java.lang.String sql)
Returns the first ResultSet that matches the
specified SQL string. |
java.util.Map |
getResultSetMap()
Returns the Map of all ResultSet
objects, that were added with prepareResultSet(String, MockResultSet). |
java.util.List |
getReturnedResultSets()
Returns the List of all returned ResultSet objects. |
java.lang.Boolean |
getReturnsResultSet(java.lang.String sql)
Returns if the specified SQL string is a select that returns a ResultSet. |
boolean |
getThrowsSQLException(java.lang.String sql)
Returns if the specified SQL string should raise an exception. |
java.lang.Integer |
getUpdateCount(java.lang.String sql)
Returns the first update count that matches the specified SQL string. |
java.util.Map |
getUpdateCountMap()
Returns the Map of all update counts, that were added
with prepareUpdateCount(String, int). |
protected boolean |
getUseRegularExpressions()
Returns if regular expression matching is enabled |
void |
prepareGlobalResultSet(MockResultSet resultSet)
Prepare the global ResultSet. |
void |
prepareGlobalUpdateCount(int updateCount)
Prepare the global update count for executeUpdate calls. |
void |
prepareResultSet(java.lang.String sql,
MockResultSet resultSet)
Prepare a ResultSet for a specified SQL string. |
void |
prepareReturnsResultSet(java.lang.String sql,
boolean returnsResultSet)
Prepare if the specified SQL string is a select that returns a ResultSet. |
void |
prepareThrowsSQLException(java.lang.String sql)
Prepare if the specified SQL string should raise an exception. |
void |
prepareUpdateCount(java.lang.String sql,
int updateCount)
Prepare the update count for executeUpdate calls
for a specified SQL string. |
void |
setCaseSensitive(boolean caseSensitive)
Set if specified SQL strings should be handled case sensitive. |
void |
setExactMatch(boolean exactMatch)
Set if specified SQL statements must match exactly. |
void |
setUseRegularExpressions(boolean useRegularExpressions)
Set if regular expressions should be used when matching SQL statements. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public AbstractResultSetHandler()
| Method Detail |
public MockResultSet createResultSet()
ResultSet with a
random id.
ResultSetpublic MockResultSet createResultSet(java.lang.String id)
ResultSet with the specified id.
id - the id
ResultSetpublic MockResultSet createResultSet(ResultSetFactory factory)
ResultSet created by
the specified factory. Currently there's only
the FileResultSetFactory to create ResultSet
objects based on CSV files but you can implement your own factories.
factory - the ResultSetFactory
ResultSet
public MockResultSet createResultSet(java.lang.String id,
ResultSetFactory factory)
ResultSet created by
the specified factory. Currently there's only
the FileResultSetFactory to create ResultSet
objects based on CSV files but you can implement your own factories.
Uses a random id.
id - the idfactory - the ResultSetFactory
ResultSetpublic void setCaseSensitive(boolean caseSensitive)
false, i.e. INSERT is the same
as insert.
Please note that this method controls SQL statement
matching for prepared results and update counts, i.e. what
statements the tested application has to execute to receive
a specified result. Unlike JDBCTestModule.setCaseSensitive(boolean)
it does not control the statement matching of JDBCTestModule
methods.
caseSensitive - enable or disable case sensitivitypublic void setExactMatch(boolean exactMatch)
false, i.e. the SQL string
does not need to match exactly. If the original statement
is insert into mytable values(?, ?, ?)
the string insert into mytable will match this statement.
Usually false is the best choice, so
prepared ResultSet objects do not have
to match exactly the current statements SQL string.
Please note that this method controls SQL statement
matching for prepared results and update counts, i.e. what
statements the tested application has to execute to receive
a specified result. Unlike JDBCTestModule.setExactMatch(boolean)
it does not control the statement matching of JDBCTestModule
methods.
exactMatch - enable or disable exact matchingpublic void setUseRegularExpressions(boolean useRegularExpressions)
exactMatch is
true. Default is false, i.e. you
cannot use regular expressions and matching is based
on string comparison (which is much faster). Enable
this feature only if necessary.
Please note that this method controls SQL statement
matching for prepared results and update counts, i.e. what
statements the tested application has to execute to receive
a specified result. Unlike JDBCTestModule.setUseRegularExpressions(boolean)
it does not control the statement matching of JDBCTestModule
methods.
useRegularExpressions - should regular expressions be usedpublic void addExecutedStatement(java.lang.String sql)
sql - the SQL stringpublic void addReturnedResultSet(MockResultSet resultSet)
ResultSet objects that were returned by
a Statement, PreparedStatement or
CallableStatement.
resultSet - the ResultSetpublic java.util.List getExecutedStatements()
List of all executed SQL strings.
List of executed SQL stringspublic java.util.List getReturnedResultSets()
List of all returned ResultSet objects.
List of returned ResultSet objectspublic void clearResultSets()
ResultSet objects.
public void clearUpdateCounts()
public void clearReturnsResultSet()
ResultSet objects or update counts.
public void clearThrowsSQLException()
public java.util.Map getResultSetMap()
Map of all ResultSet
objects, that were added with prepareResultSet(String, MockResultSet).
The SQL strings map to the corresponding ResultSet.
Map of ResultSet objectspublic java.util.Map getUpdateCountMap()
Map of all update counts, that were added
with prepareUpdateCount(String, int).
The SQL strings map to the corresponding update count as
Integer object.
Map of ResultSet objectspublic MockResultSet getResultSet(java.lang.String sql)
ResultSet that matches the
specified SQL string. Please note that you can modify
the match parameters with setCaseSensitive(boolean),
setExactMatch(boolean) and setUseRegularExpressions(boolean).
sql - the SQL string
MockResultSetpublic MockResultSet getGlobalResultSet()
ResultSet.
The statement returns the global ResultSet
if no ResultSet can be found for the current
SQL string.
MockResultSetpublic java.lang.Integer getUpdateCount(java.lang.String sql)
setCaseSensitive(boolean),
setExactMatch(boolean) and setUseRegularExpressions(boolean).
sql - the SQL string
public int getGlobalUpdateCount()
executeUpdate
calls.
The statement returns the global update count
if no update count can be found for the current
SQL string.
public java.lang.Boolean getReturnsResultSet(java.lang.String sql)
ResultSet.
Usually you do not have to specify this.
It is assumed that an SQL string returns a ResultSet
if it contains SELECT.
Please note that you can modify the match parameters with
setCaseSensitive(boolean), setExactMatch(boolean) and
setUseRegularExpressions(boolean).
sql - the SQL string
true if the SQL string returns a ResultSetpublic boolean getThrowsSQLException(java.lang.String sql)
setCaseSensitive(boolean), setExactMatch(boolean) and
setUseRegularExpressions(boolean).
sql - the SQL string
true if the specified SQL string should raise an exception,
false otherwise
public void prepareResultSet(java.lang.String sql,
MockResultSet resultSet)
ResultSet for a specified SQL string.
Please note that you can modify the match parameters with
setCaseSensitive(boolean), setExactMatch(boolean) and
setUseRegularExpressions(boolean).
sql - the SQL stringresultSet - the corresponding MockResultSetpublic void prepareGlobalResultSet(MockResultSet resultSet)
ResultSet.
The statement returns the global ResultSet
if no ResultSet can be found for the current
SQL string.
resultSet - the MockResultSet
public void prepareUpdateCount(java.lang.String sql,
int updateCount)
executeUpdate calls
for a specified SQL string. Please note that you can modify
the match parameters with setCaseSensitive(boolean),
setExactMatch(boolean) and setUseRegularExpressions(boolean).
sql - the SQL stringupdateCount - the update countpublic void prepareGlobalUpdateCount(int updateCount)
executeUpdate calls.
The statement returns the global update count
if no update count can be found for the current
SQL string.
updateCount - the update count
public void prepareReturnsResultSet(java.lang.String sql,
boolean returnsResultSet)
ResultSet. Usually you do not have to specify this.
It is assumed that an SQL string returns a ResultSet
if it contains SELECT.
Please note that you can modify the match parameters with
setCaseSensitive(boolean), setExactMatch(boolean) and
setUseRegularExpressions(boolean).
sql - the SQL stringreturnsResultSet - specify if the SQL string returns a ResultSetpublic void prepareThrowsSQLException(java.lang.String sql)
setCaseSensitive(boolean), setExactMatch(boolean) and
setUseRegularExpressions(boolean).
sql - the SQL stringpublic void clearGlobalResultSet()
ResultSet.
protected boolean getCaseSensitive()
protected boolean getExactMatch()
protected boolean getUseRegularExpressions()
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||