Class ExternalSqlClientPool

java.lang.Object
org.hibernate.reactive.pool.impl.SqlClientPool
org.hibernate.reactive.pool.impl.ExternalSqlClientPool
All Implemented Interfaces:
Serializable, ReactiveConnectionPool, org.hibernate.service.Service

public final class ExternalSqlClientPool extends SqlClientPool
A pool of reactive connections backed by a Vert.x Pool.

This is an alternative to DefaultSqlClientPool, for use when one doesn't want Hibernate Reactive to manage the lifecycle of the underlying Pool.

This implementation is meant to be used in Quarkus or other runtimes.

N.B. the injected pool instance is required to be threadsafe, while the default implementation in Vert.x version 3 is not. So use this only by extensions of the default implementation which can deliver a different actual underlying Pool instance for each thread. All clients of the pool instances retrieved from the injected Pool instance are expected to be running on a Vert.x event loop. Integration tests in Hibernate Reactive run exclusively on the Vert.x event loop, however in practice this will need to be guaranteed by the integrating runtime as well. Alternatively, a valid integration mode which doesn't require wrapping the Pool instance with a ThreadLocal could be devised by having all of the use of the Hibernate Reactive's SessionFactory instance (Stage.SessionFactory or a Mutiny.SessionFactory) constrained within a single thread, running within the Vert.x event loop.

See Also:
  • Constructor Details

    • ExternalSqlClientPool

      public ExternalSqlClientPool(io.vertx.sqlclient.Pool pool, org.hibernate.engine.jdbc.spi.SqlStatementLogger sqlStatementLogger, org.hibernate.engine.jdbc.spi.SqlExceptionHelper sqlExceptionHelper)
  • Method Details

    • getPool

      protected io.vertx.sqlclient.Pool getPool()
      Specified by:
      getPool in class SqlClientPool
      Returns:
      the underlying Vert.x Pool for the current context.
    • getSqlStatementLogger

      protected org.hibernate.engine.jdbc.spi.SqlStatementLogger getSqlStatementLogger()
      Specified by:
      getSqlStatementLogger in class SqlClientPool
      Returns:
      a Hibernate SqlStatementLogger for logging SQL statements as they are executed
    • getSqlExceptionHelper

      public org.hibernate.engine.jdbc.spi.SqlExceptionHelper getSqlExceptionHelper()
      Specified by:
      getSqlExceptionHelper in class SqlClientPool
      Returns:
      a Hibernate SqlExceptionHelper for converting exceptions
    • getCloseFuture

      public CompletionStage<Void> getCloseFuture()
      Since this Service implementation does not implement @Stoppable and we're only adapting an externally provided pool, we will not actually close such provided pool when Hibernate ORM is shutdown (it doesn't own the lifecycle of this external component). Therefore, there is no need to wait for its shutdown and this method returns an already successfully completed CompletionStage.
    • selectJdbcOutsideTransaction

      public CompletionStage<ResultSet> selectJdbcOutsideTransaction(String sql, Object[] paramValues)
      Description copied from class: SqlClientPool
      This method is intended to be used only for queries returning a ResultSet that must be executed outside any "current" transaction (i.e. with autocommit=true).

      For example, it would be appropriate to use this method when performing queries on information_schema or system tables in order to obtain metadata information about catalogs, schemas, tables, etc.

      Specified by:
      selectJdbcOutsideTransaction in interface ReactiveConnectionPool
      Overrides:
      selectJdbcOutsideTransaction in class SqlClientPool
      Parameters:
      sql - - the query to execute outside a transaction
      paramValues - - a non-null array of parameter values
      Returns:
      the CompletionStage from executing the query.
    • preparedQueryOutsideTransaction

      public CompletionStage<io.vertx.sqlclient.RowSet<io.vertx.sqlclient.Row>> preparedQueryOutsideTransaction(String sql, io.vertx.sqlclient.Tuple parameters)