You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Bernd Bartke <be...@bbartke.de> on 2005/02/25 11:27:05 UTC
Tomcat 5.5.7 using builtin JDBC connection pool, can't access 'real'
connection - accessToUnderlyingConnectionAllowed=true
Hi there,
did anybody manage to access the underlying 'real' database connection?
I have got to use the PostgreSQL LargeObject API and therefore I need access to the delegated connection.
But after several hours of trial and error I lost my motivation ... It seems like:
- doesn't do anything:
<Resource ... accessToUnderlyingConnectionAllowed="true" .../>
- always returns 'false':
org.apache.tomcat.dbcp.dbcp.PoolingDriver.isAccessToUnderlyingConnectionAllowed() .
- doesn't do anything:
org.apache.tomcat.dbcp.dbcp.PoolingDriver.setAccessToUnderlyingConnectionAllowed(true);
- also doesn't do anything:
dataSource.setAccessToUnderlyingConnectionAllowed(true)
At last I found some kind of workaround, which is indeed not really desirable ...
Accessing an org.postgresql.PGConnection via a statement works ...
Maybe someone can help me.
Bye,
Bernd.
code snippet:
import org.apache.tomcat.dbcp.dbcp.PoolingDriver;
import org.apache.tomcat.dbcp.dbcp.BasicDataSource;
import org.apache.tomcat.dbcp.dbcp.DelegatingConnection;
import org.apache.tomcat.dbcp.dbcp.DelegatingStatement;
import org.postgresql.PGConnection;
...
logger.debug("PoolingDriver.isAccessToUnderlyingConnectionAllowed: "+PoolingDriver.isAccessToUnderlyingConnectionAllowed());
PoolingDriver.setAccessToUnderlyingConnectionAllowed(true);
BasicDataSource dataSource = (BasicDataSource)envContext.lookup("jdbc/website");
logger.debug("dataSource.isAccessToUnderlyingConnectionAllowed: "+dataSource.isAccessToUnderlyingConnectionAllowed());
dataSource.setAccessToUnderlyingConnectionAllowed(true);
logger.debug("getting delegating connection");
DelegatingConnection connection = (DelegatingConnection)dataSource.getConnection();
logger.debug("getting 'real' connection");
logger.debug("connection.getDelegate(): " + connection.getDelegate());
logger.debug("connection.getInnermostDelegate(): " + connection.getInnermostDelegate());
// for some reason this works:
DelegatingStatement stmt = (DelegatingStatement)connection.createStatement();
PGConnection pgCon = (PGConnection)stmt.getDelegate().getConnection();
stmt.close();
logger.debug(pgCon);
..
corresponding output:
"PoolingDriver.isAccessToUnderlyingConnectionAllowed: false"
"dataSource.isAccessToUnderlyingConnectionAllowed: false"
"getting delegating connection"
"getting 'real' connection"
"connection.getDelegate(): null"
"connection.getInnermostDelegate(): null"
"org.postgresql.jdbc3.Jdbc3Connection@842d9a"
my configuration:
"""""""""""""""""
server.xml:
- no pooling stuff in here -
WEB-INF/web.xml:
<web-app>
...
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/website</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
...
</web-app>
META-INF/context.xml:
<Context ...>
...
<Resource name="jdbc/website" scope="Shareable" type="javax.sql.DataSource"
auth="Container" factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
url="jdbc:postgresql://host:5432/website"
driverClassName="org.postgresql.Driver" username="tomcat" password="***"
defaultAutoCommit="false" defaultReadOnly="false"
defaultTransactionIsolation="READ_COMMITTED" initialSize="1" minIdle="1"
maxWait="10000" maxIdle="10" maxActive="20" accessToUnderlyingConnectionAllowed="true"
validationQuery="select 1"
/>
<!-- forget it ... also has no effect
<ResourceParams name="jdbc/website">
<parameter>
<name>accessToUnderlyingConnectionAllowed</name>
<value>true</value>
</parameter>
</ResourceParams>
-->
</Context>
java 1.4.2_07
tomcat 5.5.7
PostgreSQL 8.01
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org