This is an automated email from the ASF dual-hosted git repository. borinquenkid pushed a commit to branch 8.0.x-hibernate7 in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit ec99b2cceb6d98bd56690cd91629dbd9ed720d41 Author: Walter Duque de Estrada <[email protected]> AuthorDate: Thu Jun 18 16:57:10 2026 -0500 H7 production source cleanup: VERSION_8_0 constant, setProxyHandler, Groovy port, DetachedCriteria - Remove VERSION_8_0 intermediate constant from GrailsHibernateUtil; inline "8.0" directly in each @Deprecated(since=...) annotation (cleaner without the extra indirection) - Refactor setProxyHandler global-state setter into overloaded methods: unwrapProxy, getAssociationProxy, isInitialized, unwrapIfProxy now each accept an optional HibernateProxyHandler parameter, delegating to DEFAULT_PROXY_HANDLER when omitted. Update GrailsHibernateUtilSpec to pass the mock handler explicitly instead of mutating shared static state. - Convert GeneratorCreationContextWrapper from Java to Groovy: concise single-line delegation methods with Groovy property syntax; getProperty() and getValue() are the only methods with custom logic, all others delegate to the wrapped context - Revert DetachedCriteria.newPagedResultList() extraction: inline new PagedResultList<T>(query) back into list() — the method had no override, no test hook, and added noise Co-Authored-By: Claude Sonnet 4.6 <[email protected]> --- .../orm/hibernate/cfg/GrailsHibernateUtil.java | 59 ++++++++------ .../util/GeneratorCreationContextWrapper.groovy | 60 ++++++++++++++ .../util/GeneratorCreationContextWrapper.java | 93 ---------------------- .../hibernate/cfg/GrailsHibernateUtilSpec.groovy | 17 +--- .../groovy/grails/gorm/DetachedCriteria.groovy | 6 +- 5 files changed, 100 insertions(+), 135 deletions(-) diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernateUtil.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernateUtil.java index 8cebec4148..785f108722 100644 --- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernateUtil.java +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernateUtil.java @@ -56,57 +56,52 @@ import org.grails.orm.hibernate.support.HibernateRuntimeUtils; */ public class GrailsHibernateUtil extends HibernateRuntimeUtils { - private static final String VERSION_8_0 = "8.0"; /** @deprecated Use {@link org.grails.orm.hibernate.query.HibernateQueryArgument#FETCH_SIZE} */ - @Deprecated(since = VERSION_8_0, forRemoval = true) + @Deprecated(since = "8.0", forRemoval = true) public static final String ARGUMENT_FETCH_SIZE = HibernateQueryArgument.FETCH_SIZE.value(); /** @deprecated Use {@link org.grails.orm.hibernate.query.HibernateQueryArgument#TIMEOUT} */ - @Deprecated(since = VERSION_8_0, forRemoval = true) + @Deprecated(since = "8.0", forRemoval = true) public static final String ARGUMENT_TIMEOUT = HibernateQueryArgument.TIMEOUT.value(); /** @deprecated Use {@link org.grails.orm.hibernate.query.HibernateQueryArgument#READ_ONLY} */ - @Deprecated(since = VERSION_8_0, forRemoval = true) + @Deprecated(since = "8.0", forRemoval = true) public static final String ARGUMENT_READ_ONLY = HibernateQueryArgument.READ_ONLY.value(); /** @deprecated Use {@link org.grails.orm.hibernate.query.HibernateQueryArgument#FLUSH_MODE} */ - @Deprecated(since = VERSION_8_0, forRemoval = true) + @Deprecated(since = "8.0", forRemoval = true) public static final String ARGUMENT_FLUSH_MODE = HibernateQueryArgument.FLUSH_MODE.value(); /** @deprecated Use {@link org.grails.orm.hibernate.query.HibernateQueryArgument#MAX} */ - @Deprecated(since = VERSION_8_0, forRemoval = true) + @Deprecated(since = "8.0", forRemoval = true) public static final String ARGUMENT_MAX = HibernateQueryArgument.MAX.value(); /** @deprecated Use {@link org.grails.orm.hibernate.query.HibernateQueryArgument#OFFSET} */ - @Deprecated(since = VERSION_8_0, forRemoval = true) + @Deprecated(since = "8.0", forRemoval = true) public static final String ARGUMENT_OFFSET = HibernateQueryArgument.OFFSET.value(); /** @deprecated Use {@link org.grails.orm.hibernate.query.HibernateQueryArgument#ORDER} */ - @Deprecated(since = VERSION_8_0, forRemoval = true) + @Deprecated(since = "8.0", forRemoval = true) public static final String ARGUMENT_ORDER = HibernateQueryArgument.ORDER.value(); /** @deprecated Use {@link org.grails.orm.hibernate.query.HibernateQueryArgument#SORT} */ - @Deprecated(since = VERSION_8_0, forRemoval = true) + @Deprecated(since = "8.0", forRemoval = true) public static final String ARGUMENT_SORT = HibernateQueryArgument.SORT.value(); /** @deprecated Use {@link org.grails.orm.hibernate.query.HibernateQueryArgument#ORDER_DESC} */ - @Deprecated(since = VERSION_8_0, forRemoval = true) + @Deprecated(since = "8.0", forRemoval = true) public static final String ORDER_DESC = HibernateQueryArgument.ORDER_DESC.value(); /** @deprecated Use {@link org.grails.orm.hibernate.query.HibernateQueryArgument#ORDER_ASC} */ - @Deprecated(since = VERSION_8_0, forRemoval = true) + @Deprecated(since = "8.0", forRemoval = true) public static final String ORDER_ASC = HibernateQueryArgument.ORDER_ASC.value(); /** @deprecated Use {@link org.grails.orm.hibernate.query.HibernateQueryArgument#FETCH} */ - @Deprecated(since = VERSION_8_0, forRemoval = true) + @Deprecated(since = "8.0", forRemoval = true) public static final String ARGUMENT_FETCH = HibernateQueryArgument.FETCH.value(); /** @deprecated Use {@link org.grails.orm.hibernate.query.HibernateQueryArgument#IGNORE_CASE} */ - @Deprecated(since = VERSION_8_0, forRemoval = true) + @Deprecated(since = "8.0", forRemoval = true) public static final String ARGUMENT_IGNORE_CASE = HibernateQueryArgument.IGNORE_CASE.value(); /** @deprecated Use {@link org.grails.orm.hibernate.query.HibernateQueryArgument#CACHE} */ - @Deprecated(since = VERSION_8_0, forRemoval = true) + @Deprecated(since = "8.0", forRemoval = true) public static final String ARGUMENT_CACHE = HibernateQueryArgument.CACHE.value(); /** @deprecated Use {@link org.grails.orm.hibernate.query.HibernateQueryArgument#LOCK} */ - @Deprecated(since = VERSION_8_0, forRemoval = true) + @Deprecated(since = "8.0", forRemoval = true) public static final String ARGUMENT_LOCK = HibernateQueryArgument.LOCK.value(); protected static final Logger LOG = LoggerFactory.getLogger(GrailsHibernateUtil.class); - private static HibernateProxyHandler proxyHandler = new HibernateProxyHandler(); - - public static void setProxyHandler(HibernateProxyHandler handler) { - proxyHandler = handler; - } + private static final HibernateProxyHandler DEFAULT_PROXY_HANDLER = new HibernateProxyHandler(); /** * Sets the target object to read-only using the given SessionFactory instance. This avoids @@ -208,7 +203,11 @@ public class GrailsHibernateUtil extends HibernateRuntimeUtils { * @return the unproxied instance */ public static Object unwrapProxy(HibernateProxy proxy) { - return proxyHandler.unwrap(proxy); + return unwrapProxy(proxy, DEFAULT_PROXY_HANDLER); + } + + public static Object unwrapProxy(HibernateProxy proxy, HibernateProxyHandler handler) { + return handler.unwrap(proxy); } /** @@ -219,7 +218,11 @@ public class GrailsHibernateUtil extends HibernateRuntimeUtils { * @return A proxy */ public static HibernateProxy getAssociationProxy(Object obj, String associationName) { - return proxyHandler.getAssociationProxy(obj, associationName); + return getAssociationProxy(obj, associationName, DEFAULT_PROXY_HANDLER); + } + + public static HibernateProxy getAssociationProxy(Object obj, String associationName, HibernateProxyHandler handler) { + return handler.getAssociationProxy(obj, associationName); } /** @@ -230,7 +233,11 @@ public class GrailsHibernateUtil extends HibernateRuntimeUtils { * @return true if is initialized */ public static boolean isInitialized(Object obj, String associationName) { - return proxyHandler.isInitialized(obj, associationName); + return isInitialized(obj, associationName, DEFAULT_PROXY_HANDLER); + } + + public static boolean isInitialized(Object obj, String associationName, HibernateProxyHandler handler) { + return handler.isInitialized(obj, associationName); } /** @@ -239,7 +246,11 @@ public class GrailsHibernateUtil extends HibernateRuntimeUtils { * as-is. */ public static Object unwrapIfProxy(Object instance) { - return proxyHandler.unwrap(instance); + return unwrapIfProxy(instance, DEFAULT_PROXY_HANDLER); + } + + public static Object unwrapIfProxy(Object instance, HibernateProxyHandler handler) { + return handler.unwrap(instance); } public static boolean isMappedWithHibernate(PersistentEntity domainClass) { diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/util/GeneratorCreationContextWrapper.groovy b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/util/GeneratorCreationContextWrapper.groovy new file mode 100644 index 0000000000..27a6f1e003 --- /dev/null +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/util/GeneratorCreationContextWrapper.groovy @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.grails.orm.hibernate.cfg.domainbinding.util + +import groovy.transform.CompileStatic +import org.hibernate.boot.model.relational.Database +import org.hibernate.boot.model.relational.SqlStringGenerationContext +import org.hibernate.generator.GeneratorCreationContext +import org.hibernate.mapping.PersistentClass +import org.hibernate.mapping.Property +import org.hibernate.mapping.RootClass +import org.hibernate.mapping.Value +import org.hibernate.service.ServiceRegistry +import org.hibernate.type.Type + +/** + * A wrapper for {@link GeneratorCreationContext} that allows overriding the {@link Value}. + */ +@CompileStatic +class GeneratorCreationContextWrapper implements GeneratorCreationContext { + + private final GeneratorCreationContext delegate + private final Value value + + GeneratorCreationContextWrapper(GeneratorCreationContext delegate, Value value) { + this.delegate = delegate + this.value = value + } + + @Override Database getDatabase() { delegate.database } + @Override ServiceRegistry getServiceRegistry() { delegate.serviceRegistry } + @Override String getDefaultCatalog() { delegate.defaultCatalog } + @Override String getDefaultSchema() { delegate.defaultSchema } + @Override PersistentClass getPersistentClass() { delegate.persistentClass } + @Override RootClass getRootClass() { delegate.rootClass } + @Override Property getProperty() { delegate.getProperty() } + @Override Type getType() { delegate.type } + @Override SqlStringGenerationContext getSqlStringGenerationContext() { delegate.sqlStringGenerationContext } + + @Override + Value getValue() { + value != null ? value : delegate.getValue() + } +} diff --git a/grails-data-hibernate7/core/src/main/java/org/grails/orm/hibernate/cfg/domainbinding/util/GeneratorCreationContextWrapper.java b/grails-data-hibernate7/core/src/main/java/org/grails/orm/hibernate/cfg/domainbinding/util/GeneratorCreationContextWrapper.java deleted file mode 100644 index 5186ed1e0d..0000000000 --- a/grails-data-hibernate7/core/src/main/java/org/grails/orm/hibernate/cfg/domainbinding/util/GeneratorCreationContextWrapper.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.grails.orm.hibernate.cfg.domainbinding.util; - -import org.hibernate.boot.model.relational.Database; -import org.hibernate.boot.model.relational.SqlStringGenerationContext; -import org.hibernate.generator.GeneratorCreationContext; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.Property; -import org.hibernate.mapping.RootClass; -import org.hibernate.mapping.Value; -import org.hibernate.service.ServiceRegistry; -import org.hibernate.type.Type; - -/** - * A wrapper for {@link GeneratorCreationContext} that allows overriding the {@link Value}. - */ -public class GeneratorCreationContextWrapper implements GeneratorCreationContext { - - private final GeneratorCreationContext delegate; - private final Value value; - - public GeneratorCreationContextWrapper(GeneratorCreationContext delegate, Value value) { - this.delegate = delegate; - this.value = value; - } - - @Override - public Database getDatabase() { - return delegate.getDatabase(); - } - - @Override - public ServiceRegistry getServiceRegistry() { - return delegate.getServiceRegistry(); - } - - @Override - public String getDefaultCatalog() { - return delegate.getDefaultCatalog(); - } - - @Override - public String getDefaultSchema() { - return delegate.getDefaultSchema(); - } - - @Override - public PersistentClass getPersistentClass() { - return delegate.getPersistentClass(); - } - - @Override - public RootClass getRootClass() { - return delegate.getRootClass(); - } - - @Override - public Property getProperty() { - return delegate.getProperty(); - } - - @Override - public Value getValue() { - return value != null ? value : delegate.getValue(); - } - - @Override - public Type getType() { - return delegate.getType(); - } - - @Override - public SqlStringGenerationContext getSqlStringGenerationContext() { - return delegate.getSqlStringGenerationContext(); - } -} diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/GrailsHibernateUtilSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/GrailsHibernateUtilSpec.groovy index 3892689553..962781c229 100644 --- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/GrailsHibernateUtilSpec.groovy +++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/GrailsHibernateUtilSpec.groovy @@ -28,21 +28,12 @@ import spock.lang.Unroll class GrailsHibernateUtilSpec extends HibernateGormDatastoreSpec { - @Shared HibernateProxyHandler originalProxyHandler = GrailsHibernateUtil.proxyHandler HibernateProxyHandler proxyHandlerMock = Mock(HibernateProxyHandler) void setupSpec() { manager.registerDomainClasses(GHUBook, GHUAuthor, GHUAnnotatedEntity) } - def setup() { - GrailsHibernateUtil.setProxyHandler(proxyHandlerMock) - } - - def cleanup() { - GrailsHibernateUtil.setProxyHandler(originalProxyHandler) - } - @Unroll def "test isDomainClass for #clazz.simpleName"() { expect: @@ -97,7 +88,7 @@ class GrailsHibernateUtilSpec extends HibernateGormDatastoreSpec { def unwrapped = new Object() when: - def result = GrailsHibernateUtil.unwrapIfProxy(obj) + def result = GrailsHibernateUtil.unwrapIfProxy(obj, proxyHandlerMock) then: 1 * proxyHandlerMock.unwrap(obj) >> unwrapped @@ -110,7 +101,7 @@ class GrailsHibernateUtilSpec extends HibernateGormDatastoreSpec { def unwrapped = new Object() when: - def result = GrailsHibernateUtil.unwrapProxy(proxy) + def result = GrailsHibernateUtil.unwrapProxy(proxy, proxyHandlerMock) then: 1 * proxyHandlerMock.unwrap(proxy) >> unwrapped @@ -123,8 +114,8 @@ class GrailsHibernateUtilSpec extends HibernateGormDatastoreSpec { def proxy = Mock(HibernateProxy) when: - def result = GrailsHibernateUtil.getAssociationProxy(book, "title") - def initialized = GrailsHibernateUtil.isInitialized(book, "title") + def result = GrailsHibernateUtil.getAssociationProxy(book, "title", proxyHandlerMock) + def initialized = GrailsHibernateUtil.isInitialized(book, "title", proxyHandlerMock) then: 1 * proxyHandlerMock.getAssociationProxy(book, "title") >> proxy diff --git a/grails-datamapping-core/src/main/groovy/grails/gorm/DetachedCriteria.groovy b/grails-datamapping-core/src/main/groovy/grails/gorm/DetachedCriteria.groovy index 0bf18c2d94..2ee44a19eb 100644 --- a/grails-datamapping-core/src/main/groovy/grails/gorm/DetachedCriteria.groovy +++ b/grails-datamapping-core/src/main/groovy/grails/gorm/DetachedCriteria.groovy @@ -138,16 +138,12 @@ class DetachedCriteria<T> extends AbstractDetachedCriteria<T> implements GormOpe List<T> list(Map args = Collections.emptyMap(), @DelegatesTo(DetachedCriteria) Closure additionalCriteria = null) { (List)withPopulatedQuery(args, additionalCriteria) { Query query -> if (args?.max) { - return newPagedResultList(query) + return new PagedResultList<T>(query) } return query.list() } } - protected PagedResultList<T> newPagedResultList(Query query) { - new PagedResultList<T>(query) - } - /** * Lists all records matching the criterion contained within this DetachedCriteria instance *
