拦截对数据库的查询
所以我试图拦截对数据库的调用。现在我有一个java程序来监听通知(各种程序发出的调用)。我正在尝试扩展它来分析这些程序之一对数据库发出的查询,该数据库使用 Hibernate ORM。
我正在研究 Hibernate Interceptor,这看起来很有趣。如何将拦截器集成到我的程序中?我不确定如何使用它与其他程序连接以监听呼叫。或者 Listener 会是更好的选择吗?
谢谢,哈利
So I'm trying to intercept calls made to a database. Right now I have a java program which listens for notifications (calls made by various programs). I'm trying to extend this to analyse queries made by one of these programs to the database, which uses the Hibernate ORM.
I'm looking at the Hibernate Interceptor and that seems quite interesting. How could I integrate the Interceptor into my program? I'm not sure how I can use it to connect with the other programs to listen for calls. Or would the Listener be a better choice?
Thanks, Harry
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能正在寻找代理 JDBC 驱动程序。它们包装了普通的 JDBC 驱动程序并记录正在发生的情况。
一个例子是 log4jdbc,我确信还有其他例子。
这些的好处是您不需要更改程序,只需更改它使用的 JDBC 驱动程序的名称即可。
You are probably looking for a proxy JDBC driver. These wrap a normal JDBC driver and log what is going on.
One example is log4jdbc, I'm sure there are others.
The good thing about these is that you don't need to change your program, just the name of the JDBC driver it uses.
要在程序中集成 Hibernate 拦截器,您必须执行以下步骤:
创建一个扩展 hibernate 的 EmptyInterceptor 的类。
实现与您的要求相关的方法。
将其设置为配置,如下
配置cfg = new Configuration();
cfg.setInterceptor(new YourInterceptor());
To Integrate Hibernate interceptor in your program, you have to follow these steps:
Create a class which extends hibernate's EmptyInterceptor.
Implement the methods which are relevant to your requirement.
Set it to the Configuration, as
Configuration cfg = new Configuration();
cfg.setInterceptor(new YourInterceptor());