hibernate-reactive icon indicating copy to clipboard operation
hibernate-reactive copied to clipboard

Support the `StatementInspector` API

Open DavideD opened this issue 2 years ago • 1 comments

Based on this question on StackOverflow, we don't support the StatementInspector API.

It seems something useful to have, but I haven't looked into it yet.

We should:

  1. Check that it actually doesn't work
  2. Figure out how to make it work, if there's an alternative, or if it makes sense to have it

DavideD avatar Jul 07 '23 08:07 DavideD

I think it's fair to say that StatementInspector doesn't work with Hibernate Reactive currently.

As a workaround, this should work:

You could create a wrapper around ReactiveConnection and intercepts all the calls related to the execution of the query.

For example, you can have:

public class ConnectionInterceptor implements ReactiveConnection {
   private final ReactiveConnection delegate;

   public ConnectionInterceptor(ReactiveConnection delegate) {
      this.delegate = delegate;
   }

   public CompletionStage<Void> execute(String sql) {
       String newSql = convert(sql);
       return delegate.execute(newSql);
   }

   // ... You need to implement all the other methods running a query
}
package my.example;

public class MyPool extends DefaultSqlClientPool {

   public CompletionStage<ReactiveConnection> getConnection() {
     return super.getConnection().thenApply( ConnectionInterceptor::new );
   }

}

You can register the new pool class using the property hibernate.vertx.pool.class:

hibernate.vertx.pool.class = my.example.MyPool

Taken from this SO answer.

DavideD avatar Nov 05 '24 08:11 DavideD