impossibl / pgjdbc-ng

A new JDBC driver for PostgreSQL aimed at supporting the advanced features of JDBC and Postgres
https://impossibl.github.io/pgjdbc-ng
Other
600 stars 108 forks source link

ResultSetDelegator for PGStatementDelegator #566

Open BeateSchatzmann opened 2 years ago

BeateSchatzmann commented 2 years ago

I use Apache's connection pool implementation "Apache Commons DBCP" (commons-dbcp2). In their connection pool (SharedPoolDataSource) I have to set a ConnectionPoolDataSource and I want to use com.impossibl.postgres.jdbc.PGConnectionPoolDataSource - because I really like that PGPooledConnection removes connections from the pool after a fatal SQLException. Now I use a lot of code that creates a ResultSet and in the end not only the ResultSet is closed but also the Statement that ResultSet.getStatement() returns and the connection that this statement's method getConnection() returns:

Connection connection = datasource.getConnection(); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(); ... (use the resultSet) resultSet.getStatement().getConnection().close();

Therefore it would be great if you could add a ResultSetDelegator to PGPooledConnection (in addition to PGPooledConnectionDelegator and PGStatementDelegator, PGCallableStatementDelegator, PGPreparedStatementDelegator) and the ResultSetDelegator returns the statement delegator on a call to getStatement() or - as I have seen in the Oracle code - the Statements get a member variable "wrapper" and PGResultSet.getStatement() returns the "wrapper" if it is not null (if it is null the Statement is returned).

davecramer commented 2 years ago

Love it... see https://github.com/pgjdbc/pgjdbc/issues/2316