如何拦截修改PreparedStatement的SQL和Spring?
How to intercept and modify SQL of PreparedStatement with Spring?
JDBCTemplate(或相关)中是否有一个中央位置,可以在其中 SQL 操作在发送到 DB 之前立即执行?
我想在发布到 RDBMS 的每个 SQL 语句前添加一个注释行。
希望有专门的扩展点。否则,我将需要编写自己的 class,它继承自 JDBCTemplate 并添加我想要避免的自定义逻辑。
Is there a central location in the JDBCTemplate
(or related) where SQL
manipulations can be performed immediately before they are sent to the DB?
是的,DataSource
。
与datasource-proxy you can intercept queries on DataSource
level using a custom QueryTransformer
:
private static class MyQueryTransformer implements QueryTransformer {
@Override
public String transformQuery(TransformInfo transformInfo) {
String query = transformInfo.getQuery();
// transform query
return query;
}
}
并将其提供给 ProxyDataSourceBuilder
:
ProxyDataSourceBuilder.create()
...
.queryTransformer(new MyQueryTransformer())
...
JDBCTemplate(或相关)中是否有一个中央位置,可以在其中 SQL 操作在发送到 DB 之前立即执行?
我想在发布到 RDBMS 的每个 SQL 语句前添加一个注释行。
希望有专门的扩展点。否则,我将需要编写自己的 class,它继承自 JDBCTemplate 并添加我想要避免的自定义逻辑。
Is there a central location in the
JDBCTemplate
(or related) whereSQL
manipulations can be performed immediately before they are sent to the DB?
是的,DataSource
。
与datasource-proxy you can intercept queries on DataSource
level using a custom QueryTransformer
:
private static class MyQueryTransformer implements QueryTransformer {
@Override
public String transformQuery(TransformInfo transformInfo) {
String query = transformInfo.getQuery();
// transform query
return query;
}
}
并将其提供给 ProxyDataSourceBuilder
:
ProxyDataSourceBuilder.create()
...
.queryTransformer(new MyQueryTransformer())
...