Database Reference
In-Depth Information
We will also set up some initial properties for the connection pool and pass them to the
setConnectionCacheProperties() method. These are similar to the pool properties we saw earlier for the
OCI connection pool, but the key names are quite different.
Use Statement Caching
You will see some confusion when doing research on the web regarding lightweight connection pooling.
Much of this confusion stems from the availability of statement caching in the OracleDataSource class. It
is particularly muddled by the reference to connection pooling as connection caching. For good
measure, let's enable statement caching as in Listing 8-16. This has nothing to do with connection
pooling.
Listing 8-16. Enable Statement Caching
cpool.setImplicitCachingEnabled(true);
With statement caching, when you call a prepared statement, the local connection caches it. Should
you call the statement again, it executes faster than it would if not cached.
Implicit caching, which we enabled by calling setImplicitCachingEnabled(true) , happens
automatically. You can also enable explicit statement caching which requires you to designate a key
string (name) for the statement and to recall it by that name. For more information, do an Internet
search on Oracle explicit statement caching.
Get the Proxy Session
We request a thin connection from the pool through the getConnection() method, as shown in Listing 8-
17. After getting the pooled connection, we request a proxy session. Pass the user identity from NTSystem
or UnixSystem as a property value to the openProxySession() method of the OracleConnection . Again, for
convenience, we just add another value, PROXY_USER_NAME to the existing Property class.
Listing 8-17. Get Proxy Connection from Thin-Client Connection Pool
conn = (OracleConnection)cpool.getConnection();
prop.setProperty(OracleConnection.PROXY_USER_NAME, userName );
conn.openProxySession(OracleConnection.PROXYTYPE_USER_NAME, prop);
When we close the proxy session, the connection will return to the pool for reuse:
conn.close( OracleConnection.PROXY_SESSION );
See the Proxy Session
The results from our queries on the thin client proxy session are as we would expect. We have set both
our client identifier and our proxying user, osuser through the proxy user, appusr . The connection passes
the tests for our secure application role and is able to read data from the HR schema.
Is proxy session: true
user : OSUSER
userenv proxy_user : APPUSR
userenv current_user : OSUSER
 
Search WWH ::




Custom Search