开发者

Can I amend the executed SQL before execution using an AspectJ pointcut

开发者 https://www.devze.com 2023-02-16 04:54 出处:网络
I\'m trying to add a specific piece of SQL to all SQL executed in a system using AspectJ. I\'ve not used AspectJ before but I believe what I need to do is create a pointcut on

I'm trying to add a specific piece of SQL to all SQL executed in a system using AspectJ.

I've not used AspectJ before but I believe what I need to do is create a pointcut on

call(PreparedStatement Connection.prepareStatement(String))

and provide the advice

before(Connection con, String sql): call(PreparedStatement Connection.prepareStatement(String)) &a开发者_如何学Pythonmp;& target(con) && args(sql) { sql = "exec myStordProc();" + sql; }

after which the Connection.prepareStatement() method will continue with the altered String?

Or should I be intercepting calls to prepareStatement and executeQuery and creating a piece of advice that changes this to addBatch() adding my stored procdure call as the first batch sql then the original sql finally executing with executeBatch()?

Any pointers would be much appreciated.

Thanks


If you want to modify a parameters value you would need to use around advice so that you can make the call with your modified value:

around(...): ... {
    proceed("exec myStordProc();" + sql);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消