Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can ConnectionProxy's Connection delegate be public? #85

Closed
nonameplum opened this issue May 21, 2014 · 1 comment
Closed

Can ConnectionProxy's Connection delegate be public? #85

nonameplum opened this issue May 21, 2014 · 1 comment

Comments

@nonameplum
Copy link

Hi,

I started to use play-hikaricp with pgjdbc-ng and I'm using in my code database notifications using method addNotificationListener from PGConnection class.

In BoneCP I have access to PGConnection from pool using code like this:

ConnectionHandle con = (ConnectionHandle) DB.getConnection();
listeningConnection = (PGConnection) con.getInternalConnection();
listeningConnection.addNotificationListener(notificationListener);
listeningConnection.createStatement().execute("LISTEN watchers");

But Hikari does not allow me to get PGConnection from delegate member - ConnectionHandle class.

Example:

ConnectionProxy connection = (ConnectionProxy) DB.getConnection();
/// proposal getter getDelegate() - delegate member containing PGConnection is not available (protected)
listeningConnection = (PGConnection) connection.getDelegate(); 
listeningConnection.addNotificationListener(notificationListener);
listeningConnection.createStatement().execute("LISTEN watchers");
@brettwooldridge
Copy link
Owner

The proper way to do this is using the JDBC unwrap() API. And you don't need unnecessary casts to ConnectionProxy either.

Connection connection = DB.getConnection();
listeningConnection = connection.unwrap(PGConnection.class); 
listeningConnection.addNotificationListener(notificationListener);
listeningConnection.createStatement().execute("LISTEN watchers");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants