Skip to main content

rbatis_plus_extension/inner/
inner_interceptor.rs

1// Source: mybatis-plus-extension/.../inner/InnerInterceptor.java
2// Source: mybatis-plus-enhance-core/.../plugins/inner/EnhanceInnerInterceptor.java
3
4use async_trait::async_trait;
5use rbatis::executor::Executor;
6use rbatis::intercept::Action;
7use rbatis::Error;
8use crate::compat::TransactionEvent;
9use rbdc::db::ExecResult;
10use rbs::Value;
11
12/// Inner interceptor — the core extension point for all RBatis-Plus plugins.
13///
14/// Mirrors Java `InnerInterceptor` (from mybatis-plus) extended with
15/// `EnhanceInnerInterceptor` lifecycle hooks (from mybatis-plus-enhance).
16///
17/// Implementors receive before/after callbacks for query and exec operations.
18/// The interceptor can modify SQL, args, or short-circuit the result.
19#[async_trait]
20pub trait InnerInterceptor: Send + Sync + std::fmt::Debug {
21    /// Called before a query reaches the database.
22    /// Return `Action::Return` to short-circuit with the result.
23    async fn before_query(
24        &self,
25        _executor: &dyn Executor,
26        _sql: &mut String,
27        _args: &mut Vec<Value>,
28        _result: &mut Result<Value, Error>,
29    ) -> Result<Action, Error> {
30        Ok(Action::Next)
31    }
32
33    /// Called after a query completes successfully.
34    async fn after_query(
35        &self,
36        _executor: &dyn Executor,
37        _sql: &str,
38        _result: &mut Result<Value, Error>,
39    ) -> Result<(), Error> {
40        Ok(())
41    }
42
43    /// Called before an exec (INSERT/UPDATE/DELETE) reaches the database.
44    async fn before_update(
45        &self,
46        _executor: &dyn Executor,
47        _sql: &mut String,
48        _args: &mut Vec<Value>,
49        _result: &mut Result<ExecResult, Error>,
50    ) -> Result<Action, Error> {
51        Ok(Action::Next)
52    }
53
54    /// Called after an exec completes.
55    async fn after_update(
56        &self,
57        _executor: &dyn Executor,
58        _sql: &str,
59        _result: &mut Result<ExecResult, Error>,
60    ) -> Result<(), Error> {
61        Ok(())
62    }
63
64    /// Called after any operation (query or exec) completes, in `finally`.
65    /// Used for observation/metrics.
66    async fn after_execution(
67        &self,
68        _executor: &dyn Executor,
69        _sql: &str,
70        _elapsed_nanos: u64,
71        _failure: Option<&Error>,
72    ) {
73    }
74
75    /// Called on transaction events (commit/rollback).
76    async fn on_transaction_event(&self, _event: &TransactionEvent) {}
77}