set schema for new connections (oracle)

Ask around here!

set schema for new connections (oracle)

Postby cheer » Wed Mar 02, 2011 7:32 am

Hello,

We're using spring + dbcp + jdbc + oracle (no hibernate!) now and trying to switch to another connection pool. Is there any possibility to set oracle schema for new connections? In DBCP the schema could be set by overriding getConnection() method which is not good, because the 'alter session ...' query is issued every time the connection is retrieved. It'd be really great to have some property for setting schema in application context. However, I did find nothing about setting schema in BoneCP.

Thanks.
cheer
 
Posts: 6
Joined: Mon Feb 28, 2011 2:30 pm

Re: set schema for new connections (oracle)

Postby wwadge » Wed Mar 02, 2011 8:01 am

One way you could do this is to setup a connection hook, specifically the onAquire() hook:


/** Called upon getting a new connection from the JDBC driver (and prior to
* inserting into the pool). You may call connection.getInternalConnection() to obtain
* a handle to the actual (unwrapped) connection obtained from the driver.
* @param connection Handle to the new connection
*/
void onAcquire(ConnectionHandle connection);

This hook will be called just once per connection (i.e. the first time the connection is retrieved and placed into the pool ready for use).

Wallace
wwadge
Site Admin
 
Posts: 713
Joined: Mon Oct 19, 2009 7:50 pm

Re: set schema for new connections (oracle)

Postby cheer » Fri Mar 04, 2011 9:23 am

Thanks, Wallace!

I was successfully able to set schema for the new connections. If someone else is interested, I extended the AbstractConnectionHook class and set the hook in the applicationContext file.
cheer
 
Posts: 6
Joined: Mon Feb 28, 2011 2:30 pm

Re: set schema for new connections (oracle)

Postby wwadge » Fri Mar 04, 2011 9:25 am

Just make sure that the hook is thread-safe and re-entrant since it can be called concurrently in different threads.

:-)

Wallace
wwadge
Site Admin
 
Posts: 713
Joined: Mon Oct 19, 2009 7:50 pm


Return to BoneCP - Help, Q&A, Whatever!

Who is online

Users browsing this forum: Google [Bot] and 2 guests