Copilot commented on code in PR #16572:
URL: https://github.com/apache/grails-core/pull/16572#discussion_r4238302016
##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/query/HibernateAlias.groovy:
##########
@@ -16,21 +16,21 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.grails.orm.hibernate.query;
+package org.grails.orm.hibernate.query
-import jakarta.persistence.criteria.JoinType;
+import groovy.transform.CompileStatic
+import jakarta.persistence.criteria.JoinType
-import org.grails.datastore.mapping.query.Query;
+import org.grails.datastore.mapping.query.Query
/**
* A internal criterion used to represent an alias for a basic collection join.
*
* @author walterduquedeestrada
*/
-public record HibernateAlias(String path, String alias, JoinType joinType)
+@CompileStatic
+@SuppressWarnings(['ClassStartsWithBlankLine', 'Indentation'])
+record HibernateAlias(String path, String alias, JoinType joinType)
implements Query.Criterion, Query.QueryElement {
- public HibernateAlias(String path, String alias) {
- this(path, alias, JoinType.INNER);
- }
}
Review Comment:
The two-argument constructor was dropped during the record conversion.
Existing callers in `HibernateQuerySpec` and `PredicateGeneratorSpec` still
instantiate `new HibernateAlias(path, alias)`, so those paths now fail at
runtime instead of defaulting to `JoinType.INNER`. Restore the overload.
##########
grails-data-hibernate7/core/src/main/groovy/grails/orm/HibernateCriteriaBuilder.groovy:
##########
@@ -125,133 +118,136 @@
* @see grails.gorm.DetachedCriteria
*/
@Slf4j
-@SuppressWarnings("PMD.AvoidDuplicateLiterals")
-public class HibernateCriteriaBuilder extends GroovyObjectSupport implements
BuildableCriteria, ProjectionList {
- private final SessionFactory sessionFactory;
- private final boolean participate;
- private final org.hibernate.query.criteria.HibernateCriteriaBuilder cb;
- private final HibernateQuery hibernateQuery;
- private Class<?> targetClass;
- private CriteriaQuery<?> criteriaQuery;
- private boolean uniqueResult = false;
-
- @SuppressWarnings("PMD.AvoidFieldNameMatchingMethodName")
- private boolean scroll;
-
- @SuppressWarnings("PMD.AvoidFieldNameMatchingMethodName")
- private boolean count;
-
- private boolean paginationEnabledList = false;
- private int defaultFlushMode;
-
- @SuppressWarnings("PMD.AvoidFieldNameMatchingMethodName")
- private boolean distinct = false;
- private CriteriaMethodInvoker criteriaMethodInvoker;
-
- @SuppressWarnings({"rawtypes", "PMD.CloseResource"})
- public HibernateCriteriaBuilder(Class targetClass, SessionFactory
sessionFactory, HibernateDatastore datastore) {
- this.targetClass = targetClass;
- setDatastore(datastore);
- this.sessionFactory = sessionFactory;
- this.cb = sessionFactory.getCriteriaBuilder();
+@SuppressWarnings('PMD.AvoidDuplicateLiterals')
+@CompileStatic
+class HibernateCriteriaBuilder extends GroovyObjectSupport implements
BuildableCriteria, ProjectionList {
+
+ private final SessionFactory sessionFactory
+ private final boolean participate
+ private final org.hibernate.query.criteria.HibernateCriteriaBuilder cb
+ private final HibernateQuery hibernateQuery
+ private Class<?> targetClass
+ private CriteriaQuery<?> criteriaQuery
+ private boolean uniqueResult = false
+
+ @SuppressWarnings('PMD.AvoidFieldNameMatchingMethodName')
+ private boolean scroll
+
+ @SuppressWarnings('PMD.AvoidFieldNameMatchingMethodName')
+ private boolean count
+
+ private boolean paginationEnabledList = false
+ private int defaultFlushMode
+
+ @SuppressWarnings('PMD.AvoidFieldNameMatchingMethodName')
+ private boolean distinct = false
+ private CriteriaMethodInvoker criteriaMethodInvoker
+
+ @SuppressWarnings(['rawtypes', 'PMD.CloseResource'])
+ HibernateCriteriaBuilder(Class targetClass, SessionFactory sessionFactory,
HibernateDatastore datastore) {
+ this.targetClass = targetClass
+ setDatastore(datastore)
+ this.sessionFactory = sessionFactory
+ this.cb = sessionFactory.getCriteriaBuilder()
if (TransactionSynchronizationManager.hasResource(sessionFactory)) {
- this.participate = true;
- } else {
- this.participate = false;
- org.hibernate.Session session = sessionFactory.openSession();
- TransactionSynchronizationManager.bindResource(sessionFactory, new
SessionHolder(session));
+ this.participate = true
}
- HibernateSession session = (HibernateSession) datastore.connect();
+ else {
+ this.participate = false
+ org.hibernate.Session session = sessionFactory.openSession()
+ TransactionSynchronizationManager.bindResource(sessionFactory, new
SessionHolder(session))
+ }
+ HibernateSession session = (HibernateSession) datastore.connect()
hibernateQuery = new HibernateQuery(
- session, (GrailsHibernatePersistentEntity)
datastore.getMappingContext().getPersistentEntity(targetClass.getName()));
- setDefaultFlushMode(GrailsHibernateTemplate.FLUSH_AUTO);
- criteriaMethodInvoker = new CriteriaMethodInvoker(this);
+ session, (GrailsHibernatePersistentEntity)
datastore.getMappingContext().getPersistentEntity(targetClass.getName()))
+ setDefaultFlushMode(GrailsHibernateTemplate.FLUSH_AUTO)
+ criteriaMethodInvoker = new CriteriaMethodInvoker(this)
}
- public static final String ALIAS_SEPARATOR = ":";
+ public static final String ALIAS_SEPARATOR = ':'
// The types a sqlProjection or sqlGroupProjection takes in the criteria
DSL, as on Hibernate 5
- public static final BasicTypeReference<?> BOOLEAN =
StandardBasicTypes.BOOLEAN;
- public static final BasicTypeReference<?> YES_NO =
StandardBasicTypes.YES_NO;
- public static final BasicTypeReference<?> BYTE = StandardBasicTypes.BYTE;
- public static final BasicTypeReference<?> CHARACTER =
StandardBasicTypes.CHARACTER;
- public static final BasicTypeReference<?> SHORT = StandardBasicTypes.SHORT;
- public static final BasicTypeReference<?> INTEGER =
StandardBasicTypes.INTEGER;
- public static final BasicTypeReference<?> LONG = StandardBasicTypes.LONG;
- public static final BasicTypeReference<?> FLOAT = StandardBasicTypes.FLOAT;
- public static final BasicTypeReference<?> DOUBLE =
StandardBasicTypes.DOUBLE;
- public static final BasicTypeReference<?> BIG_DECIMAL =
StandardBasicTypes.BIG_DECIMAL;
- public static final BasicTypeReference<?> BIG_INTEGER =
StandardBasicTypes.BIG_INTEGER;
- public static final BasicTypeReference<?> STRING =
StandardBasicTypes.STRING;
- public static final BasicTypeReference<?> NUMERIC_BOOLEAN =
StandardBasicTypes.NUMERIC_BOOLEAN;
- public static final BasicTypeReference<?> TRUE_FALSE =
StandardBasicTypes.TRUE_FALSE;
- public static final BasicTypeReference<?> URL = StandardBasicTypes.URL;
- public static final BasicTypeReference<?> TIME = StandardBasicTypes.TIME;
- public static final BasicTypeReference<?> DATE = StandardBasicTypes.DATE;
- public static final BasicTypeReference<?> TIMESTAMP =
StandardBasicTypes.TIMESTAMP;
- public static final BasicTypeReference<?> CALENDAR =
StandardBasicTypes.CALENDAR;
- public static final BasicTypeReference<?> CALENDAR_DATE =
StandardBasicTypes.CALENDAR_DATE;
- public static final BasicTypeReference<?> CLASS = StandardBasicTypes.CLASS;
- public static final BasicTypeReference<?> LOCALE =
StandardBasicTypes.LOCALE;
- public static final BasicTypeReference<?> CURRENCY =
StandardBasicTypes.CURRENCY;
- public static final BasicTypeReference<?> TIMEZONE =
StandardBasicTypes.TIMEZONE;
- public static final BasicTypeReference<?> UUID_BINARY =
StandardBasicTypes.UUID_BINARY;
- public static final BasicTypeReference<?> UUID_CHAR =
StandardBasicTypes.UUID_CHAR;
- public static final BasicTypeReference<?> BINARY =
StandardBasicTypes.BINARY;
- public static final BasicTypeReference<?> WRAPPER_BINARY =
StandardBasicTypes.BINARY_WRAPPER;
- public static final BasicTypeReference<?> IMAGE = StandardBasicTypes.IMAGE;
- public static final BasicTypeReference<?> BLOB = StandardBasicTypes.BLOB;
- public static final BasicTypeReference<?> MATERIALIZED_BLOB =
StandardBasicTypes.MATERIALIZED_BLOB;
- public static final BasicTypeReference<?> CHAR_ARRAY =
StandardBasicTypes.CHAR_ARRAY;
- public static final BasicTypeReference<?> CHARACTER_ARRAY =
StandardBasicTypes.CHARACTER_ARRAY;
- public static final BasicTypeReference<?> TEXT = StandardBasicTypes.TEXT;
- public static final BasicTypeReference<?> CLOB = StandardBasicTypes.CLOB;
- public static final BasicTypeReference<?> MATERIALIZED_CLOB =
StandardBasicTypes.MATERIALIZED_CLOB;
- public static final BasicTypeReference<?> SERIALIZABLE =
StandardBasicTypes.SERIALIZABLE;
+ static final BasicTypeReference<?> BOOLEAN = StandardBasicTypes.BOOLEAN
+ static final BasicTypeReference<?> YES_NO = StandardBasicTypes.YES_NO
+ static final BasicTypeReference<?> BYTE = StandardBasicTypes.BYTE
+ static final BasicTypeReference<?> CHARACTER = StandardBasicTypes.CHARACTER
+ static final BasicTypeReference<?> SHORT = StandardBasicTypes.SHORT
Review Comment:
The Java version exposed all SQL projection type constants as `public static
final` fields, but the conversion removed `public`. That turns them into Groovy
properties and breaks Java source/binary access such as
`HibernateCriteriaBuilder.BOOLEAN`. Restore public field visibility for this
entire constant block.
##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/util/BackticksRemover.groovy:
##########
@@ -28,16 +29,21 @@
*
* @since 8.0
*/
-public class BackticksRemover implements Function<String, String> {
+@CompileStatic
+class BackticksRemover implements Function<String, String> {
- public static final String BACKTICK = "`";
+ static final String BACKTICK = '`'
Review Comment:
This constant was public in the Java source. The conversion now exposes only
Groovy property access rather than the original Java field, breaking Java
callers of `BackticksRemover.BACKTICK`; keep it explicitly public.
##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/IdentityEnumType.groovy:
##########
@@ -0,0 +1,240 @@
+/*
+ * 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
+
+import groovy.transform.CompileStatic
+import org.hibernate.HibernateException
+import org.hibernate.MappingException
+import org.hibernate.engine.spi.SharedSessionContractImplementor
+import org.hibernate.type.descriptor.WrapperOptions
+import org.hibernate.type.descriptor.java.JavaType
+import org.hibernate.type.descriptor.jdbc.BigIntJdbcType
+import org.hibernate.type.descriptor.jdbc.IntegerJdbcType
+import org.hibernate.type.descriptor.jdbc.JdbcType
+import org.hibernate.type.descriptor.jdbc.VarcharJdbcType
+import org.hibernate.type.spi.TypeConfiguration
+import org.hibernate.usertype.ParameterizedType
+import org.hibernate.usertype.UserType
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+import java.lang.reflect.InvocationTargetException
+import java.lang.reflect.Method
+import java.sql.PreparedStatement
+import java.sql.ResultSet
+import java.sql.SQLException
+import java.sql.Types
+
+/**
+ * Hibernate 7 UserType to map Enums to their "id" value.
+ */
+@CompileStatic
+class IdentityEnumType implements UserType<Object>, ParameterizedType,
Serializable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(IdentityEnumType)
+ private static final TypeConfiguration typeConfiguration = new
TypeConfiguration()
+
+ static final String ENUM_ID_ACCESSOR = 'getId'
+ static final String PARAM_ENUM_CLASS = 'enumClass'
Review Comment:
Both constants were public static fields in the Java class. Dropping
`public` changes their Java-facing ABI to Groovy properties, so custom type
integrations cannot continue referencing `IdentityEnumType.ENUM_ID_ACCESSOR` or
`PARAM_ENUM_CLASS`. Preserve the field visibility.
##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/support/ClosureEventTriggeringInterceptor.groovy:
##########
@@ -103,97 +99,96 @@ public class ClosureEventTriggeringInterceptor
* @deprecated Use {@link AbstractPersistenceEvent#ONLOAD_EVENT} instead
*/
@Deprecated
- public static final String ONLOAD_EVENT =
AbstractPersistenceEvent.ONLOAD_EVENT;
+ static final String ONLOAD_EVENT = AbstractPersistenceEvent.ONLOAD_EVENT
Review Comment:
These deprecated event constants were public static fields before the
conversion. Removing `public` makes them Groovy properties and breaks Java
compatibility before their declared removal; restore public visibility for all
ten constants in this block.
##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernateUtil.groovy:
##########
@@ -0,0 +1,316 @@
+/*
+ * 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
+
+import groovy.transform.CompileStatic
+import org.hibernate.FlushMode
+import org.hibernate.Hibernate
+import org.hibernate.Session
+import org.hibernate.SessionFactory
+import org.hibernate.engine.spi.EntityEntry
+import org.hibernate.engine.spi.SessionImplementor
+import org.hibernate.engine.spi.Status
+import org.hibernate.internal.util.StringHelper
+import org.hibernate.proxy.HibernateProxy
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+import
org.springframework.transaction.support.TransactionSynchronizationManager
+
+import grails.gorm.annotation.Entity
+import org.grails.datastore.gorm.GormEntity
+import org.grails.datastore.mapping.model.PersistentEntity
+import org.grails.datastore.mapping.model.config.GormProperties
+import
org.grails.orm.hibernate.cfg.domainbinding.hibernate.GrailsHibernatePersistentEntity
+import org.grails.orm.hibernate.proxy.HibernateProxyHandler
+import org.grails.orm.hibernate.query.HibernateQueryArgument
+import org.grails.orm.hibernate.support.HibernateRuntimeUtils
+
+import java.lang.annotation.Annotation
+
+/**
+ * Utility methods for configuring Hibernate inside Grails.
+ *
+ * @author Graeme Rocher
+ * @since 0.4
+ */
+@CompileStatic
+class GrailsHibernateUtil extends HibernateRuntimeUtils {
+
+ /** @deprecated Use {@link
org.grails.orm.hibernate.query.HibernateQueryArgument#FETCH_SIZE} */
+ @Deprecated(since = '8.0', forRemoval = true)
+ static final String ARGUMENT_FETCH_SIZE =
HibernateQueryArgument.FETCH_SIZE.value()
Review Comment:
These deprecated constants were public fields before the conversion. In
Groovy, omitting `public` declares properties rather than preserving the public
static fields, so Java consumers can no longer compile against
`GrailsHibernateUtil.ARGUMENT_*`; deprecation promises they remain available
until removal. Restore `public` on every converted constant in this block.
##########
grails-data-hibernate7/spring-orm/src/main/groovy/org/grails/orm/hibernate/support/hibernate7/HibernateOperations.groovy:
##########
@@ -80,9 +75,7 @@ public interface HibernateOperations {
* @see HibernateTransactionManager
* @see org.hibernate.Session
*/
- @Nullable
- <T> T execute(HibernateCallback<T> action) throws DataAccessException;
-
+ def <T> T execute(HibernateCallback<T> action) throws DataAccessException
Review Comment:
`HibernateOperations.execute` previously declared a nullable result,
matching its documentation and callback contract. Removing `@Nullable` changes
the public interface consumed by Java/Kotlin callers; restore the return
annotation here (and on the other nullable operations converted in this
interface).
##########
grails-data-hibernate7/spring-orm/src/main/groovy/org/grails/orm/hibernate/support/hibernate7/HibernateCallback.groovy:
##########
@@ -48,7 +46,6 @@ public interface HibernateCallback<T> {
* @throws HibernateException if thrown by the Hibernate API
* @see HibernateTemplate#execute
*/
- @Nullable
- T doInHibernate(Session session) throws HibernateException;
+ T doInHibernate(Session session) throws HibernateException
Review Comment:
This callback explicitly allowed a null result before the conversion, but
the `@Nullable` return annotation was removed. Since this is a public
functional interface, that changes the nullness contract seen by Java/Kotlin
callers and static-analysis tools even though `HibernateTemplate` still
documents and returns null results. Preserve the annotation.
##########
grails-data-hibernate7/spring-orm/src/main/groovy/org/grails/orm/hibernate/support/hibernate7/support/OpenSessionInViewInterceptor.groovy:
##########
@@ -69,111 +67,109 @@
* @see TransactionSynchronizationManager
* @see SessionFactory#getCurrentSession()
*/
-public class OpenSessionInViewInterceptor implements
AsyncWebRequestInterceptor {
+@CompileStatic
+class OpenSessionInViewInterceptor implements AsyncWebRequestInterceptor {
/**
* Suffix that gets appended to the {@code SessionFactory}
* {@code toString()} representation for the "participate in existing
* session handling" request attribute.
* @see #getParticipateAttributeName
*/
- public static final String PARTICIPATE_SUFFIX = ".PARTICIPATE";
+ static final String PARTICIPATE_SUFFIX = '.PARTICIPATE'
Review Comment:
`PARTICIPATE_SUFFIX` was public before this conversion. An unqualified
Groovy property does not preserve the public static field consumed by Java
extensions, so this is an avoidable API break; retain the original visibility.
##########
grails-data-hibernate7/spring-orm/src/main/groovy/org/grails/orm/hibernate/support/hibernate7/SessionFactoryUtils.groovy:
##########
@@ -80,18 +77,20 @@
* @see HibernateExceptionTranslator
* @see HibernateTransactionManager
*/
-public abstract class SessionFactoryUtils {
+@CompileStatic
+abstract class SessionFactoryUtils {
/**
* Order value for TransactionSynchronization objects that clean up
Hibernate Sessions.
* Returns {@code DataSourceUtils.CONNECTION_SYNCHRONIZATION_ORDER - 100}
* to execute Session cleanup before JDBC Connection cleanup, if any.
* @see DataSourceUtils#CONNECTION_SYNCHRONIZATION_ORDER
*/
- public static final int SESSION_SYNCHRONIZATION_ORDER =
- DataSourceUtils.CONNECTION_SYNCHRONIZATION_ORDER - 100;
+ static final int SESSION_SYNCHRONIZATION_ORDER =
+ DataSourceUtils.CONNECTION_SYNCHRONIZATION_ORDER - 100
Review Comment:
This synchronization-order constant was a public static field before
conversion. Without explicit `public`, Java subclasses and integrations can no
longer access `SessionFactoryUtils.SESSION_SYNCHRONIZATION_ORDER`; restore its
original visibility.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]