Top Description Inners Fields Constructors Methods
org.jooq.tools.jdbc

public Class MockConnectionProvider

extends Object
implements ConnectionProvider
Class Inheritance
All Implemented Interfaces
org.jooq.ConnectionProvider
Imports
java.sql.Connection, org.jooq.ConnectionProvider

A mock connection provider.

This ConnectionProvider wraps a delegate ConnectionProvider and wraps all acquired Connection references in MockConnection.

Disclaimer

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. 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 (e.g. using https://www.testcontainers.org), rather than implementing your test database inside of a MockDataProvider.

Author
Lukas Eder

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
MockConnectionProvider.MockConnectionWrapper

Deprecated as a consequence of MockConnection being deprecated.

Field Summary

Modifier and TypeField and Description
private final ConnectionProvider
private final MockDataProvider

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final Connection
acquire()

Implements org.jooq.ConnectionProvider.acquire.

Acquire a connection from the connection lifecycle handler.
public final void
release(Connection
A connection that was previously obtained from acquire(). This is never null.
connection
)

Implements org.jooq.ConnectionProvider.release.

Release a connection to the connection lifecycle handler.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

delegateback to summary
private final ConnectionProvider delegate
providerback to summary
private final MockDataProvider provider

Constructor Detail

MockConnectionProviderback to summary
public MockConnectionProvider(ConnectionProvider delegate, MockDataProvider provider)

Method Detail

acquireback to summary
public final Connection acquire()

Implements org.jooq.ConnectionProvider.acquire.

Doc from org.jooq.ConnectionProvider.acquire.

Acquire a connection from the connection lifecycle handler.

This method is called by jOOQ exactly once per execution lifecycle, i.e. per ExecuteContext. Implementations may freely chose, whether subsequent calls to this method:

  • return the same connection instance
  • return the same connection instance for the same thread
  • return the same connection instance for the same transaction (e.g. a javax.transaction.UserTransaction)
  • return a fresh connection instance every time

jOOQ will guarantee that every acquired connection is released through release(Connection) exactly once.

Returns:Connection

A connection for the current ExecuteContext. If null is returned (e.g. by NoConnectionProvider), then statements cannot be executed. Attempts to execute statements will result in a DetachedException.

Annotations
@Override
releaseback to summary
public final void release(Connection connection)

Implements org.jooq.ConnectionProvider.release.

Doc from org.jooq.ConnectionProvider.release.

Release a connection to the connection lifecycle handler.

jOOQ will guarantee that every acquired connection is released exactly once.

Parameters
connection:Connection

A connection that was previously obtained from acquire(). This is never null.

Annotations
@Override
org.jooq.tools.jdbc back to summary

private Class MockConnectionProvider.MockConnectionWrapper

extends MockConnection
Class Inheritance

Deprecated

as a consequence of MockConnection being deprecated. See corresponding docs for further information.

Field Summary

Modifier and TypeField and Description
pack-priv final Connection

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from org.jooq.tools.jdbc.MockConnection:
clearWarningsclosecommitcreateArrayOfcreateBlobcreateClobcreateNClobcreateSQLXMLcreateStatementcreateStatementcreateStatementcreateStructgetAutoCommitgetCataloggetClientInfogetClientInfogetHoldabilitygetMetaDatagetTransactionIsolationgetTypeMapgetWarningsisClosedisReadOnlyisValidisWrapperFornativeSQLprepareCallprepareCallprepareCallprepareStatementprepareStatementprepareStatementprepareStatementprepareStatementprepareStatementreleaseSavepointrollbackrollbacksetAutoCommitsetCatalogsetClientInfosetClientInfosetHoldabilitysetReadOnlysetSavepointsetSavepointsetTransactionIsolationsetTypeMapunwrap

Field Detail

connectionback to summary
pack-priv final Connection connection

Constructor Detail

MockConnectionWrapperback to summary
public MockConnectionWrapper(Connection connection)