RE: Casting a Connection as an OracleConnection in Tomcat 7

2011-12-02 Thread Jason Perrone
So, I can't cast the connection Tomcat returns as a DelegatingConnection.  
DelegatingConnection is from Commons DBCP and this connection is 
org.apache.tomcat.dbcp.dbcp.PoolableConnection.  I do not want to reference any 
Tomcat libraries directly because our product is container agnostic.  Any 
suggestions would be greatly appreciated.

Thank you.


-Original Message-
From: Christopher Schultz [mailto:ch...@christopherschultz.net] 
Sent: Tuesday, November 29, 2011 5:08 PM
To: Tomcat Users List
Subject: Re: Casting a Connection as an OracleConnection in Tomcat 7

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Jason,

On 11/29/11 2:34 PM, Jason Perrone wrote:
 Has anyone yet figured out how to cast the PoolableConnection that 
 Tomcat 7 now returns when you get a Connection from a DataSource as an 
 OracleConnection?

If you are using the standard pool (which uses DBCP under the hood), I think 
you get use getInnermostDelegate after casting to DelegatingConnection. That 
thing that gets returned should be an OracleConnection.

You also might need to set accessToUnderlyingConnectionAllowed on the 
DataSource in order to actually call getInnermostDelegate. See the DBCP 
configuration page and look for that setting for more info.

As always, remember to close the connection you got from the DataSource, not 
the inner delegate, or you will be toast.

 In Tomcat 6 the connection was returned as T4CConnection and had no 
 problem being cast as an OracleConnection. Now, I just can't figure it 
 out. Tried using the Commons DBCP package to get native JDBC 
 connections, and every other thing I found by Googling it.

What did you actually try? What is the runtime type of the Connection object 
returned from DataSource.getConnection? For me, it's BasicDataSource.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk7VV8wACgkQ9CaO5/Lv0PDTOgCgqC3q35DFDoGaCGsdWwnRfN48
k5gAn3J+wzFTrzN3kmrsLWDAnLxHNxBo
=ro6R
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Casting a Connection as an OracleConnection in Tomcat 7

2011-12-02 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Jason,

On 12/2/11 3:23 PM, Jason Perrone wrote:
 So, I can't cast the connection Tomcat returns as a 
 DelegatingConnection.  DelegatingConnection is from Commons DBCP
 and this connection is
 org.apache.tomcat.dbcp.dbcp.PoolableConnection.  I do not want to
 reference any Tomcat libraries directly because our product is
 container agnostic.  Any suggestions would be greatly appreciated.

Two thoughts:

1. Use reflection ;)

2. Stop trying to cast to OracleConnection

What do you need OracleConnection for, anyway?

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk7ZNSgACgkQ9CaO5/Lv0PA8iACeIyzpkgEx7B49HKcx7ZquASYK
UXEAnRAL4dcEPFENnatgp0WSJ+rQXMAN
=AWRl
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



RE: Casting a Connection as an OracleConnection in Tomcat 7

2011-12-02 Thread Jason Perrone
I might be able to do it as an SQL statement instead of using this driver 
method... 


-Original Message-
From: Christopher Schultz [mailto:ch...@christopherschultz.net] 
Sent: Friday, December 02, 2011 3:29 PM
To: Tomcat Users List
Subject: Re: Casting a Connection as an OracleConnection in Tomcat 7

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Jason,

On 12/2/11 3:23 PM, Jason Perrone wrote:
 So, I can't cast the connection Tomcat returns as a 
 DelegatingConnection.  DelegatingConnection is from Commons DBCP and 
 this connection is org.apache.tomcat.dbcp.dbcp.PoolableConnection.  I 
 do not want to reference any Tomcat libraries directly because our 
 product is container agnostic.  Any suggestions would be greatly 
 appreciated.

Two thoughts:

1. Use reflection ;)

2. Stop trying to cast to OracleConnection

What do you need OracleConnection for, anyway?

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk7ZNSgACgkQ9CaO5/Lv0PA8iACeIyzpkgEx7B49HKcx7ZquASYK
UXEAnRAL4dcEPFENnatgp0WSJ+rQXMAN
=AWRl
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



RE: Casting a Connection as an OracleConnection in Tomcat 7

2011-12-02 Thread Jason Perrone
Bingo.

Yep, screw casting as an Oracle connection.  Just do this:

session.beginTransaction();
PreparedStatement st = session.connection().prepareStatement(alter session set 
TIME_ZONE=' + timeZone.getID() + ');
st.execute();
session.connection().commit();
st.close();

Thanks Christopher, for getting me to think outside the box :)



-Original Message-
From: Christopher Schultz [mailto:ch...@christopherschultz.net] 
Sent: Friday, December 02, 2011 3:29 PM
To: Tomcat Users List
Subject: Re: Casting a Connection as an OracleConnection in Tomcat 7

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Jason,

