当前位置:网站首页>How to use filters in jfinal to monitor Druid for SQL execution?
How to use filters in jfinal to monitor Druid for SQL execution?
2022-06-29 19:42:00 【InfoQ】
Configure filters
public void configPlugin(Plugins me) {
DruidPlugin druidPlugin = createDruidPlugin_holdoa();
druidPlugin.setPublicKey(p.get("publicKeydebug").trim());
wallFilter = new WallFilter();
wallFilter.setDbType("mysql");
druidPlugin_oa.addFilter(wallFilter);
druidPlugin_oa.addFilter(new StatFilter());
me.add(druidPlugin);
}import com.alibaba.druid.filter.FilterEventAdapter;
public class DataScopeFilter extends FilterEventAdapter {
}public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql) throws SQLException {...}
protected void statementExecuteUpdateBefore(StatementProxy statement, String sql) {...}
protected void statementExecuteUpdateAfter(StatementProxy statement, String sql, int updateCount) {...}
protected void statementExecuteQueryBefore(StatementProxy statement, String sql) {...}
protected void statementExecuteQueryAfter(StatementProxy statement, String sql, ResultSetProxy resultSet) {...}
protected void statementExecuteBefore(StatementProxy statement, String sql) {...}
protected void statementExecuteAfter(StatementProxy statement, String sql, boolean result) {...}package xxxx.xxxx;
import com.alibaba.druid.filter.FilterChain;
import com.alibaba.druid.filter.FilterEventAdapter;
import com.alibaba.druid.proxy.jdbc.ResultSetProxy;
import com.alibaba.druid.proxy.jdbc.StatementProxy;
import com.jfinal.kit.LogKit;
import java.sql.SQLException;
public class DataScopeFilter extends FilterEventAdapter {
@Override
public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql) throws SQLException {
LogKit.info("statement_execute");
return super.statement_execute(chain, statement, sql);
}
@Override
protected void statementExecuteQueryBefore(StatementProxy statement, String sql) {
LogKit.info("statementExecuteQueryBefore");
super.statementExecuteQueryBefore(statement, sql);
}
@Override
protected void statementExecuteQueryAfter(StatementProxy statement, String sql, ResultSetProxy resultSet) {
LogKit.info("statementExecuteQueryAfter");
super.statementExecuteQueryAfter(statement, sql, resultSet);
}
@Override
protected void statementExecuteBefore(StatementProxy statement, String sql) {
LogKit.info("statementExecuteBefore");
super.statementExecuteBefore(statement, sql);
}
@Override
protected void statementExecuteAfter(StatementProxy statement, String sql, boolean result) {
LogKit.info("statementExecuteAfter");
super.statementExecuteAfter(statement, sql, result);
}
@Override
public ResultSetProxy statement_executeQuery(FilterChain chain, StatementProxy statement, String sql)
throws SQLException {
LogKit.info("statement_executeQuery");
return super.statement_executeQuery(chain, statement, sql);
}
}druidPlugin.addFilter(new DataScopeFilter());statement_executeQuery
statementExecuteQueryBefore
statementExecuteQueryAfter@Override
public ResultSetProxy statement_executeQuery(FilterChain chain, StatementProxy statement, String sql)
throws SQLException {
statementExecuteQueryBefore(statement, sql);
try {
ResultSetProxy resultSet = super.statement_executeQuery(chain, statement, sql);
if (resultSet != null) {
statementExecuteQueryAfter(statement, sql, resultSet);
resultSetOpenAfter(resultSet);
}
return resultSet;
} catch (SQLException error) {
statement_executeErrorAfter(statement, sql, error);
throw error;
} catch (RuntimeException error) {
statement_executeErrorAfter(statement, sql, error);
throw error;
} catch (Error error) {
statement_executeErrorAfter(statement, sql, error);
throw error;
}
} @Override
public ResultSetProxy statement_executeQuery(FilterChain chain, StatementProxy statement, String sql)
throws SQLException {
statementExecuteQueryBefore(statement, sql);
ResultSetProxy result = chain.statement_executeQuery(statement, sql);
statementExecuteQueryAfter(statement, sql, result);
return result;
}statementExecuteQueryBefore
statement_executeQuery
statementExecuteQueryAftersql Be declared final type
public class DruidPooledPreparedStatement extends DruidPooledStatement implements PreparedStatement {
private final static Log LOG = LogFactory.getLog(DruidPooledPreparedStatement.class);
private final PreparedStatementHolder holder;
private final PreparedStatement stmt;
private final String sql;
....
}@Override
public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql)
throws SQLException {
// It can be modified SQL Purpose
sql += " LIMIT 1";
PreparedStatementProxy statement = super.connection_prepareStatement(chain, connection, sql);
statementPrepareAfter(statement);
return statement;
}边栏推荐
- Exploration and practice of NLP problem modeling scheme
- DAO 中存在的不足和优化方案
- How to install and use computer SSD hard disk
- How important is it to make a silver K-line chart?
- Win11安装权限在哪里设置?Win11安装权限设置的方法
- 软件测试逻辑覆盖相关理解
- 畫虎國手孟祥順數字藏品限量發售,隨贈虎年茅臺
- [network orientation training] - Enterprise Park Network Design - [had done]
- powershell命令仅输出目录列表
- Win11策略服务被禁用怎么办?Win11策略服务被禁用的解决方法
猜你喜欢

Exploration and practice of NLP problem modeling scheme

终于,进亚马逊了~

细说GaussDB(DWS)复杂多样的资源负载管理手段

From CIO to Consultant: the transformation of it leaders

使用 OpenCV 的基于标记的增强现实

Performance improvement at the cost of other components is not good

KDD 2022 | 協同過濾中考慮錶征對齊和均勻性

电脑ssd硬盘怎么安装使用

【观察】软通动力刘天文:拥抱变化“顺势而为”,做中国数字经济“使能者”...

JVM(4) 字节码技术+运行期优化
随机推荐
npm ERR! fatal: early EOF npm ERR! fatal: index-pack failed
Nacos problem
Tiger painter mengxiangshun's digital collection is on sale in limited quantities and comes with Maotai in the year of the tiger
小米笔试真题一
JVM (4) bytecode technology + runtime optimization
Win11系统小组件打不开?Win11系统小组件无法打开解决方法
测试方法学习
[observation] softcom power liutianwen: embrace change and "follow the trend" to become an "enabler" of China's digital economy
Installation and configuration of MariaDB
JVM (4) Bytecode Technology + Runtime Optimization
3-3 host discovery - layer 4 discovery
【网络方向实训】-企业园区网络设计-【Had Done】
Game maker Foundation presents: Valley of belonging
JVM(2) 垃圾回收
Win11策略服务被禁用怎么办?Win11策略服务被禁用的解决方法
Docker compose deploy the flask project and build the redis service
Why is informatization ≠ digitalization? Finally someone made it clear
并查集(Union-Find)
Go: how to write a correct UDP server
剑指 Offer 59 - I. 滑动窗口的最大值