You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2026/04/18 12:21:58 UTC
(groovy) 02/03: GROOVY-10547: Sql.java namedParamSqlCache map is getting populated despite the cacheNamedQueries flag
This is an automated email from the ASF dual-hosted git repository.
paulk-asert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 2c23aefec9854dfc40df40dadee3900c1368cd6b
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sat Apr 18 22:14:54 2026 +1000
GROOVY-10547: Sql.java namedParamSqlCache map is getting populated despite the cacheNamedQueries flag
---
.../groovy-sql/src/main/java/groovy/sql/Sql.java | 6 ++++--
.../src/test/groovy/groovy/sql/SqlCacheTest.groovy | 17 +++++++++++++++++
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java b/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
index 7c92078bdf..4866b94b93 100644
--- a/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
+++ b/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
@@ -4672,8 +4672,10 @@ public class Sql implements AutoCloseable {
ExtractIndexAndSql extractIndexAndSql = ExtractIndexAndSql.from(sql);
newSql = extractIndexAndSql.getNewSql();
propList = extractIndexAndSql.getIndexPropList();
- namedParamSqlCache.put(sql, newSql);
- namedParamIndexPropCache.put(sql, propList);
+ if (cacheNamedQueries) {
+ namedParamSqlCache.put(sql, newSql);
+ namedParamIndexPropCache.put(sql, propList);
+ }
}
if (sql.equals(newSql)) {
diff --git a/subprojects/groovy-sql/src/test/groovy/groovy/sql/SqlCacheTest.groovy b/subprojects/groovy-sql/src/test/groovy/groovy/sql/SqlCacheTest.groovy
index 77762a3f34..6b31f3d946 100644
--- a/subprojects/groovy-sql/src/test/groovy/groovy/sql/SqlCacheTest.groovy
+++ b/subprojects/groovy-sql/src/test/groovy/groovy/sql/SqlCacheTest.groovy
@@ -274,4 +274,21 @@ class SqlCacheTest extends GroovyTestCase {
}
}
+ // GROOVY-10547
+ void testNamedQueryCacheRespectsFlag() {
+ def namedCache = Sql.class.getDeclaredField('namedParamSqlCache')
+ namedCache.accessible = true
+ def indexCache = Sql.class.getDeclaredField('namedParamIndexPropCache')
+ indexCache.accessible = true
+
+ sql.cacheNamedQueries = false
+ sql.firstRow('SELECT * FROM PERSON WHERE firstname=:name', [name: 'James'])
+ assert namedCache.get(sql).isEmpty()
+ assert indexCache.get(sql).isEmpty()
+
+ sql.cacheNamedQueries = true
+ sql.firstRow('SELECT * FROM PERSON WHERE firstname=:name', [name: 'James'])
+ assert namedCache.get(sql).size() == 1
+ assert indexCache.get(sql).size() == 1
+ }
}