From 6e5d4427aa2336e3517d9a83d2440cc85ab5b3da Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Wed, 6 Nov 2024 07:48:26 +1300 Subject: [PATCH] For PooledConnection.resetForUse() remove the asserts 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. --- .../io/ebean/datasource/pool/PooledConnection.java | 11 +---------- .../io/ebean/datasource/test/PostgresInitTest.java | 4 ++-- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/ebean-datasource/src/main/java/io/ebean/datasource/pool/PooledConnection.java b/ebean-datasource/src/main/java/io/ebean/datasource/pool/PooledConnection.java index 6adcd6a..db5f529 100644 --- a/ebean-datasource/src/main/java/io/ebean/datasource/pool/PooledConnection.java +++ b/ebean-datasource/src/main/java/io/ebean/datasource/pool/PooledConnection.java @@ -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; - } } /** diff --git a/ebean-datasource/src/test/java/io/ebean/datasource/test/PostgresInitTest.java b/ebean-datasource/src/test/java/io/ebean/datasource/test/PostgresInitTest.java index d8a8f16..e330b22 100644 --- a/ebean-datasource/src/test/java/io/ebean/datasource/test/PostgresInitTest.java +++ b/ebean-datasource/src/test/java/io/ebean/datasource/test/PostgresInitTest.java @@ -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"); @@ -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");