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 Summary
Static MethodsModifier and TypeMethodDescriptionstatic voidintercept(UnaryOperator<Sql> interceptor, Runnable runnable) Executes aRunnableaction within the context of an SQL interceptor, which modifies SQL statements.static <T> Tintercept(UnaryOperator<Sql> interceptor, Supplier<T> supplier) Executes aSupplierwithin the context of an SQL interceptor, returning its result.static <T> TinterceptThrowing(UnaryOperator<Sql> interceptor, Callable<T> callable) Executes aCallableaction within the context of an SQL interceptor, returning its result and potentially throwing exceptions.static voidExecutes aRunnableaction within the context of an SQL observer, which consumes SQL statements.static <T> TExecutes aSupplierwithin the context of an SQL observer, returning its result.static <T> TobserveThrowing(Consumer<Sql> observer, Callable<T> callable) Executes aCallableaction within the context of an SQL observer, returning its result and potentially throwing exceptions.static voidregisterGlobalInterceptor(UnaryOperator<Sql> interceptor) Register a global interceptor that will be called for all SQL statements being generated.static voidregisterGlobalObserver(Consumer<Sql> observer) Register a global observer that will be called for all SQL statements being generated.static voidunregisterGlobalInterceptor(UnaryOperator<Sql> interceptor) Unregister a global interceptor.static voidunregisterGlobalObserver(Consumer<Sql> observer) Unregister a global observer.
-
Method Details
-
registerGlobalObserver
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
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
Unregister a global observer.- Parameters:
observer- the observer to unregister.
-
unregisterGlobalInterceptor
Unregister a global interceptor.- Parameters:
interceptor- the interceptor to unregister.
-
observe
Executes aRunnableaction within the context of an SQL observer, which consumes SQL statements.This observer sees only SQL statements generated within the scope of this
runnableand its child threads.- Parameters:
observer- the consumer invoked for each SQL statement.runnable- the action to execute.
-
observe
Executes aSupplierwithin the context of an SQL observer, returning its result.This observer sees only SQL statements generated within the scope of this
supplierand 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 aCallableaction 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
callableand 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
Executes aRunnableaction within the context of an SQL interceptor, which modifies SQL statements.This interceptor sees only SQL statements generated within the scope of this
runnableand its child threads.- Parameters:
interceptor- the operator applied to each SQL statement.runnable- the action to execute.
-
intercept
Executes aSupplierwithin the context of an SQL interceptor, returning its result.This interceptor sees only SQL statements generated within the scope of this
supplierand 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 aCallableaction 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
callableand 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.
-