@FunctionalInterface public interface MockDataProvider
Supply this data provider to your
MockConnection in order to globally
provide data for SQL statements.
The general idea of mocking a JDBC connection with this jOOQ API is to
provide quick workarounds, injection points, etc. using a very
simple JDBC abstraction (see the
method). It is NOT RECOMMENDED to emulate an entire database
(including complex state transitions, transactions, locking, etc.) using this
mock API. Once you have this requirement, please consider using an actual
database instead for integration testing, rather than implementing your test
database inside of a
execute(MockExecuteContext) for more details.
|Modifier and Type||Method and Description|
Execution callback for a JDBC query execution.
MockResult execute(MockExecuteContext ctx) throws SQLException
This callback will be called by
MockStatement upon the various
statement execution methods. These include:
The various execution modes are unified into this simple method. Implementations should adhere to this contract:
MockStatementdoes not distinguish between "static" and "prepared" statements. However, a non-empty
MockExecuteContext.bindings()is a strong indicator for a
MockStatementdoes not distinguish between "batch" and "single" statements. However...
MockExecuteContext.batchSQL()with more than one SQL string is a strong indicator for a "multi-batch statement", as understood by jOOQ's
MockExecuteContext.batchBindings()with more than one bind variable array is a strong indicator for a "single-batch statement", as understood by jOOQ's
MockResultobjects as batch executions. In other words, you should guarantee that:
int multiSize = context.getBatchSQL().length;
int singleSize = context.getBatchBindings().length;
assertEquals(result.length, Math.max(multiSize, singleSize))
This holds true also for non-batch executions (where both sizes are equal
Statement.RETURN_GENERATED_KEYS) are requested from this execution, you can also add
MockResult.datato your result, in addition to the affected
MockResult.rows. The relevant flag is passed from
MockStatementto any of these properties:
Record. If OUT parameters are requested, implementors must ensure the presence of such a
ctx- The execution context.
SQLExceptionthat is passed through to jOOQ.
Copyright © 2016. All Rights Reserved.