Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,19 +241,35 @@ protected Connection newConnection() throws RaiseException, SQLException {
}
throw ex;
}
final PGConnection pgConnection;
if ( connection instanceof PGConnection ) {
pgConnection = (PGConnection) connection;
// The physical connection is open now; if any of the post-connect
// setup below fails we must close it, otherwise the server-side backend
// leaks (the caller only sees the exception and never gets a handle to
// close). This mirrors the native adapter discarding a connection that
// could not be fully established.
try {
final PGConnection pgConnection;
if ( connection instanceof PGConnection ) {
pgConnection = (PGConnection) connection;
}
else {
pgConnection = connection.unwrap(PGConnection.class);
}
pgConnection.addDataType("daterange", DateRangeType.class);
pgConnection.addDataType("tsrange", TsRangeType.class);
pgConnection.addDataType("tstzrange", TstzRangeType.class);
pgConnection.addDataType("int4range", Int4RangeType.class);
pgConnection.addDataType("int8range", Int8RangeType.class);
pgConnection.addDataType("numrange", NumRangeType.class);
}
else {
pgConnection = connection.unwrap(PGConnection.class);
catch (SQLException|RuntimeException ex) {
try {
connection.close();
}
catch (SQLException closeError) {
ex.addSuppressed(closeError);
}
throw ex;
}
pgConnection.addDataType("daterange", DateRangeType.class);
pgConnection.addDataType("tsrange", TsRangeType.class);
pgConnection.addDataType("tstzrange", TstzRangeType.class);
pgConnection.addDataType("int4range", Int4RangeType.class);
pgConnection.addDataType("int8range", Int8RangeType.class);
pgConnection.addDataType("numrange", NumRangeType.class);
return connection;
}

Expand Down
Loading