Module storm

Interface SqlInterceptor


public interface SqlInterceptor
Interceptor for SQL statement generation events.

This interceptor is invoked during the generation of SQL statements by the SqlTemplate, and not during their execution. It allows you to inspect SQL statements before they are sent to the database, operating completely separate from the execution phase.

Since:
1.1
  • Method Details

    • registerGlobalObserver

      static void registerGlobalObserver(@Nonnull Consumer<Sql> observer)
      Register a global observer that will be called for all SQL statements being generated.
      Parameters:
      observer - the observer to call for each SQL statement.
    • registerGlobalInterceptor

      static void registerGlobalInterceptor(@Nonnull UnaryOperator<Sql> interceptor)
      Register a global interceptor that will be called for all SQL statements being generated.
      Parameters:
      interceptor - the interceptor to call for each SQL statement.
    • unregisterGlobalObserver

      static void unregisterGlobalObserver(@Nonnull Consumer<Sql> observer)
      Unregister a global observer.
      Parameters:
      observer - the observer to unregister.
    • unregisterGlobalInterceptor

      static void unregisterGlobalInterceptor(@Nonnull UnaryOperator<Sql> interceptor)
      Unregister a global interceptor.
      Parameters:
      interceptor - the interceptor to unregister.
    • observe

      static void observe(@Nonnull Consumer<Sql> observer, Runnable runnable)
      Executes a Runnable action within the context of an SQL observer, which consumes SQL statements.

      This observer sees only SQL statements generated within the scope of this runnable and its child threads.

      Parameters:
      observer - the consumer invoked for each SQL statement.
      runnable - the action to execute.
    • observe

      static <T> T observe(@Nonnull Consumer<Sql> observer, @Nonnull Supplier<T> supplier)
      Executes a Supplier within the context of an SQL observer, returning its result.

      This observer sees only SQL statements generated within the scope of this supplier and its child threads.

      Type Parameters:
      T - the type of the supplied result.
      Parameters:
      observer - the consumer invoked for each SQL statement.
      supplier - the action supplying the result.
      Returns:
      the result of the supplied action.
    • observeThrowing

      static <T> T observeThrowing(@Nonnull Consumer<Sql> observer, @Nonnull Callable<T> callable) throws Exception
      Executes a Callable action within the context of an SQL observer, returning its result and potentially throwing exceptions.

      This observer sees only SQL statements generated within the scope of this callable and its child threads.

      Type Parameters:
      T - the type of the result.
      Parameters:
      observer - the consumer invoked for each SQL statement.
      callable - the action supplying the result and potentially throwing exceptions.
      Returns:
      the result of the callable action.
      Throws:
      Exception - if the callable action throws an exception.
    • intercept

      static void intercept(@Nonnull UnaryOperator<Sql> interceptor, @Nonnull Runnable runnable)
      Executes a Runnable action within the context of an SQL interceptor, which modifies SQL statements.

      This interceptor sees only SQL statements generated within the scope of this runnable and its child threads.

      Parameters:
      interceptor - the operator applied to each SQL statement.
      runnable - the action to execute.
    • intercept

      static <T> T intercept(@Nonnull UnaryOperator<Sql> interceptor, @Nonnull Supplier<T> supplier)
      Executes a Supplier within the context of an SQL interceptor, returning its result.

      This interceptor sees only SQL statements generated within the scope of this supplier and its child threads.

      Type Parameters:
      T - the type of the supplied result.
      Parameters:
      interceptor - the operator applied to each SQL statement.
      supplier - the action supplying the result.
      Returns:
      the result of the supplied action.
    • interceptThrowing

      static <T> T interceptThrowing(@Nonnull UnaryOperator<Sql> interceptor, @Nonnull Callable<T> callable) throws Exception
      Executes a Callable action within the context of an SQL interceptor, returning its result and potentially throwing exceptions.

      This interceptor sees only SQL statements generated within the scope of this callable and its child threads.

      Type Parameters:
      T - the type of the result.
      Parameters:
      interceptor - the operator applied to each SQL statement.
      callable - the action supplying the result and potentially throwing exceptions.
      Returns:
      the result of the callable action.
      Throws:
      Exception - if the callable action throws an exception.