1

我正在尝试将一段特定的 SQL 添加到使用 AspectJ 在系统中执行的所有 SQL 中。

我以前没有使用过 AspectJ,但我相信我需要做的是创建一个切入点

调用(PreparedStatement Connection.prepareStatement(字符串))

并提供建议

before(Connection con, String sql): call(PreparedStatement Connection.prepareStatement(String)) && target(con) && args(sql) { sql = "exec myStordProc();" + sql; }

之后 Connection.prepareStatement() 方法将继续使用更改后的字符串吗?

或者我应该拦截对 prepareStatement 和 executeQuery 的调用并创建一条建议,将其更改为 addBatch() 添加我存储的过程调用作为第一批 sql,然后最终使用 executeBatch() 执行原始 sql?

任何指针将不胜感激。

谢谢

4

1 回答 1

1

如果要修改参数值,则需要使用周围的建议,以便可以使用修改后的值进行调用:

around(...): ... {
    proceed("exec myStordProc();" + sql);
}
于 2011-03-09T10:51:16.667 回答