• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extending Postgres implementation of Connection, PreparedStatement, ResultSet

 
Jim Atharris
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • 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
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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()

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic