This is an automated email from the ASF dual-hosted git repository. borinquenkid pushed a commit to branch 8.0.x-hibernate7-dev in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit 845862793a2048cbdab9d206266732cfcd90a963 Author: Walter Duque de Estrada <[email protected]> AuthorDate: Fri Mar 6 13:39:09 2026 -0600 hibernate7: cleanup HibernateHqlQuery --- .../orm/hibernate/HibernateGormStaticApi.groovy | 3 +- .../orm/hibernate/query/HibernateHqlQuery.java | 90 +++++++++++----------- .../hibernate/query/HibernateHqlQuerySpec.groovy | 2 +- 3 files changed, 47 insertions(+), 48 deletions(-) diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormStaticApi.groovy b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormStaticApi.groovy index d6cad39943..81fd409907 100644 --- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormStaticApi.groovy +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormStaticApi.groovy @@ -397,7 +397,8 @@ class HibernateGormStaticApi<D> extends GormStaticApi<D> { ctx, args, positionalParams, - getHibernateTemplate() + getHibernateTemplate(), + conversionService ) } diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/query/HibernateHqlQuery.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/query/HibernateHqlQuery.java index 116715fa02..b7120a501f 100644 --- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/query/HibernateHqlQuery.java +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/query/HibernateHqlQuery.java @@ -137,14 +137,15 @@ public class HibernateHqlQuery extends Query { * the prepared {@link HqlQueryContext}, then applies settings and parameters. */ @SuppressWarnings({"unchecked", "rawtypes"}) - public static HibernateHqlQuery createHqlQuery( + private static HibernateHqlQuery create( HibernateDatastore dataStore, SessionFactory sessionFactory, PersistentEntity entity, HqlQueryContext ctx, Map args, Collection positionalParams, - GrailsHibernateTemplate template) { + GrailsHibernateTemplate template, + ConversionService conversionService) { HibernateHqlQuery hqlQuery = template.execute(session -> buildQuery(session, dataStore, sessionFactory, entity, ctx)); var selectQuery = hqlQuery.selectQuery(); @@ -152,7 +153,8 @@ public class HibernateHqlQuery extends Query { template.applySettings(selectQuery); } hqlQuery.populateQuerySettings( - MapUtils.isNotEmpty(args) ? new HashMap<>(args) : Collections.emptyMap()); + MapUtils.isNotEmpty(args) ? new HashMap<>(args) : Collections.emptyMap(), + conversionService); if (MapUtils.isNotEmpty(ctx.namedParams())) { hqlQuery.populateQueryWithNamedArguments(ctx.namedParams()); } else if (CollectionUtils.isNotEmpty(positionalParams)) { @@ -161,6 +163,45 @@ public class HibernateHqlQuery extends Query { return hqlQuery; } + @SuppressWarnings({"unchecked", "rawtypes"}) + public static HibernateHqlQuery createHqlQuery( + HibernateDatastore dataStore, + SessionFactory sessionFactory, + PersistentEntity entity, + HqlQueryContext ctx, + Map args, + Collection positionalParams, + GrailsHibernateTemplate template, + ConversionService conversionService) { + return create(dataStore, sessionFactory, entity, ctx, args, positionalParams, template, conversionService); + } + + /** + * Factory for {@code list(Map params)} — builds HQL with ORDER BY / JOIN FETCH from the params + * map, applies pagination settings, and wraps in a ready-to-execute {@link HibernateHqlQuery}. + */ + @SuppressWarnings({"unchecked", "rawtypes"}) + public static HibernateHqlQuery forList( + HibernateDatastore dataStore, + SessionFactory sessionFactory, + PersistentEntity entity, + Map<?, ?> params, + GrailsHibernateTemplate template, + ConversionService conversionService) { + HqlListQueryBuilder builder = new HqlListQueryBuilder(entity, params); + String hql = builder.buildListHql(); + HqlQueryContext ctx = HqlQueryContext.prepare(hql, false, false, Collections.emptyMap(), entity); + Map<String, Object> mutableParams = params instanceof Map ? new HashMap<>((Map<String, Object>) params) : Collections.emptyMap(); + return create(dataStore, sessionFactory, entity, ctx, mutableParams, Collections.emptyList(), template, conversionService); + } + + /** + * Builds the count HQL string used by {@link PagedResultList} when paging is requested. + */ + public static String buildCountHql(PersistentEntity entity) { + return new HqlListQueryBuilder(entity, Collections.emptyMap()).buildCountHql(); + } + // ─── Query configuration ───────────────────────────────────────────────── public void setFlushMode(FlushMode flushMode) { @@ -193,49 +234,6 @@ public class HibernateHqlQuery extends Query { } } - /** @deprecated Use {@link #populateQuerySettings(Map, ConversionService)} */ - @Deprecated - public void populateQuerySettings(Map<?, ?> args) { - ifPresent(args, HibernateQueryArgument.MAX.value(), v -> delegate.setMaxResults(toInt(v))); - ifPresent(args, HibernateQueryArgument.OFFSET.value(), v -> delegate.setFirstResult(toInt(v))); - ifPresent(args, HibernateQueryArgument.CACHE.value(), v -> delegate.setCacheable(toBool(v))); - ifPresent(args, HibernateQueryArgument.FETCH_SIZE.value(), v -> delegate.setFetchSize(toInt(v))); - ifPresent(args, HibernateQueryArgument.TIMEOUT.value(), v -> delegate.setTimeout(toInt(v))); - ifPresent(args, HibernateQueryArgument.READ_ONLY.value(), v -> delegate.setReadOnly(toBool(v))); - ifPresent(args, HibernateQueryArgument.FLUSH_MODE.value(), v -> delegate.setQueryFlushMode(convertQueryFlushMode(v))); - } - - /** - * Factory for {@code list(Map params)} — builds HQL with ORDER BY / JOIN FETCH from the params - * map, applies pagination settings, and wraps in a ready-to-execute {@link HibernateHqlQuery}. - */ - @SuppressWarnings({"unchecked", "rawtypes"}) - public static HibernateHqlQuery forList( - HibernateDatastore dataStore, - SessionFactory sessionFactory, - PersistentEntity entity, - Map<?, ?> params, - GrailsHibernateTemplate template, - ConversionService conversionService) { - HqlListQueryBuilder builder = new HqlListQueryBuilder(entity, params); - String hql = builder.buildListHql(); - HqlQueryContext ctx = HqlQueryContext.prepare(hql, false, false, Collections.emptyMap(), entity); - HibernateHqlQuery hqlQuery = - template.execute(session -> buildQuery(session, dataStore, sessionFactory, entity, ctx)); - org.hibernate.query.Query<?> q = hqlQuery.selectQuery(); - if (q != null) template.applySettings(q); - Map<String, Object> mutableParams = params instanceof Map ? new HashMap<>((Map<String, Object>) params) : Collections.emptyMap(); - hqlQuery.populateQuerySettings(mutableParams, conversionService); - return hqlQuery; - } - - /** - * Builds the count HQL string used by {@link PagedResultList} when paging is requested. - */ - public static String buildCountHql(PersistentEntity entity) { - return new HqlListQueryBuilder(entity, Collections.emptyMap()).buildCountHql(); - } - public static QueryFlushMode convertQueryFlushMode(Object object) { FlushMode fm = convertFlushMode(object); if (fm == null) return QueryFlushMode.DEFAULT; diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/query/HibernateHqlQuerySpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/query/HibernateHqlQuerySpec.groovy index ab22d31c14..f992d69659 100644 --- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/query/HibernateHqlQuerySpec.groovy +++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/query/HibernateHqlQuerySpec.groovy @@ -23,7 +23,7 @@ class HibernateHqlQuerySpec extends HibernateGormDatastoreSpec { def ctx = HqlQueryContext.prepare(hql, false, isUpdate, namedParams, entity) def session = sessionFactory.currentSession def hqlQuery = HibernateHqlQuery.buildQuery(session, datastore, sessionFactory, entity, ctx) - if (args) hqlQuery.populateQuerySettings(new HashMap(args)) + if (args) hqlQuery.populateQuerySettings(new HashMap(args), mappingContext.conversionService) if (ctx.namedParams()) hqlQuery.populateQueryWithNamedArguments(new HashMap(ctx.namedParams())) else if (positionalParams) hqlQuery.populateQueryWithIndexedArguments(positionalParams) hqlQuery
