This is an automated email from the ASF dual-hosted git repository.

borinquenkid pushed a commit to branch merge-hibernate6
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit 5405671ab0b368511b00e4e458e985441a8209ff
Author: Walter Duque de Estrada <[email protected]>
AuthorDate: Sat Jul 12 18:13:37 2025 -0500

    SimpleValueBinder
---
 .../orm/hibernate/cfg/GrailsDomainBinder.java      | 50 +++++++---------------
 .../cfg/domainbinding/SimpleValueBinder.java       | 23 +++++-----
 .../cfg/domainbinding/SimpleValueBinderSpec.groovy | 10 ++---
 3 files changed, 31 insertions(+), 52 deletions(-)

diff --git 
a/grails-data-hibernate6/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java
 
b/grails-data-hibernate6/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java
index 185402701f..793d49b266 100644
--- 
a/grails-data-hibernate6/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java
+++ 
b/grails-data-hibernate6/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java
@@ -37,6 +37,7 @@ import 
org.grails.orm.hibernate.access.TraitPropertyAccessStrategy;
 import org.grails.orm.hibernate.cfg.domainbinding.ClassBinder;
 import 
org.grails.orm.hibernate.cfg.domainbinding.ConfigureDerivedPropertiesConsumer;
 import org.grails.orm.hibernate.cfg.domainbinding.NamingStrategyProvider;
+import org.grails.orm.hibernate.cfg.domainbinding.SimpleValueBinder;
 import org.grails.orm.hibernate.cfg.domainbinding.TypeNameProvider;
 import org.hibernate.FetchMode;
 import org.hibernate.MappingException;
