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 117af70c0cfec3f2569a157146ec27c2288f0da3
Author: Walter Duque de Estrada <[email protected]>
AuthorDate: Sat Mar 7 13:36:42 2026 -0600

    hibernate7: more Codenarc
---
 .../orm/hibernate/HibernateGormStaticApi.groovy    | 98 ++++++++++------------
 .../hibernate/HibernateGormValidationApi.groovy    |  4 +-
 2 files changed, 48 insertions(+), 54 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 f4f49f10cb..d6545ee4db 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
@@ -72,7 +72,7 @@ class HibernateGormStaticApi<D> extends GormStaticApi<D> {
         this.conversionService = datastore.mappingContext.conversionService
         this.proxyHandler = datastore.mappingContext.proxyHandler
         this.hibernateSession = new HibernateSession(
-                (HibernateDatastore)datastore,
+                (HibernateDatastore) datastore,
                 hibernateTemplate.getSessionFactory()
         )
         this.classLoader = classLoader
@@ -108,11 +108,11 @@ class HibernateGormStaticApi<D> extends GormStaticApi<D> {
             return null
         }
 
-        if(persistentEntity.isMultiTenant()) {
+        if (persistentEntity.isMultiTenant()) {
             // for multi-tenant entities we process get(..) via a query
-            (D)hibernateTemplate.execute(  { Session session ->
-                return new HibernateQuery(hibernateSession,persistentEntity 
).idEq(id).singleResult()
-            } )
+            (D) hibernateTemplate.execute { Session session ->
+                new HibernateQuery(hibernateSession, 
persistentEntity).idEq(id).singleResult()
+            }
         }
         else {
             // for non multi-tenant entities we process get(..) via the second 
level cache
@@ -130,28 +130,28 @@ class HibernateGormStaticApi<D> extends GormStaticApi<D> {
             return null
         }
 
-        (D)hibernateTemplate.execute(  { Session session ->
+        (D) hibernateTemplate.execute { Session session ->
             CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder()
             CriteriaQuery criteriaQuery = 
criteriaBuilder.createQuery(persistentEntity.javaClass)
 
             Root queryRoot = criteriaQuery.from(persistentEntity.javaClass)
-            criteriaQuery = criteriaQuery.where (
+            criteriaQuery = criteriaQuery.where(
                     //TODO: Remove explicit type cast once GROOVY-9460
-                    criteriaBuilder.equal((Expression<?>)  
queryRoot.get(persistentEntity.identity.name), id)
+                    criteriaBuilder.equal((Expression<?>) 
queryRoot.get(persistentEntity.identity.name), id)
             )
             Query criteria = session.createQuery(criteriaQuery)
                     .setHint(AvailableHints.HINT_READ_ONLY, true)
             HibernateHqlQuery hibernateHqlQuery = new HibernateHqlQuery(
                     hibernateSession, persistentEntity, criteria)
-            return proxyHandler.unwrap( hibernateHqlQuery.singleResult() )
-        } )
+            proxyHandler.unwrap(hibernateHqlQuery.singleResult())
+        }
     }
 
     @Override
     D load(Serializable id) {
         id = convertIdentifier(id)
         if (id != null) {
-            return (D) hibernateTemplate.load((Class)persistentClass, id)
+            return (D) hibernateTemplate.load((Class) persistentClass, id)
         }
         else {
             return null
@@ -164,7 +164,7 @@ class HibernateGormStaticApi<D> extends GormStaticApi<D> {
         if (id != null) {
             // Use the configured MappingContext proxyFactory (e.g. 
GroovyProxyFactory) so proxies are created correctly
             def proxyFactory = datastore.getMappingContext().getProxyFactory()
-            return (D) proxyFactory.createProxy(datastore.currentSession, 
(Class)persistentClass, id)
+            return (D) proxyFactory.createProxy(datastore.currentSession, 
(Class) persistentClass, id)
         }
         else {
             return null
@@ -176,7 +176,6 @@ class HibernateGormStaticApi<D> extends GormStaticApi<D> {
         doListInternal("from ${persistentEntity.name}".toString(), [:], [], 
[:], false)
     }
 
-
     @Override
     Integer count() {
         String entity = persistentEntity.name
@@ -211,12 +210,12 @@ class HibernateGormStaticApi<D> extends GormStaticApi<D> {
 
     @Override
     D find(CharSequence query, Collection positionalParams, Map args) {
-       doSingleInternal(query, [:], positionalParams, args, false)
+        doSingleInternal(query, [:], positionalParams, args, false)
     }
 
     @Override
     List<D> findAll(CharSequence query, Map namedParams, Map args) {
-      doListInternal(query, namedParams, [], args, false)
+        doListInternal(query, namedParams, [], args, false)
     }
 
     D findWithNativeSql(CharSequence sql, Map args = Collections.emptyMap()) {
@@ -241,25 +240,25 @@ class HibernateGormStaticApi<D> extends GormStaticApi<D> {
 
     @Override
     List<D> findAll(CharSequence query) {
-        requireGString(query, "findAll")
+        requireGString(query, 'findAll')
         doListInternal(query, [:], [], [:], false)
     }
 
     @Override
     List executeQuery(CharSequence query) {
-        requireGString(query, "executeQuery")
+        requireGString(query, 'executeQuery')
         doListInternal(query, [:], [], [:], false)
     }
 
     @Override
     Integer executeUpdate(CharSequence query) {
-        requireGString(query, "executeUpdate")
-        doInternalExecuteUpdate(query,[:],[],[:])
+        requireGString(query, 'executeUpdate')
+        doInternalExecuteUpdate(query, [:], [], [:])
     }
 
     @Override
     D find(CharSequence query) {
-        requireGString(query, "find")
+        requireGString(query, 'find')
         doSingleInternal(query, [:], [], [:], false)
     }
 
@@ -289,23 +288,26 @@ class HibernateGormStaticApi<D> extends GormStaticApi<D> {
         doListInternal(query, [:], [], args, false)
     }
 
-
     @Override
     D findWhere(Map queryMap, Map args) {
         if (!queryMap) return null
-        String entity = persistentEntity.name
-        String where = queryMap.keySet().collect { "$it = :$it" }.join(' and ')
-        doSingleInternal("from $entity where $where" as String, queryMap as 
Map, [], args, false)
+        String hql = buildWhereHql(queryMap)
+        doSingleInternal(hql, queryMap, [], args, false)
     }
 
     @Override
     List<D> findAllWhere(Map queryMap, Map args) {
         if (!queryMap) return null
-        String entity = persistentEntity.name
-        String where = queryMap.keySet().collect { "$it = :$it" }.join(' and ')
-        doListInternal("from $entity where $where" as String, queryMap as Map, 
[], args, false)
+        String hql = buildWhereHql(queryMap)
+        doListInternal(hql, queryMap, [], args, false)
     }
 
+    private String buildWhereHql(Map queryMap) {
+        String whereClause = queryMap.keySet().collect { Object key -> "$key = 
:$key" }.join(' and ')
+        return "from ${persistentEntity.name} where $whereClause"
+    }
+
+
     @Override
     List executeQuery(CharSequence query, Map namedParams, Map args) {
         doListInternal(query, namedParams, [], args, false)
@@ -332,14 +334,11 @@ class HibernateGormStaticApi<D> extends GormStaticApi<D> {
         ids.collect { byId[it] }
     }
 
-
     @Override
     List<D> getAll(Serializable... ids) {
         getAllInternal(ids as List)
     }
 
-
-
     private List<D> doListInternal(CharSequence hql,
                                    Map namedParams,
                                    Collection positionalParams,
@@ -367,12 +366,12 @@ class HibernateGormStaticApi<D> extends GormStaticApi<D> {
 
     @Override
     Integer executeUpdate(CharSequence query, Map params, Map args) {
-        doInternalExecuteUpdate(query,params,[],args)
+        doInternalExecuteUpdate(query, params, [], args)
     }
 
     @Override
     Integer executeUpdate(CharSequence query, Collection indexedParams, Map 
args) {
-        doInternalExecuteUpdate(query,[:],indexedParams,args)
+        doInternalExecuteUpdate(query, [:], indexedParams, args)
     }
 
     private Integer doInternalExecuteUpdate(CharSequence hql,
@@ -389,7 +388,7 @@ class HibernateGormStaticApi<D> extends GormStaticApi<D> {
     @SuppressWarnings('GroovyAssignabilityCheck')
     private HibernateHqlQuery prepareHqlQuery(CharSequence hql, boolean 
isNative, boolean isUpdate,
                                               Map namedParams, Collection 
positionalParams, Map querySettings) {
-        def ctx = HqlQueryContext.prepare(persistentEntity, hql, namedParams, 
positionalParams,querySettings, isNative, isUpdate,)
+        def ctx = HqlQueryContext.prepare(persistentEntity, hql, namedParams, 
positionalParams, querySettings, isNative, isUpdate)
         return HibernateHqlQuery.createHqlQuery(
                 (HibernateDatastore) datastore,
                 sessionFactory,
@@ -401,21 +400,21 @@ class HibernateGormStaticApi<D> extends GormStaticApi<D> {
         )
     }
 
-
     protected Serializable convertIdentifier(Serializable id) {
         def identity = persistentEntity.identity
-        if(identity != null) {
+        if (identity != null) {
             ConversionService conversionService = 
persistentEntity.mappingContext.conversionService
-            if(id != null) {
+            if (id != null) {
                 Class identityType = identity.type
                 Class idInstanceType = id.getClass()
-                if(identityType.isAssignableFrom(idInstanceType)) {
+                if (identityType.isAssignableFrom(idInstanceType)) {
                     return id
                 }
-                else if(conversionService.canConvert(idInstanceType, 
identityType)) {
+                else if (conversionService.canConvert(idInstanceType, 
identityType)) {
                     try {
-                        return (Serializable)conversionService.convert(id, 
identityType)
-                    } catch (Throwable ignored) {
+                        return (Serializable) conversionService.convert(id, 
identityType)
+                    }
+                    catch (Throwable ignored) {
                         return null
                     }
                 }
@@ -427,13 +426,12 @@ class HibernateGormStaticApi<D> extends GormStaticApi<D> {
         return id
     }
 
-
     @Override
     List<D> list(Map params = Collections.emptyMap()) {
         firePreQueryEvent()
-        HqlListQueryBuilder builder = new 
HqlListQueryBuilder(persistentEntity, params);
-        String hql = builder.buildListHql();
-        HqlQueryContext ctx = HqlQueryContext.prepare(persistentEntity, hql, 
Collections.emptyMap(), Collections.emptyList(), params , false, false );
+        HqlListQueryBuilder builder = new 
HqlListQueryBuilder(persistentEntity, params)
+        String hql = builder.buildListHql()
+        HqlQueryContext ctx = HqlQueryContext.prepare(persistentEntity, hql, 
Collections.emptyMap(), Collections.emptyList(), params, false, false)
         HibernateHqlQuery hqlQuery = HibernateHqlQuery.createHqlQuery(
                 (HibernateDatastore) datastore,
                 sessionFactory,
@@ -452,7 +450,7 @@ class HibernateGormStaticApi<D> extends GormStaticApi<D> {
 
     @Override
     def propertyMissing(String name) {
-        if(datastore instanceof ConnectionSourcesProvider) {
+        if (datastore instanceof ConnectionSourcesProvider) {
             return GormEnhancer.findStaticApi(persistentClass, name)
         }
         else {
@@ -462,16 +460,15 @@ class HibernateGormStaticApi<D> extends GormStaticApi<D> {
 
     @Override
     GrailsCriteria createCriteria() {
-        def builder = new HibernateCriteriaBuilder(persistentClass, 
sessionFactory,(HibernateDatastore)datastore)
+        def builder = new HibernateCriteriaBuilder(persistentClass, 
sessionFactory, (HibernateDatastore) datastore)
         builder.conversionService = conversionService
         return builder
     }
 
-
     protected void firePostQueryEvent(Object result) {
         def hibernateQuery = new HibernateQuery(new 
HibernateSession((HibernateDatastore) datastore, sessionFactory), 
persistentEntity)
-        def list = result instanceof List ? (List)result :  
Collections.singletonList(result)
-        datastore.applicationEventPublisher.publishEvent( new 
PostQueryEvent(datastore, hibernateQuery, list))
+        def list = result instanceof List ? (List) result : 
Collections.singletonList(result)
+        datastore.applicationEventPublisher.publishEvent(new 
PostQueryEvent(datastore, hibernateQuery, list))
     }
 
     protected void firePreQueryEvent() {
@@ -479,7 +476,4 @@ class HibernateGormStaticApi<D> extends GormStaticApi<D> {
         def hibernateQuery = new HibernateQuery(hibernateSession, 
persistentEntity)
         datastore.applicationEventPublisher.publishEvent(new 
PreQueryEvent(datastore, hibernateQuery))
     }
-
-
-
 }
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormValidationApi.groovy
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormValidationApi.groovy
index 05e652bf1c..2bf204e982 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormValidationApi.groovy
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormValidationApi.groovy
@@ -32,8 +32,8 @@ import org.springframework.validation.Validator
 @CompileStatic
 class HibernateGormValidationApi<D> extends GormValidationApi<D> {
 
-    public static final String ARGUMENT_DEEP_VALIDATE = "deepValidate"
-    private static final String ARGUMENT_EVICT = "evict"
+    public static final String ARGUMENT_DEEP_VALIDATE = 'deepValidate'
+    private static final String ARGUMENT_EVICT = 'evict'
 
     protected ClassLoader classLoader
     protected HibernateDatastore datastore

Reply via email to