On 12/2/11 3:23 PM, Jason Perrone wrote:
 So, I can't cast the connection Tomcat returns as a 
 DelegatingConnection.  DelegatingConnection is from Commons DBCP and 
 this connection is org.apache.tomcat.dbcp.dbcp.PoolableConnection.  I 
 do not want to reference any Tomcat libraries directly because our 
 product is container agnostic.  Any suggestions would be greatly 
 appreciated.

Two thoughts:

1. Use reflection ;)

2. Stop trying to cast to OracleConnection

What do you need OracleConnection for, anyway?

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk7ZNSgACgkQ9CaO5/Lv0PA8iACeIyzpkgEx7B49HKcx7ZquASYK
UXEAnRAL4dcEPFENnatgp0WSJ+rQXMAN
=AWRl
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Casting a Connection as an OracleConnection in Tomcat 7

2011-12-02 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Jason,

On 12/2/11 3:54 PM, Jason Perrone wrote:
 Yep, screw casting as an Oracle connection.

That would be my recommendation. People used to cast to
OracleConnection because JDBC didn't have support for LOB types way
back in the day. Some old online HOWTO must have been the meeting
place for Google searchers to discover that great hint to make your
life into a living hell by using underlying connections when it's not
necessary.

 Just do this:
 
 session.beginTransaction(); PreparedStatement st =
 session.connection().prepareStatement(alter session set
 TIME_ZONE=' + timeZone.getID() + ');

If you're going to use a PreparedStatement, you may as well actually
used the parametric replacement that it offers. :)

 Thanks Christopher, for getting me to think outside the box :)

I just think inside a different box.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk7ZQO0ACgkQ9CaO5/Lv0PDDgQCdEkkWqfO7QC/zGxeV644EjE3U
iGoAn3XtoIX93+3+uoCs97mP08MhBtQ3
=L1fD
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Casting a Connection as an OracleConnection in Tomcat 7

2011-11-29 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Jason,

On 11/29/11 2:34 PM, Jason Perrone wrote:
 Has anyone yet figured out how to cast the PoolableConnection that 
 Tomcat 7 now returns when you get a Connection from a DataSource
 as an OracleConnection?

If you are using the standard pool (which uses DBCP under the hood), I
think you get use getInnermostDelegate after casting to
DelegatingConnection. That thing that gets returned should be an
OracleConnection.

You also might need to set accessToUnderlyingConnectionAllowed on the
DataSource in order to actually call getInnermostDelegate. See the
DBCP configuration page and look for that setting for more info.

As always, remember to close the connection you got from the
DataSource, not the inner delegate, or you will be toast.

 In Tomcat 6 the connection was returned as T4CConnection and had no
 problem being cast as an OracleConnection. Now, I just can't figure
 it out. Tried using the Commons DBCP package to get native JDBC
 connections, and every other thing I found by Googling it.

What did you actually try? What is the runtime type of the Connection
object returned from DataSource.getConnection? For me, it's
BasicDataSource.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk7VV8wACgkQ9CaO5/Lv0PDTOgCgqC3q35DFDoGaCGsdWwnRfN48
k5gAn3J+wzFTrzN3kmrsLWDAnLxHNxBo
=ro6R
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



RE: Casting a Connection as an OracleConnection in Tomcat 7

2011-11-29 Thread Jason Perrone
I did try getInnermostDelegate after casting to DelegatingConnection, but I did 
not set accessToUnderlyingConnectionAllowed. I will try that tomorrow. Thanks.


-Original Message-
From: Christopher Schultz [mailto:ch...@christopherschultz.net] 
Sent: Tuesday, November 29, 2011 5:08 PM
To: Tomcat Users List
Subject: Re: Casting a Connection as an OracleConnection in Tomcat 7

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Jason,

On 11/29/11 2:34 PM, Jason Perrone wrote:
 Has anyone yet figured out how to cast the PoolableConnection that 
 Tomcat 7 now returns when you get a Connection from a DataSource as an 
 OracleConnection?

If you are using the standard pool (which uses DBCP under the hood), I think 
you get use getInnermostDelegate after casting to DelegatingConnection. That 
thing that gets returned should be an OracleConnection.

You also might need to set accessToUnderlyingConnectionAllowed on the 
DataSource in order to actually call getInnermostDelegate. See the DBCP 
configuration page and look for that setting for more info.

As always, remember to close the connection you got from the DataSource, not 
the inner delegate, or you will be toast.

 In Tomcat 6 the connection was returned as T4CConnection and had no 
 problem being cast as an OracleConnection. Now, I just can't figure it 
 out. Tried using the Commons DBCP package to get native JDBC 
 connections, and every other thing I found by Googling it.

What did you actually try? What is the runtime type of the Connection object 
returned from DataSource.getConnection? For me, it's BasicDataSource.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk7VV8wACgkQ9CaO5/Lv0PDTOgCgqC3q35DFDoGaCGsdWwnRfN48
k5gAn3J+wzFTrzN3kmrsLWDAnLxHNxBo
=ro6R
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org