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 db5f529..3bdb37e 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 @@ -151,15 +151,12 @@ final class PooledConnection extends ConnectionDelegator { this.originalSchema = pool.schema(); this.originalCatalog = pool.catalog(); if (originalSchema != null) { - schemaState = SCHEMA_CATALOG_KNOWN; + this.schemaState = SCHEMA_CATALOG_KNOWN; this.cacheKeySchema = originalSchema; - // if schema & catalog is defined, we can be sure, that connection is initialized properly - assert originalSchema.equals(connection.getSchema()) : "Connection is in the wrong schema: " + connection.getSchema() + ", expected: " + originalSchema; } if (originalCatalog != null) { - catalogState = SCHEMA_CATALOG_KNOWN; + this.catalogState = SCHEMA_CATALOG_KNOWN; this.cacheKeyCatalog = originalCatalog; - assert originalCatalog.equals(connection.getCatalog()) : "Connection is in the wrong catalog: " + connection.getCatalog() + ", expected: " + originalCatalog; } this.pstmtCache = new PstmtCache(pool.pstmtCacheSize()); this.maxStackTrace = pool.maxStackTraceSize(); @@ -461,6 +458,12 @@ public void close() throws SQLException { resetIsolationReadOnlyRequired = false; } + if (catalogState == SCHEMA_CATALOG_CHANGED) { + connection.setCatalog(originalCatalog); + cacheKeyCatalog = originalCatalog; + catalogState = SCHEMA_CATALOG_KNOWN; + } + if (schemaState == SCHEMA_CATALOG_CHANGED) { connection.setSchema(originalSchema); // we can use original value for cache computation from now on @@ -468,12 +471,6 @@ public void close() throws SQLException { schemaState = SCHEMA_CATALOG_KNOWN; } - if (catalogState == SCHEMA_CATALOG_CHANGED) { - connection.setCatalog(originalCatalog); - cacheKeyCatalog = originalCatalog; - catalogState = SCHEMA_CATALOG_KNOWN; - } - // the connection is assumed GOOD so put it back in the pool lastUseTime = System.currentTimeMillis(); connection.clearWarnings();