Package com.mockobjects.sql

# Class MockConnection2

java.lang.Object
com.mockobjects.MockObject
com.mockobjects.sql.MockConnection2

All Implemented Interfaces:
  `Verifiable`, `AutoCloseable`, `Connection`, `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.

## 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
Constructor
Description
`MockConnection2()`
`MockConnection2(String name)`

## Method Summary

Modifier and Type
Method
Description
`void`
`addExpectedAutoCommit(boolean autoCommit)`
Register the anticipated value for autoCommit during testing.
`void`
`addExpectedPreparedStatementString(String sql)`
Deprecated.
Add an SQL string to use with a prepared staement.
`void`
`clearWarnings()`
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.
`Statement`
`createStatement()`
Will throw either of the statement exceptions if one has been set, or otherwise return the Statement passed to setupStatement.
`Statement`
`createStatement(int resultSetType, int resultSetConcurrency)`
Calls notImplemented.
`Statement`
`createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)`
`boolean`
`getAutoCommit()`
`String`
`getCatalog()`
Calls notImplemented.
`int`
`getHoldability()`
`DatabaseMetaData`
`getMetaData()`
Returns the DatabaseMetaData instance passed to setupMetaData.
`int`
`getTransactionIsolation()`
Calls notImplemented.
`Map`
`getTypeMap()`
Calls notImplemented.
`SQLWarning`
`getWarnings()`
Calls notImplemented.
`boolean`
`isClosed()`
Throw the isClosedException if it has been set, or otherwise return the value passed to setupIsClosed.
`boolean`
`isReadOnly()`
Calls notImplemented.
`String`
`nativeSQL(String sql)`
Calls notImplemented.
`CallableStatement`
`prepareCall(String sql)`
Calls notImplemented.
`CallableStatement`
`prepareCall(String sql, int resultSetType, int resultSetConcurrency)`
Calls notImplemented.
`CallableStatement`
`prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)`
`PreparedStatement`
`prepareStatement(String sql)`
Throws a statement exception if one has been registered (@see throwStatementExceptionIfAny) or returns the next PreparedStatement instance passed to setupAddPreparedStatement.
`PreparedStatement`
`prepareStatement(String sql, int autoGeneratedKeys)`
`PreparedStatement`
`prepareStatement(String sql, int[] columnIndexes)`
`PreparedStatement`
`prepareStatement(String sql, int resultSetType, int resultSetConcurrency)`
Calls notImplemented.
`PreparedStatement`
`prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)`
`PreparedStatement`
`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 the `resultSetConcurrency` parameter of `createStatement()` calls.
`void`
`setExpectedResultSetType(int resultSetType)`
Sets expectations about the possible value of the `resultSetType` parameter of `createStatement()` 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 prepareStatement
`void`
`setupAddPreparedStatement(PreparedStatement prepared)`
Deprecated.
Adds a PreparedStatement to be return by prepareStatement
`void`
`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 setupIsClosed
`void`
`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

public MockConnection2(String name)

## Method Details

### setupAddPreparedStatement

public void setupAddPreparedStatement(String sql, PreparedStatement prepared)
Adds a PreparedStatement to be return by prepareStatement

### prepareStatement

public PreparedStatement prepareStatement(String sql) throws SQLException
Throws a statement exception if one has been registered (@see throwStatementExceptionIfAny) or returns the next PreparedStatement instance passed to setupAddPreparedStatement.

Specified by:
  `prepareStatement` in interface `Connection`
Throws:
  `SQLException`

### addExpectedPreparedStatementString

