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 66435d5a3562e87ec9132019c6f96ef23ef4581e
Author: Walter Duque de Estrada <[email protected]>
AuthorDate: Tue Mar 3 13:59:43 2026 -0600

    refactor: move CollectionKeyBinder into CollectionKeyColumnUpdater
---
 .../cfg/domainbinding/binder/CollectionBinder.java   | 12 ++++++------
 .../secondpass/CollectionKeyColumnUpdater.java       | 18 ++++++++++++++++++
 .../secondpass/CollectionSecondPassBinder.java       |  9 +++------
 .../secondpass/CollectionKeyColumnUpdaterSpec.groovy | 20 +++++++++++++++++++-
 .../secondpass/CollectionSecondPassBinderSpec.groovy |  4 ++--
 5 files changed, 48 insertions(+), 15 deletions(-)

diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/CollectionBinder.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/CollectionBinder.java
index 7749b30556..b397d360ad 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/CollectionBinder.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/CollectionBinder.java
@@ -110,15 +110,15 @@ public class CollectionBinder {
             new ColumnConfigToColumnBinder());
     this.collectionSecondPassBinder =
         new CollectionSecondPassBinder(
-            new CollectionKeyColumnUpdater(),
+            new CollectionKeyColumnUpdater(
+                new CollectionKeyBinder(
+                    new BidirectionalOneToManyLinker(grailsPropertyResolver),
+                    new DependentKeyValueBinder(simpleValueBinder, 
compositeIdentifierToManyToOneBinder),
+                    simpleValueColumnBinder,
+                    new PrimaryKeyValueCreator(metadataBuildingContext))),
             new UnidirectionalOneToManyBinder(collectionWithJoinTableBinder, 
mappings),
             collectionWithJoinTableBinder,
             collectionForPropertyConfigBinder,
-            new CollectionKeyBinder(
-                new BidirectionalOneToManyLinker(grailsPropertyResolver),
-                new DependentKeyValueBinder(simpleValueBinder, 
compositeIdentifierToManyToOneBinder),
-                simpleValueColumnBinder,
-                new PrimaryKeyValueCreator(metadataBuildingContext)),
             new BidirectionalMapElementBinder(manyToOneBinder, 
collectionForPropertyConfigBinder),
             new ManyToManyElementBinder(manyToOneBinder, 
collectionForPropertyConfigBinder),
             new CollectionOrderByBinder(),
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyColumnUpdater.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyColumnUpdater.java
index 0d9f2f55e3..64fe89ac08 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyColumnUpdater.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyColumnUpdater.java
@@ -21,11 +21,29 @@ package 
org.grails.orm.hibernate.cfg.domainbinding.secondpass;
 import java.util.Objects;
 import java.util.stream.StreamSupport;
 import 
org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateToManyProperty;
+import org.hibernate.mapping.Collection;
 import org.hibernate.mapping.DependantValue;
+import org.hibernate.mapping.PersistentClass;
 
 /** Forces columns to be nullable and checks if the key is updateable. */
 public class CollectionKeyColumnUpdater {
 
+  private final CollectionKeyBinder collectionKeyBinder;
+
+  /** Creates a new {@link CollectionKeyColumnUpdater} instance. */
+  public CollectionKeyColumnUpdater(CollectionKeyBinder collectionKeyBinder) {
+    this.collectionKeyBinder = collectionKeyBinder;
+  }
+
+  /** Creates the key, sets it on the collection, and updates its columns. */
+  public void bind(
+      HibernateToManyProperty property,
+      PersistentClass associatedClass,
+      Collection collection) {
+    DependantValue key = collectionKeyBinder.bind(property, associatedClass, 
collection);
+    forceNullableAndCheckUpdatable(key, property);
+  }
+
   /** Force nullable and check updatable. */
   public void forceNullableAndCheckUpdatable(DependantValue key, 
HibernateToManyProperty property) {
     key.getColumns().stream()
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionSecondPassBinder.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionSecondPassBinder.java
index 4507e52732..26b2f34cd0 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionSecondPassBinder.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionSecondPassBinder.java
@@ -35,10 +35,9 @@ import org.hibernate.mapping.Collection;
 public class CollectionSecondPassBinder {
   private final CollectionOrderByBinder collectionOrderByBinder;
   private final CollectionMultiTenantFilterBinder 
collectionMultiTenantFilterBinder;
-  private final CollectionKeyBinder collectionKeyBinder;
+  private final CollectionKeyColumnUpdater collectionKeyColumnUpdater;
   private final BidirectionalMapElementBinder bidirectionalMapElementBinder;
   private final ManyToManyElementBinder manyToManyElementBinder;
-  private final CollectionKeyColumnUpdater collectionKeyColumnUpdater;
   private final UnidirectionalOneToManyBinder unidirectionalOneToManyBinder;
   private final CollectionWithJoinTableBinder collectionWithJoinTableBinder;
   private final CollectionForPropertyConfigBinder 
collectionForPropertyConfigBinder;
@@ -49,7 +48,6 @@ public class CollectionSecondPassBinder {
       UnidirectionalOneToManyBinder unidirectionalOneToManyBinder,
       CollectionWithJoinTableBinder collectionWithJoinTableBinder,
       CollectionForPropertyConfigBinder collectionForPropertyConfigBinder,
-      CollectionKeyBinder collectionKeyBinder,
       BidirectionalMapElementBinder bidirectionalMapElementBinder,
       ManyToManyElementBinder manyToManyElementBinder,
       CollectionOrderByBinder collectionOrderByBinder,
@@ -58,7 +56,6 @@ public class CollectionSecondPassBinder {
     this.unidirectionalOneToManyBinder = unidirectionalOneToManyBinder;
     this.collectionWithJoinTableBinder = collectionWithJoinTableBinder;
     this.collectionForPropertyConfigBinder = collectionForPropertyConfigBinder;
-    this.collectionKeyBinder = collectionKeyBinder;
     this.bidirectionalMapElementBinder = bidirectionalMapElementBinder;
     this.manyToManyElementBinder = manyToManyElementBinder;
     this.collectionOrderByBinder = collectionOrderByBinder;
@@ -79,11 +76,11 @@ public class CollectionSecondPassBinder {
     collectionMultiTenantFilterBinder.bind(property, collection);
     collection.setSorted(property.isSorted());
 
-    DependantValue key = collectionKeyBinder.bind(property, associatedClass, 
collection);
+    collectionKeyColumnUpdater.bind(property, associatedClass, collection);
     collection.setCacheConcurrencyStrategy(property.getCacheUSage());
 
     bindCollectionElement(property, mappings, collection);
-    collectionKeyColumnUpdater.forceNullableAndCheckUpdatable(key, property);
+
   }
 
   private void bindOneToManyAssociation(
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyColumnUpdaterSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyColumnUpdaterSpec.groovy
index 0ba9db6f09..dc5e411c2b 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyColumnUpdaterSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyColumnUpdaterSpec.groovy
@@ -2,7 +2,11 @@ package org.grails.orm.hibernate.cfg.domainbinding.secondpass
 
 import grails.gorm.annotation.Entity
 import grails.gorm.specs.HibernateGormDatastoreSpec
+import 
org.grails.orm.hibernate.cfg.domainbinding.binder.CompositeIdentifierToManyToOneBinder
+import org.grails.orm.hibernate.cfg.domainbinding.binder.SimpleValueBinder
+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.util.GrailsPropertyResolver
 import org.hibernate.mapping.Column
 import org.hibernate.mapping.DependantValue
 import spock.lang.Subject
@@ -10,7 +14,21 @@ import spock.lang.Subject
 class CollectionKeyColumnUpdaterSpec extends HibernateGormDatastoreSpec {
 
     @Subject
-    CollectionKeyColumnUpdater updater = new CollectionKeyColumnUpdater()
+    CollectionKeyColumnUpdater updater
+
+    void setup() {
+        def gdb = getGrailsDomainBinder()
+        def mbc = gdb.getMetadataBuildingContext()
+        def ns = gdb.getNamingStrategy()
+        def je = gdb.getJdbcEnvironment()
+        def svb = new SimpleValueBinder(mbc, ns, je)
+        def citmto = new CompositeIdentifierToManyToOneBinder(mbc, ns, je)
+        def botml = new BidirectionalOneToManyLinker(new 
GrailsPropertyResolver())
+        def dkvb = new DependentKeyValueBinder(svb, citmto)
+        def svcb = new SimpleValueColumnBinder()
+        def pkvc = new PrimaryKeyValueCreator(mbc)
+        updater = new CollectionKeyColumnUpdater(new 
CollectionKeyBinder(botml, dkvb, svcb, pkvc))
+    }
 
     void "test forceNullableAndCheckUpdateable with single unidirectional 
association"() {
         given:
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionSecondPassBinderSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionSecondPassBinderSpec.groovy
index 46a18eba1c..d89e94b226 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionSecondPassBinderSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionSecondPassBinderSpec.groovy
@@ -32,7 +32,6 @@ class CollectionSecondPassBinderSpec extends 
HibernateGormDatastoreSpec {
         def citmto = new CompositeIdentifierToManyToOneBinder(mbc, ns, je)
         def mtob = new ManyToOneBinder(mbc, ns, svb, new 
ManyToOneValuesBinder(), citmto)
         def pkvc = new PrimaryKeyValueCreator(mbc)
-        def cku = new CollectionKeyColumnUpdater()
         def botml = new BidirectionalOneToManyLinker(new 
org.grails.orm.hibernate.cfg.domainbinding.util.GrailsPropertyResolver())
         def dkvb = new DependentKeyValueBinder(svb, citmto)
         def cwjtb = new CollectionWithJoinTableBinder(mbc, ns, new 
UnidirectionalOneToManyInverseValuesBinder(), null, citmto, svcf, new 
CollectionForPropertyConfigBinder(), new SimpleValueColumnBinder(), null)
@@ -40,8 +39,9 @@ class CollectionSecondPassBinderSpec extends 
HibernateGormDatastoreSpec {
         def cfpcb = new CollectionForPropertyConfigBinder()
         def dcnf = new DefaultColumnNameFetcher(ns, new BackticksRemover())
         def svcb = new SimpleValueColumnBinder()
+        def cku = new CollectionKeyColumnUpdater(new 
CollectionKeyBinder(botml, dkvb, svcb, pkvc))
 
-        binder = new CollectionSecondPassBinder(cku, uotmb, cwjtb, cfpcb, new 
CollectionKeyBinder(botml, dkvb, svcb, pkvc), new 
BidirectionalMapElementBinder(mtob, cfpcb), new ManyToManyElementBinder(mtob, 
cfpcb), new CollectionOrderByBinder(), new 
CollectionMultiTenantFilterBinder(dcnf))
+        binder = new CollectionSecondPassBinder(cku, uotmb, cwjtb, cfpcb, new 
BidirectionalMapElementBinder(mtob, cfpcb), new ManyToManyElementBinder(mtob, 
cfpcb), new CollectionOrderByBinder(), new 
CollectionMultiTenantFilterBinder(dcnf))
     }
 
     protected HibernatePersistentProperty 
createTestHibernateToManyProperty(Class<?> domainClass = 
CSPBTestEntityWithMany, String propertyName = "items") {

Reply via email to