在Jboss中使用DBMS_APPLICATION_INFO [英] using DBMS_APPLICATION_INFO with Jboss
问题描述
有人有示例如何将 DBMS_APPLICATION_INFO 包与JBOSS?
Does anyone have examples of how to use DBMS_APPLICATION_INFO package with JBOSS?
我们有在JBOSS中运行并共享数据库池的各种应用程序.我希望在每个会话开始时,这些应用程序使用DBMS_APPLICATION_INFO向数据库标识自己,以便我可以更轻松地跟踪应用程序的哪些部分引起数据库问题.
We have a various applications which run within JBOSS and share db pools. I would like, at the start of each session these applications to identify themselves to the database using DBMS_APPLICATION_INFO so I can more easily track which sections of the application is causing database issues.
我对JBOSS的会话生命周期不太熟悉,但是到最后,需要发生的事情是在事务的开始和结束时,需要调用此程序包.
I'm not too familiar with session life cycles in JBOSS, but at the end of the day, what needs to happen is at the start and end of a transaction, this package needs to be called.
有人做过吗?
推荐答案
是的,您可以在连接池周围编写包装器类,并在连接周围编写包装器 因此,假设您拥有:
yes, you can write a wrapper class around your connection pool, and a wraper around the connection so lets say you have:
OracleConnection conn=connectionPool.getConnection("java:scott@mydb");
将其更改为:
public class LoggingConnectionPool extends ConnectionPool{
public OracleConnection getConnection(String datasourceName, String module, String action){
OracleConnection conn=getConnection(datasourceName);
CallableStatement call=conn.preparedCall("begin dbms_application_info.setModule(module_name => ?, action_name => ?); end;");
try{
call.setString(1,module);
call.setString(2,action);
call.execute();
finally{
call.close();
}
return new WrappedOracleConnection(conn);
}
请注意上面WrappedOracleConnection的使用.您需要使用此功能,因为您需要捕获关闭呼叫
Note the use of WrappedOracleConnection above. You need this because you need to trap the close call
public class WrappedOracleConnection extends OracleConnection{
public void close(){
CallableStatement call=this.preparedCall("begin dbms_application_info.setModule(module_name => ?, action_name => ?); end;");
try{
call.setNull(1,Types.VARCHAR);
call.setNull(2,Types.VARCHAR);
call.execute();
finally{
call.close();
}
}
// and you need to implement every other method
//for example
public CallableStatement prepareCall(String command){
return super.prepareCall(command);
}
...
}
希望这会有所帮助,我在开发服务器上执行了类似的操作,以捕获未关闭的连接(未返回到池中).
Hope this helps, I do something similar on a development server to catch connections that are not closed (not returned to the pool).
这篇关于在Jboss中使用DBMS_APPLICATION_INFO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!