我有一个在 Tomcat 中运行的 Java EE 应用程序,它使用 Tomcat 连接池,通过 postgres 数据库,并且该应用程序使用 OpenJPA for ORM。
对于某些操作,我需要从 postgres 访问 LargeObjectManager API。这需要我参考实际的 postgres 连接对象。
因此,我正在尝试深入研究从 OpenJPA 获得的连接对象,以获取实际的 Postgres 对象。但是我被一个“sun.misc.proxy.$ProxyNN”对象阻止了,我不确定我该如何走得更远。
这是我现在正在做的事情:
OpenJPAEntityManager oem = OpenJPAPersistence.cast(em);
// get open JPA connection object
Connection c = oem.getConnection();
// all the way down to what's no longer OpenJPA
c = ((DelegatingConnection)c).getInnermostDelegate()
这就是我停下来的地方。返回的对象如下。我不能在上面调用 ProxyConnection 方法,我什至不知道是谁创建了这些代理(但我敢打赌它是 Tomcat DBCP)。
c = {com.sun.proxy.$Proxy5@1793}"ProxyConnection[PooledConnection[Pooled connection wrapping physical connection org.postgresql.jdbc4.Jdbc4Connection@a7a434]]"
h = {org.apache.tomcat.jdbc.pool.ProxyConnection@5671}"ProxyConnection[PooledConnection[Pooled connection wrapping physical connection org.postgresql.jdbc4.Jdbc4Connection@a7a434]]"
connection = {org.apache.tomcat.jdbc.pool.PooledConnection@5673}"PooledConnection[Pooled connection wrapping physical connection org.postgresql.jdbc4.Jdbc4Connection@a7a434]"
poolProperties = {org.apache.tomcat.jdbc.pool.PoolProperties@5676}"ConnectionPool[defaultAutoCommit=false; defaultReadOnly=null; defaultTransactionIsolation=-1; defaultCatalog=null; driverClassName=null; maxActive=100; maxIdle=100; minIdle=10; initialSize=10; maxWait=30000; testOnBorrow=false; testOnReturn=false; timeBe...
connection = {com.sun.proxy.$Proxy0@5677}"Pooled connection wrapping physical connection org.postgresql.jdbc4.Jdbc4Connection@a7a434"
h = {org.postgresql.ds.jdbc23.AbstractJdbc23PooledConnection$ConnectionHandler@5686}
xaConnection = null
abandonTrace = null
timestamp = 1372621172141
lock = {java.util.concurrent.locks.ReentrantReadWriteLock@5678}"java.util.concurrent.locks.ReentrantReadWriteLock@9267fe[Write locks = 0, Read locks = 0]"
discarded = false
lastConnected = 1372620679402
lastValidated = 1372620679398
parent = {org.apache.tomcat.jdbc.pool.ConnectionPool@5674}
attributes = {java.util.HashMap@5679} size = 2
handler = {org.apache.tomcat.jdbc.pool.ProxyConnection@5671}"ProxyConnection[PooledConnection[Pooled connection wrapping physical connection org.postgresql.jdbc4.Jdbc4Connection@a7a434]]"
released = {java.util.concurrent.atomic.AtomicBoolean@5680}"false"
suspect = false
driver = null
pool = {org.apache.tomcat.jdbc.pool.ConnectionPool@5674}
properties = null
next = null
useEquals = true
tomcat:7.0.22 postgres jdbc:9.2-1002 openJPA:2.1.1