Package com.mockobjects.sql
Class MockConnection2
- java.lang.Object
-
- com.mockobjects.MockObject
-
- com.mockobjects.sql.MockConnection2
-
- All Implemented Interfaces:
Verifiable,java.lang.AutoCloseable,java.sql.Connection,java.sql.Wrapper
public class MockConnection2 extends MockObject
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.
-
-
Constructor Summary
Constructors Constructor Description MockConnection2()MockConnection2(java.lang.String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddExpectedAutoCommit(boolean autoCommit)Register the anticipated value for autoCommit during testing.voidaddExpectedPreparedStatementString(java.lang.String sql)Deprecated.Add an SQL string to use with a prepared staement.voidclearWarnings()Calls 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.java.sql.StatementcreateStatement()Will throw either of the statement exceptions if one has been set, or otherwise return the Statement passed to setupStatement.java.sql.StatementcreateStatement(int resultSetType, int resultSetConcurrency)Calls notImplemented.java.sql.StatementcreateStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)booleangetAutoCommit()java.lang.StringgetCatalog()Calls notImplemented.intgetHoldability()java.sql.DatabaseMetaDatagetMetaData()Returns the DatabaseMetaData instance passed to setupMetaData.intgetTransactionIsolation()Calls notImplemented.java.util.MapgetTypeMap()Calls notImplemented.java.sql.SQLWarninggetWarnings()Calls notImplemented.booleanisClosed()Throw the isClosedException if it has been set, or otherwise return the value passed to setupIsClosed.booleanisReadOnly()Calls notImplemented.java.lang.StringnativeSQL(java.lang.String sql)Calls notImplemented.java.sql.CallableStatementprepareCall(java.lang.String sql)Calls notImplemented.java.sql.CallableStatementprepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency)Calls notImplemented.java.sql.CallableStatementprepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)java.sql.PreparedStatementprepareStatement(java.lang.String sql)Throws a statement exception if one has been registered (@see throwStatementExceptionIfAny) or returns the next PreparedStatement instance passed to setupAddPreparedStatement.java.sql.PreparedStatementprepareStatement(java.lang.String sql, int autoGeneratedKeys)java.sql.PreparedStatementprepareStatement(java.lang.String sql, int[] columnIndexes)java.sql.PreparedStatementprepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)Calls notImplemented.java.sql.PreparedStatementprepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)java.sql.PreparedStatementprepareStatement(java.lang.String sql, java.lang.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(java.lang.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(java.util.Map map)Calls notImplemented.voidsetupAddPreparedStatement(java.lang.String sql, java.sql.PreparedStatement prepared)Adds a PreparedStatement to be return by prepareStatementvoidsetupAddPreparedStatement(java.sql.PreparedStatement prepared)Deprecated.Adds a PreparedStatement to be return by prepareStatementvoidsetupAutoCommit(boolean autoCommitToReturn)voidsetupCloseException(java.sql.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(java.sql.SQLException aIsClosedException)Pass the SQL exception instance to throw if isClosed is called during a test.voidsetupMetaData(java.sql.DatabaseMetaData metaData)Pass the DataBaseMetaData instance for use with tests.voidsetupStatement(java.sql.Statement statement)Pass the Statement instance for use with tests.voidsetupThrowExceptionOnPrepareOrCreate(java.sql.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
-
-
-
-
Method Detail
-
setupAddPreparedStatement
public void setupAddPreparedStatement(java.lang.String sql, java.sql.PreparedStatement prepared)Adds a PreparedStatement to be return by prepareStatement
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql) throws java.sql.SQLExceptionThrows a statement exception if one has been registered (@see throwStatementExceptionIfAny) or returns the next PreparedStatement instance passed to setupAddPreparedStatement.- Specified by:
prepareStatementin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
addExpectedPreparedStatementString
public void addExpectedPreparedStatementString(java.lang.String sql)
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
public void setupAddPreparedStatement(java.sql.PreparedStatement prepared)
Deprecated.Adds a PreparedStatement to be return by prepareStatement- See Also:
CommonMockConnection2
-
setupCloseException
public void setupCloseException(java.sql.SQLException aCloseException)
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
public void setupIsClosedException(java.sql.SQLException aIsClosedException)
Pass the SQL exception instance to throw if isClosed is called during a test.
-
setupMetaData
public void setupMetaData(java.sql.DatabaseMetaData metaData)
Pass the DataBaseMetaData instance for use with tests.
-
setupStatement
public void setupStatement(java.sql.Statement statement)
Pass the Statement instance for use with tests.
-
setupThrowExceptionOnPrepareOrCreate
public void setupThrowExceptionOnPrepareOrCreate(java.sql.SQLException exception)
Pass the SQL exception to throw if preparedStatement or createStatement is called during a test.
-
setupAutoCommit
public void setupAutoCommit(boolean autoCommitToReturn)
-
close
public void close() throws java.sql.SQLExceptionWill throw the CloseException if it has been set, or otherwise increment the number or close calls.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
commit
public void commit() throws java.sql.SQLExceptionIncrements the number of commit calls.- Specified by:
commitin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
createStatement
public java.sql.Statement createStatement() throws java.sql.SQLExceptionWill throw either of the statement exceptions if one has been set, or otherwise return the Statement passed to setupStatement.- Specified by:
createStatementin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getMetaData
public java.sql.DatabaseMetaData getMetaData() throws java.sql.SQLExceptionReturns the DatabaseMetaData instance passed to setupMetaData.- Specified by:
getMetaDatain interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
isClosed
public boolean isClosed() throws java.sql.SQLExceptionThrow the isClosedException if it has been set, or otherwise return the value passed to setupIsClosed.- Specified by:
isClosedin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
rollback
public void rollback() throws java.sql.SQLExceptionIncrements the number of roll back calls.- Specified by:
rollbackin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setAutoCommit
public void setAutoCommit(boolean autoCommit) throws java.sql.SQLExceptionStores the value passed for comparison with the value passed to setupAutoCommit. The validate method will report any discrepency.- Specified by:
setAutoCommitin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
clearWarnings
public void clearWarnings() throws java.sql.SQLExceptionCalls notImplemented.- Specified by:
clearWarningsin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
createStatement
public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency) throws java.sql.SQLExceptionCalls notImplemented. Returns null.- Specified by:
createStatementin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getAutoCommit
public boolean getAutoCommit() throws java.sql.SQLException- Specified by:
getAutoCommitin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getCatalog
public java.lang.String getCatalog() throws java.sql.SQLExceptionCalls notImplemented. Returns null.- Specified by:
getCatalogin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getTransactionIsolation
public int getTransactionIsolation() throws java.sql.SQLExceptionCalls notImplemented. Returns 0.- Specified by:
getTransactionIsolationin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getTypeMap
public java.util.Map getTypeMap() throws java.sql.SQLExceptionCalls notImplemented. Returns null.- Specified by:
getTypeMapin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getWarnings
public java.sql.SQLWarning getWarnings() throws java.sql.SQLExceptionCalls notImplemented. Returns null.- Specified by:
getWarningsin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
isReadOnly
public boolean isReadOnly() throws java.sql.SQLExceptionCalls notImplemented. Returns false.- Specified by:
isReadOnlyin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
nativeSQL
public java.lang.String nativeSQL(java.lang.String sql) throws java.sql.SQLExceptionCalls notImplemented. Returns null.- Specified by:
nativeSQLin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
prepareCall
public java.sql.CallableStatement prepareCall(java.lang.String sql) throws java.sql.SQLExceptionCalls notImplemented. Returns null.- Specified by:
prepareCallin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
prepareCall
public java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws java.sql.SQLExceptionCalls notImplemented. Returns null.- Specified by:
prepareCallin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws java.sql.SQLExceptionCalls notImplemented. Returns null.- Specified by:
prepareStatementin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setCatalog
public void setCatalog(java.lang.String catalog) throws java.sql.SQLExceptionCalls notImplemented.- Specified by:
setCatalogin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setReadOnly
public void setReadOnly(boolean readOnly) throws java.sql.SQLExceptionCalls notImplemented.- Specified by:
setReadOnlyin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setTransactionIsolation
public void setTransactionIsolation(int level) throws java.sql.SQLExceptionCalls notImplemented.- Specified by:
setTransactionIsolationin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setTypeMap
public void setTypeMap(java.util.Map map) throws java.sql.SQLExceptionCalls notImplemented.- Specified by:
setTypeMapin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setHoldability
public void setHoldability(int holdability) throws java.sql.SQLException- Specified by:
setHoldabilityin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getHoldability
public int getHoldability() throws java.sql.SQLException- Specified by:
getHoldabilityin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
createStatement
public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException- Specified by:
createStatementin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException- Specified by:
prepareStatementin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
prepareCall
public java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException- Specified by:
prepareCallin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException- Specified by:
prepareStatementin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException- Specified by:
prepareStatementin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException- Specified by:
prepareStatementin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
-