Skip to content

Commit

Permalink
For PooledConnection.resetForUse() remove the asserts
Browse files Browse the repository at this point in the history
The resetForUse() is called "on borrow" just before the connection
is returned to the application. As such we can't do anything that
could throw any Exception here. All connection reset actions must
be performed when the connection is returned to the pool.
  • Loading branch information
rbygrave committed Nov 5, 2024
1 parent b053076 commit 6e5d442
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -385,21 +385,12 @@ public PreparedStatement prepareStatement(String sql, int resultSetType, int res
* Reset the connection for returning to the client. Resets the status,
* startUseTime and hadErrors.
*/
void resetForUse() throws SQLException {
void resetForUse() {
this.status = STATUS_ACTIVE;
this.startUseTime = System.currentTimeMillis();
this.createdByMethod = null;
this.lastStatement = null;
this.hadErrors = false;
// CHECKME: Shoud we keep the asserts here or should we even reset schema/catalog here
assert schemaState != SCHEMA_CATALOG_CHANGED : "connection is in the wrong state (not properly closed)";
if (schemaState == SCHEMA_CATALOG_KNOWN) {
assert originalSchema.equals(getSchema()) : "connection is in the wrong schema: " + getSchema() + ", expected: " + originalSchema;
}
assert catalogState != SCHEMA_CATALOG_CHANGED : "connection is in the wrong state (not properly closed)";
if (catalogState == SCHEMA_CATALOG_KNOWN) {
assert originalCatalog.equals(getCatalog()) : "connection is in the wrong catalog: " + getCatalog() + ", expected: " + originalCatalog;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void test_with_clientInfo() throws SQLException {
void test_with_applicationNameAndSchema() throws SQLException {
DataSourceConfig ds = new DataSourceConfig();
ds.setUrl("jdbc:postgresql://127.0.0.1:9999/app");
ds.setSchema("fred");
ds.setSchema("public");
ds.setUsername("db_owner");
ds.setPassword("test");
ds.setApplicationName("my-application-name");
Expand Down Expand Up @@ -112,7 +112,7 @@ void test_with_applicationNameAndSchema() throws SQLException {
void test_password2() throws SQLException {
DataSourceConfig ds = new DataSourceConfig();
ds.setUrl("jdbc:postgresql://127.0.0.1:9999/app");
ds.setSchema("fred");
ds.setSchema("public");
ds.setUsername("db_owner");
ds.setPassword("test");
ds.setPassword2("newRolledPassword");
Expand Down

0 comments on commit 6e5d442

Please sign in to comment.