public class SqlInterceptorChain extends Object implements SqlInterceptor
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addInterceptor(SqlInterceptor interceptor) |
void |
afterExecution(PreparedSql preparedSql,
Object applyResult,
Exception exception)
在 SQL 执行完成或发生异常后执行的拦截逻辑。
|
ExecutionControl |
beforeExecution(SqlStatementWrapper sqlStatementWrapper,
Connection connection)
在 SQL 执行之前的拦截逻辑。
|
static SqlInterceptorChain |
getInstance() |
SqlInterceptor |
getInterceptor(Class<? extends SqlInterceptor> sqlInterceptorClass) |
<R> R |
retrieveSkippedResult(SqlStatementWrapper sqlStatementWrapper,
Connection connection)
当
SqlInterceptor.beforeExecution(com.dynamic.sql.core.dml.SqlStatementWrapper, java.sql.Connection) 方法返回 SKIP 时调用,用于生成跳过数据库操作的结果。 |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetOrderpublic static SqlInterceptorChain getInstance()
public void addInterceptor(SqlInterceptor interceptor)
public ExecutionControl beforeExecution(SqlStatementWrapper sqlStatementWrapper, Connection connection)
SqlInterceptor此方法允许开发者在 SQL 被真正执行之前介入,进行检查、修改或控制。 通过返回值控制后续行为,包括继续执行、跳过执行或终止执行。
beforeExecution 在接口中 SqlInterceptorsqlStatementWrapper - 包含原始 SQL、解析后的参数及上下文信息的包装对象,
可用作 SQL 检查或动态修改的依据。connection - 数据库连接,允许拦截器基于连接执行必要的前置逻辑(如连接状态检查)。ExecutionControl 枚举值:
PROCEED 表示继续执行 SQL 或后续拦截器。SKIP 表示跳过 SQL 的实际执行,但仍会进入 SqlInterceptor.afterExecution(com.dynamic.sql.core.database.PreparedSql, java.lang.Object, java.lang.Exception) 逻辑。public <R> R retrieveSkippedResult(SqlStatementWrapper sqlStatementWrapper, Connection connection)
SqlInterceptorSqlInterceptor.beforeExecution(com.dynamic.sql.core.dml.SqlStatementWrapper, java.sql.Connection) 方法返回 SKIP 时调用,用于生成跳过数据库操作的结果。
通过该方法,拦截器可以根据业务逻辑返回一个自定义结果,而无需真正执行 SQL。
retrieveSkippedResult 在接口中 SqlInterceptorR - 返回结果的类型。sqlStatementWrapper - 包含原始 SQL 和参数的包装对象。connection - 数据库连接对象,用于获取上下文信息。null。public void afterExecution(PreparedSql preparedSql, Object applyResult, Exception exception)
SqlInterceptor此方法提供一个统一的回调,无论 SQL 正常执行完成或因异常中断均会触发。 可用于记录日志、清理资源或统计执行结果等操作。
afterExecution 在接口中 SqlInterceptorpreparedSql - 执行的 SQL 语句及其参数的预处理对象。可以用于记录或分析 SQL。applyResult - SQL 执行后的返回结果。如果 SQL 未实际执行,可能为 null。exception - 执行过程中可能抛出的异常。如果没有异常则为 null。public SqlInterceptor getInterceptor(Class<? extends SqlInterceptor> sqlInterceptorClass)
Copyright © 2024–2025 Dynamic-SQL. All rights reserved.