swaldman / c3p0

a mature, highly concurrent JDBC Connection pooling library, with support for caching and reuse of PreparedStatements.
http://www.mchange.com/projects/c3p0
Other
1.3k stars 339 forks source link

Make isWrapperFor() and unwrap() behavior more consistent so log4jdbc works #134

Closed bickelj closed 9 months ago

bickelj commented 5 years ago

Copying from an offhand comment in another issue:

I think there is an issue around https://github.com/swaldman/c3p0/blob/c3p0-0.9.5.3/src/java/com/mchange/v2/c3p0/codegen/JdbcProxyGenerator.java#L1142 and https://github.com/swaldman/c3p0/blob/c3p0-0.9.5.3/src/java/com/mchange/v2/c3p0/codegen/JdbcProxyGenerator.java#L1143 regarding the contract of isWrapperFor and unwrap.

The isWrapperFor method generated should follow the guidelines at https://docs.oracle.com/en/java/javase/11/docs/api/java.sql/java/sql/Wrapper.html#isWrapperFor(java.lang.Class) by calling isWrapperFor on the inner object. The c3p0 method unwrap also seems to call isWrapperFor around https://github.com/swaldman/c3p0/blob/c3p0-0.9.5.3/src/java/com/mchange/v2/c3p0/codegen/JdbcProxyGenerator.java#L1158 which is why unwrap might not work in some cases.

The case I ran into was trying to run log4jdbc under c3p0 and the pg jdbc driver under that, and isWrapperFor returned false. Not sure if this is exactly the same cause of your issue, but might be worth trying out.

bickelj commented 9 months ago

:tada: