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 TypeMethodDescriptionvoid
addExpectedAutoCommit
(boolean autoCommit) Register the anticipated value for autoCommit during testing.void
Deprecated.Add an SQL string to use with a prepared staement.void
Calls notImplemented.void
close()
Will throw the CloseException if it has been set, or otherwise increment the number or close calls.void
commit()
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) boolean
Calls notImplemented.int
Returns the DatabaseMetaData instance passed to setupMetaData.int
Calls notImplemented.Calls notImplemented.Calls notImplemented.boolean
isClosed()
Throw the isClosedException if it has been set, or otherwise return the value passed to setupIsClosed.boolean
Calls 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) void
rollback()
Increments the number of roll back calls.void
setAutoCommit
(boolean autoCommit) Stores the value passed for comparison with the value passed to setupAutoCommit.void
setCatalog
(String catalog) Calls notImplemented.void
setExpectedCloseCalls
(int callCount) Register the number of close calls the test should make.void
setExpectedCommitCalls
(int callCount) Register the number of commit calls the test should make.void
setExpectedCreateStatementCalls
(int calls) Register the number of create statement calls the test should make.void
setExpectedResultSetConcurrency
(int resultSetConcurrency) Sets expectations about the possible value of theresultSetConcurrency
parameter ofcreateStatement()
calls.void
setExpectedResultSetType
(int resultSetType) Sets expectations about the possible value of theresultSetType
parameter ofcreateStatement()
calls.void
setExpectedRollbackCalls
(int callCount) Register the number of roll back calls the test should make.void
setHoldability
(int holdability) void
setReadOnly
(boolean readOnly) Calls notImplemented.void
setTransactionIsolation
(int level) Calls notImplemented.void
setTypeMap
(Map map) Calls notImplemented.void
setupAddPreparedStatement
(String sql, PreparedStatement prepared) Adds a PreparedStatement to be return by prepareStatementvoid
setupAddPreparedStatement
(PreparedStatement prepared) Deprecated.Adds a PreparedStatement to be return by prepareStatementvoid
setupAutoCommit
(boolean autoCommitToReturn) void
setupCloseException
(SQLException aCloseException) Pass the SQL exception to throw if close is called during a test.void
setupIsClose
(boolean aIsClosed) Deprecated.Use setupIsClosedvoid
setupIsClosed
(boolean aIsClosed) Pass the value to return if isClosed is called during a test.void
setupIsClosedException
(SQLException aIsClosedException) Pass the SQL exception instance to throw if isClosed is called during a test.void
setupMetaData
(DatabaseMetaData metaData) Pass the DataBaseMetaData instance for use with tests.void
setupStatement
(Statement statement) Pass the Statement instance for use with tests.void
setupThrowExceptionOnPrepareOrCreate
(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, verify
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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, setTypeMap
Methods 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:
prepareStatement
in 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 theresultSetConcurrency
parameter 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 theresultSetType
parameter ofcreateStatement()
calls.- Parameters:
resultSetType
- One of the constants starting with TYPE inResultSet
.
-
setupAddPreparedStatement
Deprecated.Adds a PreparedStatement to be return by prepareStatement- See Also:
-
CommonMockConnection2
-
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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceConnection
- Throws:
SQLException
-
commit
Increments the number of commit calls.- Specified by:
commit
in 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:
createStatement
in interfaceConnection
- Throws:
SQLException
-
getMetaData
Returns the DatabaseMetaData instance passed to setupMetaData.- Specified by:
getMetaData
in interfaceConnection
- Throws:
SQLException
-
isClosed
Throw the isClosedException if it has been set, or otherwise return the value passed to setupIsClosed.- Specified by:
isClosed
in interfaceConnection
- Throws:
SQLException
-
rollback
Increments the number of roll back calls.- Specified by:
rollback
in 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:
setAutoCommit
in interfaceConnection
- Throws:
SQLException
-
clearWarnings
Calls notImplemented.- Specified by:
clearWarnings
in interfaceConnection
- Throws:
SQLException
-
createStatement
Calls notImplemented. Returns null.- Specified by:
createStatement
in interfaceConnection
- Throws:
SQLException
-
getAutoCommit
- Specified by:
getAutoCommit
in interfaceConnection
- Throws:
SQLException
-
getCatalog
Calls notImplemented. Returns null.- Specified by:
getCatalog
in interfaceConnection
- Throws:
SQLException
-
getTransactionIsolation
Calls notImplemented. Returns 0.- Specified by:
getTransactionIsolation
in interfaceConnection
- Throws:
SQLException
-
getTypeMap
Calls notImplemented. Returns null.- Specified by:
getTypeMap
in interfaceConnection
- Throws:
SQLException
-
getWarnings
Calls notImplemented. Returns null.- Specified by:
getWarnings
in interfaceConnection
- Throws:
SQLException
-
isReadOnly
Calls notImplemented. Returns false.- Specified by:
isReadOnly
in interfaceConnection
- Throws:
SQLException
-
nativeSQL
Calls notImplemented. Returns null.- Specified by:
nativeSQL
in interfaceConnection
- Throws:
SQLException
-
prepareCall
Calls notImplemented. Returns null.- Specified by:
prepareCall
in interfaceConnection
- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException Calls notImplemented. Returns null.- Specified by:
prepareCall
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException Calls notImplemented. Returns null.- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
setCatalog
Calls notImplemented.- Specified by:
setCatalog
in interfaceConnection
- Throws:
SQLException
-
setReadOnly
Calls notImplemented.- Specified by:
setReadOnly
in interfaceConnection
- Throws:
SQLException
-
setTransactionIsolation
Calls notImplemented.- Specified by:
setTransactionIsolation
in interfaceConnection
- Throws:
SQLException
-
setTypeMap
Calls notImplemented.- Specified by:
setTypeMap
in interfaceConnection
- Throws:
SQLException
-
setHoldability
- Specified by:
setHoldability
in interfaceConnection
- Throws:
SQLException
-
getHoldability
- Specified by:
getHoldability
in interfaceConnection
- Throws:
SQLException
-
createStatement
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
createStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareCall
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-