public class MockConnection extends JDBC41Connection implements Connection
Mock connections can be used to supply jOOQ with unit test data, avoiding the round-trip of using an actual in-memory test database, such as Derby, H2 or HSQLDB. A usage example:
MockDataProvider provider = new MockDataProvider() {
public MockResult[] execute(MockExecuteContext context) throws SQLException {
Result<MyTableRecord> result = executor.newResult(MY_TABLE);
result.add(executor.newRecord(MY_TABLE));
return new MockResult[] {
new MockResult(1, result)
};
}
};
Connection connection = new MockConnection(provider);
DSLContext create = DSL.using(connection, dialect);
assertEquals(1, create.selectOne().fetch().size());
While this MockConnection
can be used independently of jOOQ, it
has been optimised for usage with jOOQ. JDBC features that are not used by
jOOQ (e.g. procedure bind value access by parameter name) are not supported
in this mock framework
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
Constructor and Description |
---|
MockConnection(MockDataProvider data) |
abort, getNetworkTimeout, getSchema, setNetworkTimeout, setSchema
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
abort, getNetworkTimeout, getSchema, setNetworkTimeout, setSchema
public MockConnection(MockDataProvider data)
public Statement createStatement() throws SQLException
createStatement
in interface Connection
SQLException
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException
createStatement
in interface Connection
SQLException
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
createStatement
in interface Connection
SQLException
public PreparedStatement prepareStatement(String sql) throws SQLException
prepareStatement
in interface Connection
SQLException
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
prepareStatement
in interface Connection
SQLException
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
prepareStatement
in interface Connection
SQLException
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException
prepareStatement
in interface Connection
SQLException
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException
prepareStatement
in interface Connection
SQLException
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException
prepareStatement
in interface Connection
SQLException
public CallableStatement prepareCall(String sql) throws SQLException
prepareCall
in interface Connection
SQLException
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
prepareCall
in interface Connection
SQLException
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
prepareCall
in interface Connection
SQLException
public void commit() throws SQLException
commit
in interface Connection
SQLException
public void rollback() throws SQLException
rollback
in interface Connection
SQLException
public void rollback(Savepoint savepoint) throws SQLException
rollback
in interface Connection
SQLException
public void close() throws SQLException
close
in interface AutoCloseable
close
in interface Connection
SQLException
public Savepoint setSavepoint() throws SQLException
setSavepoint
in interface Connection
SQLException
public Savepoint setSavepoint(String name) throws SQLException
setSavepoint
in interface Connection
SQLException
public void releaseSavepoint(Savepoint savepoint) throws SQLException
releaseSavepoint
in interface Connection
SQLException
public boolean isClosed() throws SQLException
isClosed
in interface Connection
SQLException
public void setAutoCommit(boolean autoCommit) throws SQLException
setAutoCommit
in interface Connection
SQLException
public boolean getAutoCommit() throws SQLException
getAutoCommit
in interface Connection
SQLException
public void setReadOnly(boolean readOnly) throws SQLException
setReadOnly
in interface Connection
SQLException
public boolean isReadOnly() throws SQLException
isReadOnly
in interface Connection
SQLException
public void setCatalog(String catalog) throws SQLException
setCatalog
in interface Connection
SQLException
public String getCatalog() throws SQLException
getCatalog
in interface Connection
SQLException
public SQLWarning getWarnings() throws SQLException
getWarnings
in interface Connection
SQLException
public void clearWarnings() throws SQLException
clearWarnings
in interface Connection
SQLException
public void setTransactionIsolation(int level) throws SQLException
setTransactionIsolation
in interface Connection
SQLException
public int getTransactionIsolation() throws SQLException
getTransactionIsolation
in interface Connection
SQLException
public void setTypeMap(Map<String,Class<?>> map) throws SQLException
setTypeMap
in interface Connection
SQLException
public Map<String,Class<?>> getTypeMap() throws SQLException
getTypeMap
in interface Connection
SQLException
public void setHoldability(int holdability) throws SQLException
setHoldability
in interface Connection
SQLException
public int getHoldability() throws SQLException
getHoldability
in interface Connection
SQLException
public boolean isValid(int timeout) throws SQLException
isValid
in interface Connection
SQLException
public void setClientInfo(String name, String value) throws SQLClientInfoException
setClientInfo
in interface Connection
SQLClientInfoException
public void setClientInfo(Properties properties) throws SQLClientInfoException
setClientInfo
in interface Connection
SQLClientInfoException
public String getClientInfo(String name) throws SQLException
getClientInfo
in interface Connection
SQLException
public Properties getClientInfo() throws SQLException
getClientInfo
in interface Connection
SQLException
public DatabaseMetaData getMetaData() throws SQLException
getMetaData
in interface Connection
SQLException
public <T> T unwrap(Class<T> iface) throws SQLException
unwrap
in interface Wrapper
SQLException
public boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor
in interface Wrapper
SQLException
public String nativeSQL(String sql) throws SQLException
nativeSQL
in interface Connection
SQLException
public Clob createClob() throws SQLException
createClob
in interface Connection
SQLException
public Blob createBlob() throws SQLException
createBlob
in interface Connection
SQLException
public NClob createNClob() throws SQLException
createNClob
in interface Connection
SQLException
public SQLXML createSQLXML() throws SQLException
createSQLXML
in interface Connection
SQLException
public Array createArrayOf(String typeName, Object[] elements) throws SQLException
createArrayOf
in interface Connection
SQLException
public Struct createStruct(String typeName, Object[] attributes) throws SQLException
createStruct
in interface Connection
SQLException
Copyright © 2015. All Rights Reserved.