Package com.mockobjects.sql
Class MockConnection2
java.lang.Object
com.mockobjects.MockObject
com.mockobjects.sql.MockConnection2
- All Implemented Interfaces:
Verifiable,AutoCloseable,Connection,Wrapper
MockConnection2 is a tempary replacement for the MockConnection.
It differs from the MockConnection in the way in which preparedstatements
are handled. The changes are significant enough to break compatiblity with
exsising testcases so MockConnection2 provides a migration path to the new
system of handling preparedstatements.
This calls will eventually be merged back into MockConnection when it is felt
systems using the classes have been provided with enough time to migrate.
-
Field Summary
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExpectedAutoCommit(boolean autoCommit) Register the anticipated value for autoCommit during testing.voidDeprecated.Add an SQL string to use with a prepared staement.voidCalls notImplemented.voidclose()Will throw the CloseException if it has been set, or otherwise increment the number or close calls.voidcommit()Increments the number of commit calls.Will throw either of the statement exceptions if one has been set, or otherwise return the Statement passed to setupStatement.createStatement(int resultSetType, int resultSetConcurrency) Calls notImplemented.createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) booleanCalls notImplemented.intReturns the DatabaseMetaData instance passed to setupMetaData.intCalls notImplemented.Calls notImplemented.Calls notImplemented.booleanisClosed()Throw the isClosedException if it has been set, or otherwise return the value passed to setupIsClosed.booleanCalls notImplemented.Calls notImplemented.prepareCall(String sql) Calls notImplemented.prepareCall(String sql, int resultSetType, int resultSetConcurrency) Calls notImplemented.prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) prepareStatement(String sql) Throws a statement exception if one has been registered (@see throwStatementExceptionIfAny) or returns the next PreparedStatement instance passed to setupAddPreparedStatement.prepareStatement(String sql, int autoGeneratedKeys) prepareStatement(String sql, int[] columnIndexes) prepareStatement(String sql, int resultSetType, int resultSetConcurrency) Calls notImplemented.prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) prepareStatement(String sql, String[] columnNames) voidrollback()Increments the number of roll back calls.voidsetAutoCommit(boolean autoCommit) Stores the value passed for comparison with the value passed to setupAutoCommit.voidsetCatalog(String catalog) Calls notImplemented.voidsetExpectedCloseCalls(int callCount) Register the number of close calls the test should make.voidsetExpectedCommitCalls(int callCount) Register the number of commit calls the test should make.voidsetExpectedCreateStatementCalls(int calls) Register the number of create statement calls the test should make.voidsetExpectedResultSetConcurrency(int resultSetConcurrency) Sets expectations about the possible value of theresultSetConcurrencyparameter ofcreateStatement()calls.voidsetExpectedResultSetType(int resultSetType) Sets expectations about the possible value of theresultSetTypeparameter ofcreateStatement()calls.voidsetExpectedRollbackCalls(int callCount) Register the number of roll back calls the test should make.voidsetHoldability(int holdability) voidsetReadOnly(boolean readOnly) Calls notImplemented.voidsetTransactionIsolation(int level) Calls notImplemented.voidsetTypeMap(Map map) Calls notImplemented.voidsetupAddPreparedStatement(String sql, PreparedStatement prepared) Adds a PreparedStatement to be return by prepareStatementvoidsetupAddPreparedStatement(PreparedStatement prepared) Deprecated.Adds a PreparedStatement to be return by prepareStatementvoidsetupAutoCommit(boolean autoCommitToReturn) voidsetupCloseException(SQLException aCloseException) Pass the SQL exception to throw if close is called during a test.voidsetupIsClose(boolean aIsClosed) Deprecated.Use setupIsClosedvoidsetupIsClosed(boolean aIsClosed) Pass the value to return if isClosed is called during a test.voidsetupIsClosedException(SQLException aIsClosedException) Pass the SQL exception instance to throw if isClosed is called during a test.voidsetupMetaData(DatabaseMetaData metaData) Pass the DataBaseMetaData instance for use with tests.voidsetupStatement(Statement statement) Pass the Statement instance for use with tests.voidsetupThrowExceptionOnPrepareOrCreate(SQLException exception) Pass the SQL exception to throw if preparedStatement or createStatement is called during a test.Methods inherited from class com.mockobjects.MockObject
notImplemented, notYetImplemented, verifyMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.sql.Connection
abort, beginRequest, clearWarnings, close, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, endRequest, getAutoCommit, getCatalog, getClientInfo, getClientInfo, getHoldability, getMetaData, getNetworkTimeout, getSchema, getTransactionIsolation, getTypeMap, getWarnings, isClosed, isReadOnly, isValid, nativeSQL, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, rollback, setAutoCommit, setCatalog, setClientInfo, setClientInfo, setHoldability, setNetworkTimeout, setReadOnly, setSavepoint, setSavepoint, setSchema, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid, setTransactionIsolation, setTypeMapMethods inherited from interface java.sql.Wrapper
isWrapperFor, unwrap
-
Constructor Details
-
MockConnection2
public MockConnection2() -
MockConnection2
-
-
Method Details
-
setupAddPreparedStatement
Adds a PreparedStatement to be return by prepareStatement -
prepareStatement
Throws a statement exception if one has been registered (@see throwStatementExceptionIfAny) or returns the next PreparedStatement instance passed to setupAddPreparedStatement.- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
addExpectedPreparedStatementString
Deprecated.Add an SQL string to use with a prepared staement. -
addExpectedAutoCommit
public void addExpectedAutoCommit(boolean autoCommit) Register the anticipated value for autoCommit during testing. -
setExpectedCloseCalls
public void setExpectedCloseCalls(int callCount) Register the number of close calls the test should make. The valid method will report any discrepancy with the actual count. -
setExpectedCommitCalls
public void setExpectedCommitCalls(int callCount) Register the number of commit calls the test should make. The valid method will report any discrepancy with the actual count. -
setExpectedCreateStatementCalls
public void setExpectedCreateStatementCalls(int calls) Register the number of create statement calls the test should make. The valid method will report any discrepancy with the actual count. -
setExpectedRollbackCalls
public void setExpectedRollbackCalls(int callCount) Register the number of roll back calls the test should make. The valid method will report any discrepancy with the actual count. -
setExpectedResultSetConcurrency
public void setExpectedResultSetConcurrency(int resultSetConcurrency) Sets expectations about the possible value of theresultSetConcurrencyparameter ofcreateStatement()calls.- Parameters:
resultSetConcurrency- One of the constants starting with CONCUR inResultSet.
-
setExpectedResultSetType
public void setExpectedResultSetType(int resultSetType) Sets expectations about the possible value of theresultSetTypeparameter ofcreateStatement()calls.- Parameters:
resultSetType- One of the constants starting with TYPE inResultSet.
-
setupAddPreparedStatement
Deprecated.Adds a PreparedStatement to be return by prepareStatement- See Also:
-
setupCloseException
Pass the SQL exception to throw if close is called during a test. -
setupIsClose
public void setupIsClose(boolean aIsClosed) Deprecated.Use setupIsClosed -
setupIsClosed
public void setupIsClosed(boolean aIsClosed) Pass the value to return if isClosed is called during a test. This is returned unless an isClosedException has been set. -
setupIsClosedException
Pass the SQL exception instance to throw if isClosed is called during a test. -
setupMetaData
Pass the DataBaseMetaData instance for use with tests. -
setupStatement
Pass the Statement instance for use with tests. -
setupThrowExceptionOnPrepareOrCreate
Pass the SQL exception to throw if preparedStatement or createStatement is called during a test. -
setupAutoCommit
public void setupAutoCommit(boolean autoCommitToReturn) -
close
Will throw the CloseException if it has been set, or otherwise increment the number or close calls.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection- Throws:
SQLException
-
commit
Increments the number of commit calls.- Specified by:
commitin interfaceConnection- Throws:
SQLException
-
createStatement
Will throw either of the statement exceptions if one has been set, or otherwise return the Statement passed to setupStatement.- Specified by:
createStatementin interfaceConnection- Throws:
SQLException
-
getMetaData
Returns the DatabaseMetaData instance passed to setupMetaData.- Specified by:
getMetaDatain interfaceConnection- Throws:
SQLException
-
isClosed
Throw the isClosedException if it has been set, or otherwise return the value passed to setupIsClosed.- Specified by:
isClosedin interfaceConnection- Throws:
SQLException
-
rollback
Increments the number of roll back calls.- Specified by:
rollbackin interfaceConnection- Throws:
SQLException
-
setAutoCommit
Stores the value passed for comparison with the value passed to setupAutoCommit. The validate method will report any discrepency.- Specified by:
setAutoCommitin interfaceConnection- Throws:
SQLException
-
clearWarnings
Calls notImplemented.- Specified by:
clearWarningsin interfaceConnection- Throws:
SQLException
-
createStatement
Calls notImplemented. Returns null.- Specified by:
createStatementin interfaceConnection- Throws:
SQLException
-
getAutoCommit
- Specified by:
getAutoCommitin interfaceConnection- Throws:
SQLException
-
getCatalog
Calls notImplemented. Returns null.- Specified by:
getCatalogin interfaceConnection- Throws:
SQLException
-
getTransactionIsolation
Calls notImplemented. Returns 0.- Specified by:
getTransactionIsolationin interfaceConnection- Throws:
SQLException
-
getTypeMap
Calls notImplemented. Returns null.- Specified by:
getTypeMapin interfaceConnection- Throws:
SQLException
-
getWarnings
Calls notImplemented. Returns null.- Specified by:
getWarningsin interfaceConnection- Throws:
SQLException
-
isReadOnly
Calls notImplemented. Returns false.- Specified by:
isReadOnlyin interfaceConnection- Throws:
SQLException
-
nativeSQL
Calls notImplemented. Returns null.- Specified by:
nativeSQLin interfaceConnection- Throws:
SQLException
-
prepareCall
Calls notImplemented. Returns null.- Specified by:
prepareCallin interfaceConnection- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException Calls notImplemented. Returns null.- Specified by:
prepareCallin interfaceConnection- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException Calls notImplemented. Returns null.- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
setCatalog
Calls notImplemented.- Specified by:
setCatalogin interfaceConnection- Throws:
SQLException
-
setReadOnly
Calls notImplemented.- Specified by:
setReadOnlyin interfaceConnection- Throws:
SQLException
-
setTransactionIsolation
Calls notImplemented.- Specified by:
setTransactionIsolationin interfaceConnection- Throws:
SQLException
-
setTypeMap
Calls notImplemented.- Specified by:
setTypeMapin interfaceConnection- Throws:
SQLException
-
setHoldability
- Specified by:
setHoldabilityin interfaceConnection- Throws:
SQLException
-
getHoldability
- Specified by:
getHoldabilityin interfaceConnection- Throws:
SQLException
-
createStatement
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
createStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareCallin interfaceConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-