@@ -279,8 +280,9 @@ public class GrailsDomainBinder implements 
MetadataContributor {
 
         SimpleValue value = new BasicValue(metadataBuildingContext, 
map.getCollectionTable());
 
-        bindSimpleValue(getIndexColumnType(property, STRING_TYPE), value, true,
-                getIndexColumnName(property, sessionFactoryBeanName), 
mappings);
+        String type = getIndexColumnType(property, STRING_TYPE);
+        String columnName1 = getIndexColumnName(property, 
sessionFactoryBeanName);
+        new SimpleValueBinder().bindSimpleValue(value, type, columnName1, 
true);
         PropertyConfig pc = getPropertyConfig(property);
         if (pc != null && pc.getIndexColumn() != null) {
             bindColumnConfigToColumn(property, getColumnForSimpleValue(value), 
getSingleColumnConfig(pc.getIndexColumn()));
@@ -309,7 +311,8 @@ public class GrailsDomainBinder implements 
MetadataContributor {
             if(typeName == null || typeName.equals(Object.class.getName())) {
                 typeName = StandardBasicTypes.STRING.getName();
             }
-            bindSimpleValue(typeName, elt, false, getMapElementName(property, 
sessionFactoryBeanName), mappings);
+            String columnName = getMapElementName(property, 
sessionFactoryBeanName);
+            new SimpleValueBinder().bindSimpleValue(elt, typeName, columnName, 
false);
 
             elt.setTypeName(typeName);
         }
@@ -342,7 +345,7 @@ public class GrailsDomainBinder implements 
MetadataContributor {
 
         Table collectionTable = list.getCollectionTable();
         SimpleValue iv = new BasicValue(metadataBuildingContext, 
collectionTable);
-        bindSimpleValue("integer", iv, true, columnName, mappings);
+        new SimpleValueBinder().bindSimpleValue(iv, "integer", columnName, 
true);
         iv.setTypeName("integer");
         list.setIndex(iv);
         list.setBaseIndex(0);
@@ -515,7 +518,8 @@ public class GrailsDomainBinder implements 
MetadataContributor {
             }
         } else {
             if (hasJoinKeyMapping(propConfig)) {
-                bindSimpleValue("long", key,false, 
propConfig.getJoinTable().getKey().getName(), mappings);
+                String columnName = 
propConfig.getJoinTable().getKey().getName();
+                new SimpleValueBinder().bindSimpleValue(key, "long", 
columnName, false);
             } else {
                 bindDependentKeyValue(property, key, mappings, 
sessionFactoryBeanName);
             }
@@ -765,7 +769,7 @@ public class GrailsDomainBinder implements 
MetadataContributor {
                     throw new MappingException("Missing type or column for 
column["+columnName+"] on domain["+domainName+"] referencing["+className+"]");
                 }
 
-                bindSimpleValue(typeName, element,true, columnName, mappings);
+                new SimpleValueBinder().bindSimpleValue(element, typeName, 
columnName, true);
                 if (hasJoinColumnMapping) {
                     bindColumnConfigToColumn(property, 
getColumnForSimpleValue(element), config.getJoinTable().getColumn());
                 }
@@ -788,7 +792,7 @@ public class GrailsDomainBinder implements 
MetadataContributor {
                     columnName = 
namingStrategy.toPhysicalColumnName(decapitalize,getJdbcEnvironment()).toString()
 + FOREIGN_KEY_SUFFIX;
                 }
 
-                bindSimpleValue("long", element,true, columnName, mappings);
+                new SimpleValueBinder().bindSimpleValue(element, "long", 
columnName, true);
             }
         }
 
@@ -1616,7 +1620,7 @@ public class GrailsDomainBinder implements 
MetadataContributor {
         joinedSubclass.setKey(key);
         final PersistentProperty identifier = sub.getIdentity();
         String columnName = getColumnNameForPropertyAndPath(identifier, 
EMPTY_PATH, null, sessionFactoryBeanName);
-        bindSimpleValue(identifier.getType().getName(), key, false, 
columnName, mappings);
+        new SimpleValueBinder().bindSimpleValue(key, 
identifier.getType().getName(), columnName, false);
 
         joinedSubclass.createPrimaryKey();
         joinedSubclass.createForeignKey();
@@ -1697,7 +1701,7 @@ public class GrailsDomainBinder implements 
MetadataContributor {
             d.addFormula(formula);
         }
         else{
-            bindSimpleValue(STRING_TYPE, d, false, 
RootClass.DEFAULT_DISCRIMINATOR_COLUMN_NAME, mappings);
+            new SimpleValueBinder().bindSimpleValue(d, STRING_TYPE, 
RootClass.DEFAULT_DISCRIMINATOR_COLUMN_NAME, false);
 
             ColumnConfig cc = !hasDiscriminatorConfig ? null : 
discriminatorConfig.getColumn();
             if (cc != null) {
@@ -1887,8 +1891,9 @@ public class GrailsDomainBinder implements 
MetadataContributor {
                 String typeName = new 
TypeNameProvider().getTypeName(currentGrailsProp,config, gormMapping);
                 if ("serializable".equals(typeName)) {
                     value = new BasicValue(metadataBuildingContext, table);
-                    bindSimpleValue(typeName, (SimpleValue) value, 
currentGrailsProp.isNullable(),
-                            getColumnNameForPropertyAndPath(currentGrailsProp, 
EMPTY_PATH, null, sessionFactoryBeanName), mappings);
+                    boolean nullable = currentGrailsProp.isNullable();
+                    String columnName = 
getColumnNameForPropertyAndPath(currentGrailsProp, EMPTY_PATH, null, 
sessionFactoryBeanName);
+                    new SimpleValueBinder().bindSimpleValue((SimpleValue) 
value, typeName, columnName, nullable);
                 }
                 else {
                     // create collection
@@ -2911,29 +2916,6 @@ public class GrailsDomainBinder implements 
MetadataContributor {
         }
     }
 
-    /**
-     * Binds a value for the specified parameters to the meta model.
-     *
-     * @param type        The type of the property
-     * @param simpleValue The simple value instance
-     * @param nullable    Whether it is nullable
-     * @param columnName  The property name
-     * @param mappings    The mappings
-     */
-    private void bindSimpleValue(String type, SimpleValue simpleValue, boolean 
nullable,
-                                   String columnName, 
InFlightMetadataCollector mappings) {
-
-        simpleValue.setTypeName(type);
-        Table t = simpleValue.getTable();
-        Column column = new Column();
-        column.setNullable(nullable);
-        column.setValue(simpleValue);
-        column.setName(columnName);
-        if (t != null) t.addColumn(column);
-
-        simpleValue.addColumn(column);
-    }
-
     /**
      * Binds a Column instance to the Hibernate meta model
      *
diff --git 
a/grails-data-hibernate6/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/SimpleValueBinder.java
 
b/grails-data-hibernate6/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/SimpleValueBinder.java
index e72f1db106..ff0766c275 100644
--- 
a/grails-data-hibernate6/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/SimpleValueBinder.java
+++ 
b/grails-data-hibernate6/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/SimpleValueBinder.java
@@ -1,9 +1,10 @@
 package org.grails.orm.hibernate.cfg.domainbinding;
 
+import org.hibernate.MappingException;
 import org.hibernate.mapping.Column;
 import org.hibernate.mapping.SimpleValue;
 
-import static java.util.Optional.ofNullable;
+import java.util.Optional;
 
 public class SimpleValueBinder {
 
@@ -16,15 +17,15 @@ public class SimpleValueBinder {
      * @param nullable    Whether it is nullable
      */
     public void bindSimpleValue(SimpleValue simpleValue, String type, String 
columnName, boolean nullable) {
-        Column column = new Column();
-        column.setNullable(nullable);
-        column.setValue(simpleValue);
-        column.setName(columnName);
-        ofNullable(simpleValue.getTable())
-                .ifPresent(
-                        table -> table.addColumn(column)
-                );
-        simpleValue.getSelectables().add(column);
-        simpleValue.setTypeName(type);
+        Optional.ofNullable(simpleValue.getTable())
+                .ifPresentOrElse( table -> {
+                    var column = new Column();
+                    column.setNullable(nullable);
+                    column.setValue(simpleValue);
+                    column.setName(columnName);
+                    table.addColumn(column);
+                    simpleValue.addColumn(column);
+                    simpleValue.setTypeName(type);
+                }, () -> { throw new MappingException("SimpleValue must have a 
table");});
     }
 }
diff --git 
a/grails-data-hibernate6/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/SimpleValueBinderSpec.groovy
 
b/grails-data-hibernate6/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/SimpleValueBinderSpec.groovy
index 7764285492..0628ed0a67 100644
--- 
a/grails-data-hibernate6/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/SimpleValueBinderSpec.groovy
+++ 
b/grails-data-hibernate6/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/SimpleValueBinderSpec.groovy
@@ -1,6 +1,7 @@
 package org.grails.orm.hibernate.cfg.domainbinding
 
 import grails.gorm.specs.HibernateGormDatastoreSpec
+import org.hibernate.MappingException
 import org.hibernate.mapping.BasicValue
 import org.hibernate.mapping.Column
 import org.hibernate.mapping.Table
@@ -41,13 +42,8 @@ class SimpleValueBinderSpec extends 
HibernateGormDatastoreSpec {
         BasicValue simpleValue = new 
BasicValue(grailsDomainBinder.metadataBuildingContext, null);
         simpleValueBinder.bindSimpleValue(simpleValue, type, columnName, 
nullable)
 
-        def column = (Column) simpleValue.column
         then:
-        column
-        column.value == simpleValue
-        column.name == columnName
-        column.nullable
-        simpleValue.column == column
-        !simpleValue.table
+        MappingException e = thrown()
+
     }
 }

Reply via email to