public void addExpectedPreparedStatementString(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 the `resultSetConcurrency` parameter of `createStatement()` calls.

Parameters:
  `resultSetConcurrency` - One of the constants starting with CONCUR in `ResultSet`.

### setExpectedResultSetType

public void setExpectedResultSetType(int resultSetType)
Sets expectations about the possible value of the `resultSetType` parameter of `createStatement()` calls.

Parameters:
  `resultSetType` - One of the constants starting with TYPE in `ResultSet`.

### setupAddPreparedStatement

public void setupAddPreparedStatement(PreparedStatement prepared)
Deprecated.
Adds a PreparedStatement to be return by prepareStatement

See Also:
  - `CommonMockConnection2`

### setupCloseException

public void setupCloseException(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(SQLException aIsClosedException)
Pass the SQL exception instance to throw if isClosed is called during a test.

### setupMetaData

public void setupMetaData(DatabaseMetaData metaData)
Pass the DataBaseMetaData instance for use with tests.

### setupStatement

public void setupStatement(Statement statement)
Pass the Statement instance for use with tests.

### setupThrowExceptionOnPrepareOrCreate

public void setupThrowExceptionOnPrepareOrCreate(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 SQLException
Will throw the CloseException if it has been set, or otherwise increment the number or close calls.

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Connection`
Throws:
  `SQLException`

### commit

public void commit() throws SQLException
Increments the number of commit calls.

Specified by:
  `commit` in interface `Connection`
Throws:
  `SQLException`

### createStatement

public Statement createStatement() throws SQLException
Will throw either of the statement exceptions if one has been set, or otherwise return the Statement passed to setupStatement.

Specified by:
  `createStatement` in interface `Connection`
Throws:
  `SQLException`

### getMetaData

public DatabaseMetaData getMetaData() throws SQLException
Returns the DatabaseMetaData instance passed to setupMetaData.

Specified by:
  `getMetaData` in interface `Connection`
Throws:
  `SQLException`

### isClosed

public boolean isClosed() throws SQLException
Throw the isClosedException if it has been set, or otherwise return the value passed to setupIsClosed.

Specified by:
  `isClosed` in interface `Connection`
Throws:
  `SQLException`

### rollback

public void rollback() throws SQLException
Increments the number of roll back calls.

Specified by:
  `rollback` in interface `Connection`
Throws:
  `SQLException`

### setAutoCommit

public void setAutoCommit(boolean autoCommit) throws SQLException
Stores the value passed for comparison with the value passed to setupAutoCommit. The validate method will report any discrepency.

Specified by:
  `setAutoCommit` in interface `Connection`
Throws:
  `SQLException`

### clearWarnings

public void clearWarnings() throws SQLException
Calls notImplemented.

Specified by:
  `clearWarnings` in interface `Connection`
Throws:
  `SQLException`

### createStatement

public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException
Calls notImplemented. Returns null.

Specified by:
  `createStatement` in interface `Connection`
Throws:
  `SQLException`

### getAutoCommit

public boolean getAutoCommit() throws SQLException

Specified by:
  `getAutoCommit` in interface `Connection`
Throws:
  `SQLException`

### getCatalog

public String getCatalog() throws SQLException
Calls notImplemented. Returns null.

Specified by:
  `getCatalog` in interface `Connection`
Throws:
  `SQLException`

### getTransactionIsolation

public int getTransactionIsolation() throws SQLException
Calls notImplemented. Returns 0.

Specified by:
  `getTransactionIsolation` in interface `Connection`
Throws:
  `SQLException`

### getTypeMap

public Map getTypeMap() throws SQLException
Calls notImplemented. Returns null.

Specified by:
  `getTypeMap` in interface `Connection`
Throws:
  `SQLException`

### getWarnings

public SQLWarning getWarnings() throws SQLException
Calls notImplemented. Returns null.

Specified by:
  `getWarnings` in interface `Connection`
Throws:
  `SQLException`

### isReadOnly

public boolean isReadOnly() throws SQLException
Calls notImplemented. Returns false.

Specified by:
  `isReadOnly` in interface `Connection`
Throws:
  `SQLException`

### nativeSQL

public String nativeSQL(String sql) throws SQLException
Calls notImplemented. Returns null.

Specified by:
  `nativeSQL` in interface `Connection`
Throws:
  `SQLException`

### prepareCall

public CallableStatement prepareCall(String sql) throws SQLException
Calls notImplemented. Returns null.

Specified by:
  `prepareCall` in interface `Connection`
Throws:
  `SQLException`

### prepareCall

public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
Calls notImplemented. Returns null.

Specified by:
  `prepareCall` in interface `Connection`
Throws:
  `SQLException`

### prepareStatement

public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
Calls notImplemented. Returns null.

Specified by:
  `prepareStatement` in interface `Connection`
Throws:
  `SQLException`

### setCatalog

public void setCatalog(String catalog) throws SQLException
Calls notImplemented.

Specified by:
  `setCatalog` in interface `Connection`
Throws:
  `SQLException`

### setReadOnly

public void setReadOnly(boolean readOnly) throws SQLException
Calls notImplemented.

Specified by:
  `setReadOnly` in interface `Connection`
Throws:
  `SQLException`

### setTransactionIsolation

public void setTransactionIsolation(int level) throws SQLException
Calls notImplemented.

Specified by:
  `setTransactionIsolation` in interface `Connection`
Throws:
  `SQLException`

### setTypeMap

public void setTypeMap(Map map) throws SQLException
Calls notImplemented.

Specified by:
  `setTypeMap` in interface `Connection`
Throws:
  `SQLException`

### setHoldability

public void setHoldability(int holdability) throws SQLException

Specified by:
  `setHoldability` in interface `Connection`
Throws:
  `SQLException`

### getHoldability

public int getHoldability() throws SQLException

Specified by:
  `getHoldability` in interface `Connection`
Throws:
  `SQLException`

### createStatement

public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException

Specified by:
  `createStatement` in interface `Connection`
Throws:
  `SQLException`

### prepareStatement

public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException

Specified by:
  `prepareStatement` in interface `Connection`
Throws:
  `SQLException`

### prepareCall

public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException

Specified by:
  `prepareCall` in interface `Connection`
Throws:
  `SQLException`

### prepareStatement

public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException

Specified by:
  `prepareStatement` in interface `Connection`
Throws:
  `SQLException`

### prepareStatement

public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException

Specified by:
  `prepareStatement` in interface `Connection`
Throws:
  `SQLException`

### prepareStatement

public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException

Specified by:
  `prepareStatement` in interface `Connection`
Throws:
  `SQLException`