• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Extending Postgres implementation of Connection, PreparedStatement, ResultSet

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I was wondering if it is possible that the DriverManager can instantiate my implementations of those three classes. Each of those classes would extend the Postgres implementation:

public class MyCoolConnection extends org.postgresql.jdbc4.Jdbc4Connection
{
}

public class MyCoolPreparedStatement extends org.postgresql.jdbc4.Jdbc4PreparedStatement
{
}

public class MyCoolResultSet extends org.postgresql.jdbc4.Jdbc4ResultSet
{
}

So any .getClass().getName() on instances of the above class would return MyCool* and not postgres' implementation Jdbo4*.


Any ideas would be great.

Thanks,Jim
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You didn't say what it actually is that you wish to accomplish, but maybe AOP (using a library like AspectJ) may help?
 
Jim Atharris
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lester Burnham wrote:You didn't say what it actually is that you wish to accomplish, but maybe AOP (using a library like AspectJ) may help?



One *possible* example for MyCoolConnection would have data members that based on a value may let the close() method get called in the base class. The real reason for this question ot the forum is proprietary business related and I cannot get into detail of it.

I would like to avoid AspectJ as that is introducing a COTS to our code base.

Thanks,Jim
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, AspectJ is open source, so the risk (and financial cost) is limited.

But then, the Postgres JDBC driver is open source, too, so you can study -and adapt- it to your heart's content.
 
Jim Atharris
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lester Burnham wrote:Well, AspectJ is open source, so the risk (and financial cost) is limited.

But then, the Postgres JDBC driver is open source, too, so you can study -and adapt- it to your heart's content.



Postgres is just an example. Would also like to do this w/ Oracle's JDBC.

But you're right w/ Postgres and it being opensource. I was just reading the DriverManager class registerDriver() and seeing if I can do the following



But then it comes to the method below and it does not get called. So I'm wondering the semantics of DriverManager.registerDriver()

 
Time flies like an arrow. Fruit flies like a banana. Steve flies like a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic