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 01e532c2402bc2cf5f96a66137d69c600234645e Author: Walter Duque de Estrada <[email protected]> AuthorDate: Tue Mar 17 21:39:09 2026 -0500 hibernate 7: refactor BindCollectionElementBinder to EnumTypeBinder --- .../hibernate/cfg/domainbinding/binder/EnumTypeBinder.java | 13 +++++++++---- .../cfg/domainbinding/binder/GrailsDomainBinder.java | 2 +- .../secondpass/BasicCollectionElementBinder.java | 9 ++++----- .../secondpass/CollectionWithJoinTableBinder.java | 5 +++-- .../hibernate/cfg/domainbinding/CollectionBinderSpec.groovy | 2 +- .../hibernate/cfg/domainbinding/EnumTypeBinderSpec.groovy | 2 +- .../cfg/domainbinding/GrailsPropertyBinderSpec.groovy | 2 +- .../secondpass/ListSecondPassBinderSpec.groovy | 2 +- .../domainbinding/secondpass/MapSecondPassBinderSpec.groovy | 2 +- .../secondpass/UnidirectionalOneToManyBinderSpec.groovy | 2 +- 10 files changed, 23 insertions(+), 18 deletions(-) diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/EnumTypeBinder.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/EnumTypeBinder.java index c6f4a607e0..8df14461a2 100644 --- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/EnumTypeBinder.java +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/EnumTypeBinder.java @@ -32,7 +32,9 @@ import org.slf4j.LoggerFactory; import org.grails.orm.hibernate.cfg.ColumnConfig; import org.grails.orm.hibernate.cfg.IdentityEnumType; +import org.grails.orm.hibernate.cfg.PersistentEntityNamingStrategy; import org.grails.orm.hibernate.cfg.PropertyConfig; +import org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateBasicProperty; import org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateEnumProperty; import org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernatePersistentProperty; import org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateToManyProperty; @@ -47,26 +49,28 @@ public class EnumTypeBinder { private final ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher; private final IndexBinder indexBinder; private final ColumnConfigToColumnBinder columnConfigToColumnBinder; + private final PersistentEntityNamingStrategy namingStrategy; public EnumTypeBinder( MetadataBuildingContext metadataBuildingContext, - ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher) { + ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher, PersistentEntityNamingStrategy namingStrategy) { this( metadataBuildingContext, columnNameForPropertyAndPathFetcher, new IndexBinder(), - new ColumnConfigToColumnBinder()); + new ColumnConfigToColumnBinder(), namingStrategy); } protected EnumTypeBinder( MetadataBuildingContext metadataBuildingContext, ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher, IndexBinder indexBinder, - ColumnConfigToColumnBinder columnConfigToColumnBinder) { + ColumnConfigToColumnBinder columnConfigToColumnBinder, PersistentEntityNamingStrategy namingStrategy) { this.metadataBuildingContext = metadataBuildingContext; this.columnNameForPropertyAndPathFetcher = columnNameForPropertyAndPathFetcher; this.indexBinder = indexBinder; this.columnConfigToColumnBinder = columnConfigToColumnBinder; + this.namingStrategy = namingStrategy; } private static final Logger LOG = LoggerFactory.getLogger(EnumTypeBinder.class); @@ -78,7 +82,8 @@ public class EnumTypeBinder { return simpleValue; } - public BasicValue bindEnumTypeForColumn(@Nonnull HibernateToManyProperty property, @Nonnull String columnName) { + public BasicValue bindEnumTypeForColumn(@Nonnull HibernateBasicProperty property, @Nonnull String _columnName) { + String columnName = property.joinTableColumName(namingStrategy); BasicValue simpleValue = new BasicValue(metadataBuildingContext, property.getTable()); bindEnumType(property, property.getComponentType(), simpleValue, columnName); return simpleValue; diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/GrailsDomainBinder.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/GrailsDomainBinder.java index ed03b6f1f3..c70e8f8417 100644 --- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/GrailsDomainBinder.java +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/GrailsDomainBinder.java @@ -136,7 +136,7 @@ public class GrailsDomainBinder implements AdditionalMappingContributor, TypeCon SimpleValueBinder simpleValueBinder = new SimpleValueBinder(metadataBuildingContext, namingStrategy, jdbcEnvironment); EnumTypeBinder enumTypeBinder = - new EnumTypeBinder(metadataBuildingContext, columnNameForPropertyAndPathFetcher); + new EnumTypeBinder(metadataBuildingContext, columnNameForPropertyAndPathFetcher, namingStrategy); PropertyFromValueCreator propertyFromValueCreator = new PropertyFromValueCreator(); ClassBinder classBinder = new ClassBinder(metadataCollector); SimpleValueColumnFetcher simpleValueColumnFetcher = new SimpleValueColumnFetcher(); diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BasicCollectionElementBinder.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BasicCollectionElementBinder.java index b6a52809e6..08171897b8 100644 --- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BasicCollectionElementBinder.java +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BasicCollectionElementBinder.java @@ -18,8 +18,9 @@ */ package org.grails.orm.hibernate.cfg.domainbinding.secondpass; -import java.util.Optional; +import jakarta.annotation.Nonnull; +import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.Collection; @@ -30,11 +31,9 @@ import org.grails.orm.hibernate.cfg.PropertyConfig; import org.grails.orm.hibernate.cfg.domainbinding.binder.ColumnConfigToColumnBinder; import org.grails.orm.hibernate.cfg.domainbinding.binder.EnumTypeBinder; import org.grails.orm.hibernate.cfg.domainbinding.binder.SimpleValueColumnBinder; -import org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateToManyProperty; +import org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateBasicProperty; import org.grails.orm.hibernate.cfg.domainbinding.util.SimpleValueColumnFetcher; -import static org.grails.orm.hibernate.cfg.domainbinding.binder.GrailsDomainBinder.UNDERSCORE; - /** Binds the element value for a basic (scalar or enum) collection. */ public class BasicCollectionElementBinder { @@ -62,7 +61,7 @@ public class BasicCollectionElementBinder { } /** Creates and binds a {@link BasicValue} element for the given basic collection property. */ - public BasicValue bind(HibernateToManyProperty property) { + public BasicValue bind(@Nonnull HibernateBasicProperty property) { String columnName = property.joinTableColumName(namingStrategy); if (property.isEnum()) { return enumTypeBinder.bindEnumTypeForColumn(property, columnName); diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionWithJoinTableBinder.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionWithJoinTableBinder.java index e60cd87aa8..8988966a35 100644 --- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionWithJoinTableBinder.java +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionWithJoinTableBinder.java @@ -26,6 +26,7 @@ import org.grails.orm.hibernate.cfg.*; import org.grails.orm.hibernate.cfg.domainbinding.binder.CollectionForPropertyConfigBinder; import org.grails.orm.hibernate.cfg.domainbinding.binder.CompositeIdentifierToManyToOneBinder; import org.grails.orm.hibernate.cfg.domainbinding.binder.SimpleValueColumnBinder; +import org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateBasicProperty; import org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateToManyProperty; import static org.grails.orm.hibernate.cfg.domainbinding.binder.GrailsDomainBinder.*; @@ -62,8 +63,8 @@ public class CollectionWithJoinTableBinder { Collection collection = property.getCollection(); collection.setInverse(false); SimpleValue element; - if (property.isBasic()) { - element = basicCollectionElementBinder.bind(property); + if (property instanceof HibernateBasicProperty basic) { + element = basicCollectionElementBinder.bind(basic); } else { element = unidirectionalOneToManyInverseValuesBinder.bind(property); final var domainClass = property.getHibernateAssociatedEntity(); diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CollectionBinderSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CollectionBinderSpec.groovy index 7310dd0e96..1cd3404c12 100644 --- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CollectionBinderSpec.groovy +++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CollectionBinderSpec.groovy @@ -81,7 +81,7 @@ class CollectionBinderSpec extends HibernateGormDatastoreSpec { ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher = new ColumnNameForPropertyAndPathFetcher(namingStrategy, defaultColumnNameFetcher, backticksRemover) CollectionHolder collectionHolder = new CollectionHolder(metadataBuildingContext) SimpleValueBinder simpleValueBinder = new SimpleValueBinder(metadataBuildingContext, namingStrategy, jdbcEnvironment) - EnumTypeBinder enumTypeBinderToUse = new EnumTypeBinder(metadataBuildingContext, columnNameForPropertyAndPathFetcher) + EnumTypeBinder enumTypeBinderToUse = new EnumTypeBinder(metadataBuildingContext, columnNameForPropertyAndPathFetcher, namingStrategy) SimpleValueColumnFetcher simpleValueColumnFetcher = new SimpleValueColumnFetcher() CompositeIdentifierToManyToOneBinder compositeIdentifierToManyToOneBinder = new CompositeIdentifierToManyToOneBinder( diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/EnumTypeBinderSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/EnumTypeBinderSpec.groovy index 25c2941784..57ea04a290 100644 --- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/EnumTypeBinderSpec.groovy +++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/EnumTypeBinderSpec.groovy @@ -41,7 +41,7 @@ class EnumTypeBinderSpec extends HibernateGormDatastoreSpec { def namingStrategy = grailsDomainBinder.getNamingStrategy() def defaultColumnNameFetcher = new DefaultColumnNameFetcher(namingStrategy, new BackticksRemover()) def columnNameFetcher = new ColumnNameForPropertyAndPathFetcher(namingStrategy, defaultColumnNameFetcher, new BackticksRemover()) - binder = new EnumTypeBinder(metadataBuildingContext, columnNameFetcher, indexBinder, columnBinder) + binder = new EnumTypeBinder(metadataBuildingContext, columnNameFetcher, indexBinder, columnBinder, namingStrategy) } private PersistentProperty setupProperty(Class clazz, String propertyName, Table table) { diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/GrailsPropertyBinderSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/GrailsPropertyBinderSpec.groovy index 2f39c5bc65..8365962723 100644 --- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/GrailsPropertyBinderSpec.groovy +++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/GrailsPropertyBinderSpec.groovy @@ -89,7 +89,7 @@ class GrailsPropertyBinderSpec extends HibernateGormDatastoreSpec { ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher = new ColumnNameForPropertyAndPathFetcher(namingStrategy, defaultColumnNameFetcher, backticksRemover) CollectionHolder collectionHolder = new CollectionHolder(metadataBuildingContext) SimpleValueBinder simpleValueBinder = new SimpleValueBinder(metadataBuildingContext, namingStrategy, jdbcEnvironment) - EnumTypeBinder enumTypeBinderToUse = new EnumTypeBinder(metadataBuildingContext, columnNameForPropertyAndPathFetcher) + EnumTypeBinder enumTypeBinderToUse = new EnumTypeBinder(metadataBuildingContext, columnNameForPropertyAndPathFetcher,namingStrategy) SimpleValueColumnFetcher simpleValueColumnFetcher = new SimpleValueColumnFetcher() CompositeIdentifierToManyToOneBinder compositeIdentifierToManyToOneBinder = new CompositeIdentifierToManyToOneBinder( diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPassBinderSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPassBinderSpec.groovy index 9798be4dd2..fdd99417c7 100644 --- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPassBinderSpec.groovy +++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPassBinderSpec.groovy @@ -79,7 +79,7 @@ class ListSecondPassBinderSpec extends HibernateGormDatastoreSpec { ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher = new ColumnNameForPropertyAndPathFetcher(namingStrategy, defaultColumnNameFetcher, backticksRemover) CollectionHolder collectionHolder = new CollectionHolder(metadataBuildingContext) SimpleValueBinder simpleValueBinder = new SimpleValueBinder(metadataBuildingContext, namingStrategy, jdbcEnvironment) - EnumTypeBinder enumTypeBinderToUse = new EnumTypeBinder(metadataBuildingContext, columnNameForPropertyAndPathFetcher) + EnumTypeBinder enumTypeBinderToUse = new EnumTypeBinder(metadataBuildingContext, columnNameForPropertyAndPathFetcher,namingStrategy) SimpleValueColumnFetcher simpleValueColumnFetcher = new SimpleValueColumnFetcher() CompositeIdentifierToManyToOneBinder compositeIdentifierToManyToOneBinder = new CompositeIdentifierToManyToOneBinder( diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPassBinderSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPassBinderSpec.groovy index 10ff5022a2..b912873e8a 100644 --- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPassBinderSpec.groovy +++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPassBinderSpec.groovy @@ -79,7 +79,7 @@ class MapSecondPassBinderSpec extends HibernateGormDatastoreSpec { ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher = new ColumnNameForPropertyAndPathFetcher(namingStrategy, defaultColumnNameFetcher, backticksRemover) CollectionHolder collectionHolder = new CollectionHolder(metadataBuildingContext) SimpleValueBinder simpleValueBinder = new SimpleValueBinder(metadataBuildingContext, namingStrategy, jdbcEnvironment) - EnumTypeBinder enumTypeBinderToUse = new EnumTypeBinder(metadataBuildingContext, columnNameForPropertyAndPathFetcher) + EnumTypeBinder enumTypeBinderToUse = new EnumTypeBinder(metadataBuildingContext, columnNameForPropertyAndPathFetcher, namingStrategy) SimpleValueColumnFetcher simpleValueColumnFetcher = new SimpleValueColumnFetcher() CompositeIdentifierToManyToOneBinder compositeIdentifierToManyToOneBinder = new CompositeIdentifierToManyToOneBinder( diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/UnidirectionalOneToManyBinderSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/UnidirectionalOneToManyBinderSpec.groovy index 1b5089dde0..ce4f598672 100644 --- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/UnidirectionalOneToManyBinderSpec.groovy +++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/UnidirectionalOneToManyBinderSpec.groovy @@ -59,7 +59,7 @@ class UnidirectionalOneToManyBinderSpec extends HibernateGormDatastoreSpec { def columnNameForPropertyAndPathFetcher = new ColumnNameForPropertyAndPathFetcher(namingStrategy, defaultColumnNameFetcher, backticksRemover) def unidirectionalOneToManyInverseValuesBinder = new UnidirectionalOneToManyInverseValuesBinder(metadataBuildingContext) - def enumTypeBinder = new EnumTypeBinder(metadataBuildingContext, columnNameForPropertyAndPathFetcher) + def enumTypeBinder = new EnumTypeBinder(metadataBuildingContext, columnNameForPropertyAndPathFetcher,namingStrategy) def compositeIdentifierToManyToOneBinder = new CompositeIdentifierToManyToOneBinder(metadataBuildingContext, namingStrategy, jdbcEnvironment) def simpleValueColumnFetcher = new SimpleValueColumnFetcher() def collectionForPropertyConfigBinder = new CollectionForPropertyConfigBinder()
