[英]How to determine info about WebLogic datasource from datasource connection?
I have a Spring app running in WebLogic. 我有一个在WebLogic中运行的Spring应用程序。 In my DAO, it inherits a base class with a method that returns a "javax.sql.DataSource". 在我的DAO中,它继承了带有返回“ javax.sql.DataSource”的方法的基类。 I inject that datasource indirectly using the "jee:jndi-lookup" in my Spring application context to get the datasource from JNDI. 我在Spring应用程序上下文中使用“ jee:jndi-lookup”间接注入了该数据源,以从JNDI获取数据源。 When I look at this in the debugger, it appears to be a "weblogic.jdbc.common.internal.RmiDataSource". 当我在调试器中查看时,它似乎是“ weblogic.jdbc.common.internal.RmiDataSource”。
I'd like to figure out how I can introspect into that datasource in my code to determine information about the database I'm connected to, particularly the host, port, SID, and username. 我想弄清楚如何在代码中内省该数据源,以确定有关我连接的数据库的信息,尤其是主机,端口,SID和用户名。 Is there any way I could do that? 有什么办法可以做到吗?
For some background, I have extensive diagnostics in my app for troubleshooting db connection and query issues. 在某些背景下,我的应用程序中包含大量诊断程序,用于对数据库连接和查询问题进行故障排除。 It would be very helpful if at runtime, I could introspect information about the WebLogic datasource from the database connection in use. 如果在运行时我可以从正在使用的数据库连接中反思有关WebLogic数据源的信息,那将非常有帮助。
As I described, I already determined in the debugger what the actual type was, and I've examined all the obvious properties in that object for casting or reflection opportunities, and I don't see any obvious indications of information like "host", "port", or "SID". 正如我所描述的,我已经在调试器中确定了实际类型是什么,并且已经检查了该对象中所有明显的属性以进行强制转换或反射,并且看不到诸如“主机”之类的信息的明显迹象, “端口”或“ SID”。
I think you can use reflection and call all the getter methods of this class. 我认为您可以使用反射并调用此类的所有getter方法。
That should get you some helpful information. 那应该给您一些有用的信息。 But based on the name of this class, 但是根据此类的名称,
it looks like it's an internal WebLogic class and it's not really designed for this. 它看起来像是内部WebLogic类,并且并非为此真正设计的。
Still, you can do it with reflection, you can even call private getter methods with reflection. 不过,您可以使用反射来做到这一点,甚至可以使用反射来调用私有的getter方法。
The "right" JEE approach is not caring about these low-level details in code. “正确的” JEE方法并不关心代码中的这些底层细节。 After finding out which DataSource doesn't work, troubleshooting problems involves only application server logs and application server configuration tweaks. 在找出哪个数据源不起作用之后,故障排除问题仅涉及应用程序服务器日志和应用程序服务器配置调整。
There are several good reasons for insulating applications from DataSource details: 有几个很好的理由使应用程序与DataSource详细信息隔离:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.