public abstract class AbstractResultSetHandler extends Object
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 and Description |
|---|
AbstractResultSetHandler() |
| Modifier and Type | Method and Description |
|---|---|
void |
addExecutedStatement(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(String id)
Creates a new
ResultSet with the specified id. |
MockResultSet |
createResultSet(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.
|
List |
getExecutedStatements()
Returns the
List of all executed SQL strings. |
MockResultSet |
getGeneratedKeys(String sql)
Returns the first generated keys
ResultSet that
matches the specified SQL string. |
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(String sql)
Returns the first
ResultSet that matches the
specified SQL string. |
Map |
getResultSetMap()
Returns the
Map of all ResultSet
objects, that were added with prepareResultSet(String, MockResultSet). |
MockResultSet[] |
getResultSets(String sql)
Returns the first
ResultSet[] that matches the
specified SQL string. |
List |
getReturnedResultSets()
Returns the
List of all returned ResultSet
or ResultSet[] objects. |
Boolean |
getReturnsResultSet(String sql)
Returns if the specified SQL string is a select that returns
a
ResultSet. |
SQLException |
getSQLException(String sql)
Returns the
SQLException the specified SQL string
should throw. |
boolean |
getThrowsSQLException(String sql)
Returns if the specified SQL string should raise an exception.
|
Integer |
getUpdateCount(String sql)
Returns the first update count that matches the
specified SQL string.
|
Map |
getUpdateCountMap()
Returns the
Map of all update counts, that were added
with prepareUpdateCount(String, int). |
Integer[] |
getUpdateCounts(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.
|
boolean |
hasMultipleGlobalUpdateCounts()
Returns if multiple global update counts have been prepared, i.e.
|
boolean |
hasMultipleResultSets(String sql)
Returns the if the specified SQL string returns multiple result sets.
|
boolean |
hasMultipleUpdateCounts(String sql)
Returns the if the specified SQL string returns multiple update counts.
|
void |
prepareGeneratedKeys(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(String sql,
MockResultSet resultSet)
Prepare a
ResultSet for a specified SQL string. |
void |
prepareResultSets(String sql,
MockResultSet[] resultSets)
Prepare an array of
ResultSet objects for a specified SQL string. |
void |
prepareReturnsResultSet(String sql,
boolean returnsResultSet)
Prepare if the specified SQL string is a select that returns
a
ResultSet. |
void |
prepareThrowsSQLException(String sql)
Prepare that the specified SQL string should raise an exception.
|
void |
prepareThrowsSQLException(String sql,
SQLException exc)
Prepare that the specified SQL string should raise an exception.
|
void |
prepareUpdateCount(String sql,
int updateCount)
Prepare the update count for
executeUpdate calls
for a specified SQL string. |
void |
prepareUpdateCounts(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.
|
public MockResultSet createResultSet()
ResultSet with a
random id.ResultSetpublic MockResultSet createResultSet(String id)
ResultSet with the specified id.id - the idResultSetpublic MockResultSet createResultSet(ResultSetFactory factory)
ResultSet created by the specified factory.
Creates a random id.factory - the ResultSetFactoryResultSetpublic MockResultSet createResultSet(String id, ResultSetFactory factory)
ResultSet created by the specified factory.id - the idfactory - the ResultSetFactoryResultSetpublic 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(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 List getExecutedStatements()
List of all executed SQL strings.List of executed SQL stringspublic 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 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 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 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(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 stringMockResultSetpublic MockResultSet[] getResultSets(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 stringMockResultSet[]public boolean hasMultipleResultSets(String sql)
setCaseSensitive(boolean),
setExactMatch(boolean) and setUseRegularExpressions(boolean).sql - the SQL stringtrue 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 Integer getUpdateCount(String sql)
setCaseSensitive(boolean),
setExactMatch(boolean) and setUseRegularExpressions(boolean).sql - the SQL stringpublic Integer[] getUpdateCounts(String sql)
setCaseSensitive(boolean),
setExactMatch(boolean) and setUseRegularExpressions(boolean).sql - the SQL stringpublic boolean hasMultipleUpdateCounts(String sql)
setCaseSensitive(boolean),
setExactMatch(boolean) and setUseRegularExpressions(boolean).sql - the SQL stringtrue 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(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 stringMockResultSetpublic MockResultSet getGlobalGeneratedKeys()
ResultSet.MockResultSetpublic Boolean getReturnsResultSet(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 stringtrue if the SQL string returns a ResultSetpublic boolean getThrowsSQLException(String sql)
setCaseSensitive(boolean), setExactMatch(boolean) and
setUseRegularExpressions(boolean).sql - the SQL stringtrue if the specified SQL string should raise an exception,
false otherwisepublic SQLException getSQLException(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 stringSQLException or nullpublic void prepareResultSet(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 prepareResultSets(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(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 prepareUpdateCounts(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 arraypublic void prepareGeneratedKeys(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 MockResultSetpublic void prepareReturnsResultSet(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(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 stringpublic void prepareThrowsSQLException(String 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()
Copyright © 2003-2014. All Rights Reserved.