|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.mockrunner.jdbc.AbstractResultSetHandler
public abstract class 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 |
addReturnedResultSets(MockResultSet[] resultSets)
Collects all ResultSet[] objects that were returned by
a Statement, PreparedStatement or
CallableStatement. |
void |
clearGeneratedKeys()
Clears the list of statements that return generated keys. |
void |
clearGlobalGeneratedKeys()
Clears the prepared global generated keys ResultSet. |
void |
clearGlobalResultSet()
Clears the prepared global ResultSet. |
void |
clearGlobalUpdateCount()
Clears the prepared global update count. |
void |
clearResultSets()
Clears all prepared 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 all prepared 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. |
boolean |
getContinueProcessingOnBatchFailure()
Returns if batch processing should be continued if one of the commands in the batch fails. |
protected boolean |
getExactMatch()
Returns if specified SQL statements must match exactly. |
java.util.List |
getExecutedStatements()
Returns the List of all executed SQL strings. |
MockResultSet |
getGeneratedKeys(java.lang.String sql)
Returns the first generated keys ResultSet that
matches the specified SQL string. |
java.util.Map |
getGeneratedKeysMap()
Returns the Map of all generated keys ResultSet
objects, that were added with prepareGeneratedKeys(String, MockResultSet). |
MockResultSet |
getGlobalGeneratedKeys()
Returns the global generated keys ResultSet. |
MockResultSet |
getGlobalResultSet()
Returns the global ResultSet. |
MockResultSet[] |
getGlobalResultSets()
Returns the global ResultSet[]. |
int |
getGlobalUpdateCount()
Returns the global update count for executeUpdate calls. |
int[] |
getGlobalUpdateCounts()
Returns the array of global update counts. |
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). |
MockResultSet[] |
getResultSets(java.lang.String sql)
Returns the first ResultSet[] that matches the
specified SQL string. |
java.util.List |
getReturnedResultSets()
Returns the List of all returned ResultSet
or ResultSet[] objects. |
java.lang.Boolean |
getReturnsResultSet(java.lang.String sql)
Returns if the specified SQL string is a select that returns a ResultSet. |
java.sql.SQLException |
getSQLException(java.lang.String sql)
Returns the SQLException the specified SQL string
should throw. |
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). |
java.lang.Integer[] |
getUpdateCounts(java.lang.String sql)
Returns the first update count array that matches the specified SQL string. |
protected boolean |
getUseRegularExpressions()
Returns if regular expression matching is enabled |
boolean |
hasMultipleGlobalResultSets()
Returns if multiple global result sets have been prepared, i.e. if an array of global result sets was prepared. |
boolean |
hasMultipleGlobalUpdateCounts()
Returns if multiple global update counts have been prepared, i.e. if an array of global update counts was prepared. |
boolean |
hasMultipleResultSets(java.lang.String sql)
Returns the if the specified SQL string returns multiple result sets. |
boolean |
hasMultipleUpdateCounts(java.lang.String sql)
Returns the if the specified SQL string returns multiple update counts. |
void |
prepareGeneratedKeys(java.lang.String sql,
MockResultSet generatedKeysResult)
Prepare the generated keys ResultSet
for a specified SQL string. |
void |
prepareGlobalGeneratedKeys(MockResultSet generatedKeysResult)
Prepare the global generated keys ResultSet. |
void |
prepareGlobalResultSet(MockResultSet resultSet)
Prepare the global ResultSet. |
void |
prepareGlobalResultSets(MockResultSet[] resultSets)
Prepare an array of global ResultSet objects. |
void |
prepareGlobalUpdateCount(int updateCount)
Prepare the global update count for executeUpdate calls. |
void |
prepareGlobalUpdateCounts(int[] updateCounts)
Prepare an array of global update count values for executeUpdate calls. |
void |
prepareResultSet(java.lang.String sql,
MockResultSet resultSet)
Prepare a ResultSet for a specified SQL string. |
void |
prepareResultSets(java.lang.String sql,
MockResultSet[] resultSets)
Prepare an array of ResultSet objects 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 that the specified SQL string should raise an exception. |
void |
prepareThrowsSQLException(java.lang.String sql,
java.sql.SQLException exc)
Prepare that 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 |
prepareUpdateCounts(java.lang.String sql,
int[] updateCounts)
Prepare an array update count values for executeUpdate calls
for a specified SQL string. |
void |
setCaseSensitive(boolean caseSensitive)
Set if specified SQL strings should be handled case sensitive. |
void |
setContinueProcessingOnBatchFailure(boolean continueProcessingOnBatchFailure)
Set if batch processing should be continued if one of the commands in the batch fails. |
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.
Creates a random id.
factory - the ResultSetFactory
ResultSet
public MockResultSet createResultSet(java.lang.String id,
ResultSetFactory factory)
ResultSet created by the specified factory.
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.
The current SQL string just has to contain the SQL string
for the prepared prepared ResultSet.
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.
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 setContinueProcessingOnBatchFailure(boolean continueProcessingOnBatchFailure)
false, i.e. if a command fails with an exception,
batch processing will not continue and the remaining commands
will not be executed.
continueProcessingOnBatchFailure - should batch processing be continuedpublic 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 void addReturnedResultSets(MockResultSet[] resultSets)
ResultSet[] objects that were returned by
a Statement, PreparedStatement or
CallableStatement. Called if a statement returns
multiple result sets.
resultSets - the ResultSet[]public java.util.List getExecutedStatements()
List of all executed SQL strings.
List of executed SQL stringspublic java.util.List getReturnedResultSets()
List of all returned ResultSet
or ResultSet[] objects. The List contains
arrays of result sets, if a query returned multiple result sets.
If a query returned multiple result sets, the list will always contain
the full array of ResultSet objects that were prepared, even
if MockStatement.getMoreResults() was
not called for all the result sets.
List of returned ResultSet or ResultSet[] objectspublic void clearResultSets()
ResultSet objects.
public void clearUpdateCounts()
public void clearReturnsResultSet()
ResultSet objects or update counts.
public void clearThrowsSQLException()
public void clearGeneratedKeys()
public void clearGlobalResultSet()
ResultSet.
public void clearGlobalGeneratedKeys()
ResultSet.
public void clearGlobalUpdateCount()
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 java.util.Map getGeneratedKeysMap()
Map of all generated keys ResultSet
objects, that were added with prepareGeneratedKeys(String, MockResultSet).
The SQL strings map to the corresponding generated keys ResultSet.
Map of generated keys ResultSet objectspublic MockResultSet getResultSet(java.lang.String sql)
ResultSet that matches the
specified SQL string. If the specified SQL string was
prepared to return multiple result sets, the first one will
be returned.
Please note that you can modify the match parameters with setCaseSensitive(boolean),
setExactMatch(boolean) and setUseRegularExpressions(boolean).
sql - the SQL string
MockResultSetpublic MockResultSet[] getResultSets(java.lang.String sql)
ResultSet[] that matches the
specified SQL string. If the specified SQL string was
prepared to return one single result set, this ResultSet
will be wrapped in an array with one element.
Please note that you can modify the match parameters with setCaseSensitive(boolean),
setExactMatch(boolean) and setUseRegularExpressions(boolean).
sql - the SQL string
MockResultSet[]public boolean hasMultipleResultSets(java.lang.String sql)
setCaseSensitive(boolean),
setExactMatch(boolean) and setUseRegularExpressions(boolean).
sql - the SQL string
true if the query returns multiple result sets,
false otherwisepublic MockResultSet getGlobalResultSet()
ResultSet.
If an array of global result sets was prepared, the first one will
be returned.
MockResultSetpublic MockResultSet[] getGlobalResultSets()
ResultSet[].
If one single ResultSet was prepared, this ResultSet
will be wrapped in an array with one element.
MockResultSet[]public boolean hasMultipleGlobalResultSets()
true if an array of global result sets was prepared,
false otherwisepublic java.lang.Integer getUpdateCount(java.lang.String sql)
setCaseSensitive(boolean),
setExactMatch(boolean) and setUseRegularExpressions(boolean).
sql - the SQL string
public java.lang.Integer[] getUpdateCounts(java.lang.String sql)
setCaseSensitive(boolean),
setExactMatch(boolean) and setUseRegularExpressions(boolean).
sql - the SQL string
public boolean hasMultipleUpdateCounts(java.lang.String sql)
setCaseSensitive(boolean),
setExactMatch(boolean) and setUseRegularExpressions(boolean).
sql - the SQL string
true if the SQL string returns multiple update counts,
false otherwisepublic int getGlobalUpdateCount()
executeUpdate calls.
If an array of global update counts was prepared, the first one will
be returned.
public int[] getGlobalUpdateCounts()
public boolean hasMultipleGlobalUpdateCounts()
true if an array of global update counts was prepared,
false otherwisepublic MockResultSet getGeneratedKeys(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 getGlobalGeneratedKeys()
ResultSet.
MockResultSetpublic 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 the string select (case insensitive).
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 otherwisepublic java.sql.SQLException getSQLException(java.lang.String sql)
SQLException the specified SQL string
should throw. Returns null if the specified SQL string
should not throw an exception.
This can be used to simulate database exceptions.
Please note that you can modify the match parameters with
setCaseSensitive(boolean), setExactMatch(boolean) and
setUseRegularExpressions(boolean).
sql - the SQL string
SQLException or null
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 MockResultSet
public void prepareResultSets(java.lang.String sql,
MockResultSet[] resultSets)
ResultSet objects for a specified SQL string.
This method can be used for queries that return multiple result sets.
Please note that you can modify the match parameters with
setCaseSensitive(boolean), setExactMatch(boolean) and
setUseRegularExpressions(boolean).
sql - the SQL stringresultSets - the corresponding MockResultSet[]public void prepareGlobalResultSet(MockResultSet resultSet)
ResultSet.
resultSet - the MockResultSetpublic void prepareGlobalResultSets(MockResultSet[] resultSets)
ResultSet objects.
resultSets - the corresponding 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 count
public void prepareUpdateCounts(java.lang.String sql,
int[] updateCounts)
executeUpdate calls
for a specified SQL string. This method can be used if multiple update counts
are returned.
Please note that you can modify the match parameters with setCaseSensitive(boolean),
setExactMatch(boolean) and setUseRegularExpressions(boolean).
sql - the SQL stringupdateCounts - the update count arraypublic void prepareGlobalUpdateCount(int updateCount)
executeUpdate calls.
updateCount - the update countpublic void prepareGlobalUpdateCounts(int[] updateCounts)
executeUpdate calls.
updateCounts - the update count array
public void prepareGeneratedKeys(java.lang.String sql,
MockResultSet generatedKeysResult)
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 stringgeneratedKeysResult - the generated keys MockResultSetpublic void prepareGlobalGeneratedKeys(MockResultSet generatedKeysResult)
ResultSet.
generatedKeysResult - the generated keys MockResultSet
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 the string select (case insensitive).
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)
SQLException and will throw this exception.
With prepareThrowsSQLException(String, SQLException) you
can specify the exception.
Please note that you can modify the match parameters with
setCaseSensitive(boolean), setExactMatch(boolean) and
setUseRegularExpressions(boolean).
sql - the SQL string
public void prepareThrowsSQLException(java.lang.String sql,
java.sql.SQLException exc)
setCaseSensitive(boolean), setExactMatch(boolean) and
setUseRegularExpressions(boolean).
sql - the SQL stringexc - the SQLException that should be thrownprotected boolean getCaseSensitive()
protected boolean getExactMatch()
protected boolean getUseRegularExpressions()
public boolean getContinueProcessingOnBatchFailure()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||