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 0a709de9966dec8fa9ab57ba1da62f8732d12d9a Author: Walter Duque de Estrada <[email protected]> AuthorDate: Mon Feb 16 08:27:02 2026 -0600 Refactor EnumTypeBinder to manage and return BasicValue instances --- .../orm/hibernate/cfg/GrailsDomainBinder.java | 5 ++-- .../cfg/domainbinding/binder/CollectionBinder.java | 13 +++++++-- .../cfg/domainbinding/binder/ComponentBinder.java | 16 +++-------- .../cfg/domainbinding/binder/EnumTypeBinder.java | 25 +++++++++++++--- .../domainbinding/binder/GrailsPropertyBinder.java | 5 +--- .../secondpass/CollectionSecondPassBinder.java | 3 +- .../cfg/domainbinding/CollectionBinderSpec.groovy | 5 ++-- .../CollectionSecondPassBinderSpec.groovy | 5 ++-- .../cfg/domainbinding/ComponentBinderSpec.groovy | 2 +- .../cfg/domainbinding/EnumTypeBinderSpec.groovy | 33 +++++++++++++++++++++- .../domainbinding/GrailsPropertyBinderSpec.groovy | 5 ++-- .../domainbinding/ListSecondPassBinderSpec.groovy | 5 ++-- .../domainbinding/MapSecondPassBinderSpec.groovy | 5 ++-- 13 files changed, 89 insertions(+), 38 deletions(-) diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java index d4b6f2446f..440eec5b4d 100644 --- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java @@ -158,7 +158,7 @@ public class GrailsDomainBinder DefaultColumnNameFetcher defaultColumnNameFetcher = new DefaultColumnNameFetcher(namingStrategy, backticksRemover); ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher = new ColumnNameForPropertyAndPathFetcher(namingStrategy, defaultColumnNameFetcher, backticksRemover); SimpleValueBinder simpleValueBinder = new SimpleValueBinder(namingStrategy, jdbcEnvironment); - EnumTypeBinder enumTypeBinder = new EnumTypeBinder(); + EnumTypeBinder enumTypeBinder = new EnumTypeBinder(metadataBuildingContext, columnNameForPropertyAndPathFetcher); PropertyFromValueCreator propertyFromValueCreator = new PropertyFromValueCreator(); ClassBinder classBinder = new ClassBinder(); SimpleValueColumnFetcher simpleValueColumnFetcher = new SimpleValueColumnFetcher(); @@ -181,7 +181,8 @@ public class GrailsDomainBinder enumTypeBinder, manyToOneBinder, compositeIdentifierToManyToOneBinder, - simpleValueColumnFetcher + simpleValueColumnFetcher, + columnNameForPropertyAndPathFetcher ); ComponentUpdater componentUpdater = new ComponentUpdater(propertyFromValueCreator); ComponentBinder componentBinder = new ComponentBinder( 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 5d0005ddab..3b49d3b89b 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 @@ -10,6 +10,9 @@ import org.grails.orm.hibernate.cfg.PersistentEntityNamingStrategy; import org.grails.orm.hibernate.cfg.PropertyConfig; import org.grails.orm.hibernate.cfg.JoinTable; import org.grails.orm.hibernate.cfg.domainbinding.util.CascadeBehavior; +import org.grails.orm.hibernate.cfg.domainbinding.util.BackticksRemover; +import org.grails.orm.hibernate.cfg.domainbinding.util.ColumnNameForPropertyAndPathFetcher; +import org.grails.orm.hibernate.cfg.domainbinding.util.DefaultColumnNameFetcher; import org.grails.orm.hibernate.cfg.domainbinding.util.NamespaceNameExtractor; import org.grails.orm.hibernate.cfg.domainbinding.util.SimpleValueColumnFetcher; import org.grails.orm.hibernate.cfg.domainbinding.util.TableForManyCalculator; @@ -40,6 +43,7 @@ public class CollectionBinder { private final MetadataBuildingContext metadataBuildingContext; private final PersistentEntityNamingStrategy namingStrategy; + private final ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher; private final ListSecondPassBinder listSecondPassBinder; private final CollectionSecondPassBinder collectionSecondPassBinder; private final MapSecondPassBinder mapSecondPassBinder; @@ -52,9 +56,11 @@ public class CollectionBinder { EnumTypeBinder enumTypeBinder, ManyToOneBinder manyToOneBinder, CompositeIdentifierToManyToOneBinder compositeIdentifierToManyToOneBinder, - SimpleValueColumnFetcher simpleValueColumnFetcher) { + SimpleValueColumnFetcher simpleValueColumnFetcher, + ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher) { this.metadataBuildingContext = metadataBuildingContext; this.namingStrategy = namingStrategy; + this.columnNameForPropertyAndPathFetcher = columnNameForPropertyAndPathFetcher; this.collectionSecondPassBinder = new CollectionSecondPassBinder( metadataBuildingContext, namingStrategy, @@ -72,10 +78,11 @@ public class CollectionBinder { public CollectionBinder(MetadataBuildingContext metadataBuildingContext, PersistentEntityNamingStrategy namingStrategy, JdbcEnvironment jdbcEnvironment) { this(metadataBuildingContext, namingStrategy, jdbcEnvironment, new SimpleValueBinder(namingStrategy, jdbcEnvironment), - new EnumTypeBinder(), + new EnumTypeBinder(metadataBuildingContext, new ColumnNameForPropertyAndPathFetcher(namingStrategy, new DefaultColumnNameFetcher(namingStrategy), new BackticksRemover())), new ManyToOneBinder(metadataBuildingContext, namingStrategy, jdbcEnvironment), new CompositeIdentifierToManyToOneBinder(namingStrategy, jdbcEnvironment), - new SimpleValueColumnFetcher()); + new SimpleValueColumnFetcher(), + new ColumnNameForPropertyAndPathFetcher(namingStrategy, new DefaultColumnNameFetcher(namingStrategy), new BackticksRemover())); } /** diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/ComponentBinder.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/ComponentBinder.java index 936c645744..d9044f5ef0 100644 --- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/ComponentBinder.java +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/ComponentBinder.java @@ -134,19 +134,11 @@ public class ComponentBinder { else if (currentGrailsProp instanceof HibernateEmbeddedProperty embedded) { value = bindComponent(persistentClass, embedded, mappings); } - else { - if (LOG.isDebugEnabled()) - LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName() + "] as SimpleValue"); - - value = new BasicValue(metadataBuildingContext, table); - if (currentGrailsProp.getType().isEnum()) { - String columnName = columnNameForPropertyAndPathFetcher.getColumnNameForPropertyAndPath(currentGrailsProp, path, null); - enumTypeBinder.bindEnumType(currentGrailsProp, currentGrailsProp.getType(), (SimpleValue) value, columnName); - } - else { - // set type + else if (currentGrailsProp.getType().isEnum()) { + value = enumTypeBinder.bindEnumType(currentGrailsProp, currentGrailsProp.getType(), table, path); + } else { + value = new BasicValue(metadataBuildingContext, table); this.simpleValueBinder.bindSimpleValue(currentGrailsProp, componentProperty, (SimpleValue) value, path); - } } return value; } 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 317494f9c5..2106474eb0 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 @@ -4,7 +4,10 @@ import org.grails.orm.hibernate.cfg.ColumnConfig; import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty; import org.grails.orm.hibernate.cfg.IdentityEnumType; import org.grails.orm.hibernate.cfg.PropertyConfig; +import org.grails.orm.hibernate.cfg.domainbinding.util.ColumnNameForPropertyAndPathFetcher; import org.hibernate.MappingException; +import org.hibernate.boot.spi.MetadataBuildingContext; +import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.Column; import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.Table; @@ -23,14 +26,21 @@ import static org.grails.orm.hibernate.cfg.GrailsDomainBinder.ENUM_TYPE_CLASS; public class EnumTypeBinder { + private final MetadataBuildingContext metadataBuildingContext; + private final ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher; private final IndexBinder indexBinder; - private ColumnConfigToColumnBinder columnConfigToColumnBinder; + private final ColumnConfigToColumnBinder columnConfigToColumnBinder; - public EnumTypeBinder() { - this(new IndexBinder(), new ColumnConfigToColumnBinder()); + public EnumTypeBinder(MetadataBuildingContext metadataBuildingContext, ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher) { + this(metadataBuildingContext, columnNameForPropertyAndPathFetcher, new IndexBinder(), new ColumnConfigToColumnBinder()); } - protected EnumTypeBinder(IndexBinder indexBinder, ColumnConfigToColumnBinder columnConfigToColumnBinder) { + protected EnumTypeBinder(MetadataBuildingContext metadataBuildingContext, + ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher, + IndexBinder indexBinder, + ColumnConfigToColumnBinder columnConfigToColumnBinder) { + this.metadataBuildingContext = metadataBuildingContext; + this.columnNameForPropertyAndPathFetcher = columnNameForPropertyAndPathFetcher; this.indexBinder = indexBinder; this.columnConfigToColumnBinder = columnConfigToColumnBinder; } @@ -38,6 +48,13 @@ public class EnumTypeBinder { private static final Logger LOG = LoggerFactory.getLogger(EnumTypeBinder.class); + public BasicValue bindEnumType(GrailsHibernatePersistentProperty property, Class<?> propertyType, Table table, String path) { + BasicValue simpleValue = new BasicValue(metadataBuildingContext, table); + String columnName = columnNameForPropertyAndPathFetcher.getColumnNameForPropertyAndPath(property, path, null); + bindEnumType(property, propertyType, simpleValue, columnName); + return simpleValue; + } + public void bindEnumType(GrailsHibernatePersistentProperty property, Class<?> propertyType, SimpleValue simpleValue, String columnName) { PropertyConfig pc = property.getMappedForm(); String enumType = pc.getEnumType(); diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/GrailsPropertyBinder.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/GrailsPropertyBinder.java index 6150f1074b..797c389002 100644 --- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/GrailsPropertyBinder.java +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/GrailsPropertyBinder.java @@ -104,10 +104,7 @@ public class GrailsPropertyBinder { } } else if (currentGrailsProp.getType().isEnum()) { - value = new BasicValue(metadataBuildingContext, table); - SimpleValue simpleValue = (SimpleValue) value; - String columnName = columnNameForPropertyAndPathFetcher.getColumnNameForPropertyAndPath(currentGrailsProp, EMPTY_PATH, null); - enumTypeBinder.bindEnumType(currentGrailsProp, currentGrailsProp.getType(), simpleValue, columnName); + value = enumTypeBinder.bindEnumType(currentGrailsProp, currentGrailsProp.getType(), table, EMPTY_PATH); } else if (currentGrailsProp.isHibernateOneToOne()) { value = oneToOneBinder.bindOneToOne((org.grails.datastore.mapping.model.types.OneToOne)currentGrailsProp, persistentClass, table, EMPTY_PATH); 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 9176d499ab..871097633d 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 @@ -10,6 +10,7 @@ import org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateManyToManyP import org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateOneToManyProperty; import org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateToManyProperty; import org.grails.orm.hibernate.cfg.domainbinding.util.BackticksRemover; +import org.grails.orm.hibernate.cfg.domainbinding.util.ColumnNameForPropertyAndPathFetcher; import org.grails.orm.hibernate.cfg.domainbinding.binder.CollectionForPropertyConfigBinder; import org.grails.orm.hibernate.cfg.domainbinding.binder.ColumnConfigToColumnBinder; import org.grails.orm.hibernate.cfg.domainbinding.binder.CompositeIdentifierToManyToOneBinder; @@ -81,7 +82,7 @@ public class CollectionSecondPassBinder { public CollectionSecondPassBinder(MetadataBuildingContext metadataBuildingContext, PersistentEntityNamingStrategy namingStrategy, JdbcEnvironment jdbcEnvironment) { this(metadataBuildingContext, namingStrategy, jdbcEnvironment, new SimpleValueBinder(namingStrategy, jdbcEnvironment), - new EnumTypeBinder(), + new EnumTypeBinder(metadataBuildingContext, new ColumnNameForPropertyAndPathFetcher(namingStrategy, new DefaultColumnNameFetcher(namingStrategy), new BackticksRemover())), new ManyToOneBinder(metadataBuildingContext, namingStrategy, jdbcEnvironment), new CompositeIdentifierToManyToOneBinder(namingStrategy, jdbcEnvironment), new SimpleValueColumnFetcher()); 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 5420cf8df1..06cf7dff8b 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 @@ -55,7 +55,7 @@ class CollectionBinderSpec extends HibernateGormDatastoreSpec { ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher = new ColumnNameForPropertyAndPathFetcher(namingStrategy, defaultColumnNameFetcher, backticksRemover) CollectionHolder collectionHolder = new CollectionHolder(metadataBuildingContext) SimpleValueBinder simpleValueBinder = new SimpleValueBinder(namingStrategy, jdbcEnvironment) - EnumTypeBinder enumTypeBinderToUse = new EnumTypeBinder() + EnumTypeBinder enumTypeBinderToUse = new EnumTypeBinder(metadataBuildingContext, columnNameForPropertyAndPathFetcher) SimpleValueColumnFetcher simpleValueColumnFetcher = new SimpleValueColumnFetcher() CompositeIdentifierToManyToOneBinder compositeIdentifierToManyToOneBinder = new CompositeIdentifierToManyToOneBinder( new org.grails.orm.hibernate.cfg.domainbinding.util.ForeignKeyColumnCountCalculator(), @@ -76,7 +76,8 @@ class CollectionBinderSpec extends HibernateGormDatastoreSpec { enumTypeBinderToUse, manyToOneBinder, compositeIdentifierToManyToOneBinder, - simpleValueColumnFetcher + simpleValueColumnFetcher, + columnNameForPropertyAndPathFetcher ) PropertyFromValueCreator propertyFromValueCreator = new PropertyFromValueCreator() ComponentUpdater componentUpdater = new ComponentUpdater(propertyFromValueCreator) diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CollectionSecondPassBinderSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CollectionSecondPassBinderSpec.groovy index 3106e7eba0..6f5407545b 100644 --- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CollectionSecondPassBinderSpec.groovy +++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CollectionSecondPassBinderSpec.groovy @@ -54,7 +54,7 @@ class CollectionSecondPassBinderSpec extends HibernateGormDatastoreSpec { ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher = new ColumnNameForPropertyAndPathFetcher(namingStrategy, defaultColumnNameFetcher, backticksRemover) CollectionHolder collectionHolder = new CollectionHolder(metadataBuildingContext) SimpleValueBinder simpleValueBinder = new SimpleValueBinder(namingStrategy, jdbcEnvironment) - EnumTypeBinder enumTypeBinderToUse = new EnumTypeBinder() + EnumTypeBinder enumTypeBinderToUse = new EnumTypeBinder(metadataBuildingContext, columnNameForPropertyAndPathFetcher) SimpleValueColumnFetcher simpleValueColumnFetcher = new SimpleValueColumnFetcher() CompositeIdentifierToManyToOneBinder compositeIdentifierToManyToOneBinder = new CompositeIdentifierToManyToOneBinder( new org.grails.orm.hibernate.cfg.domainbinding.util.ForeignKeyColumnCountCalculator(), @@ -75,7 +75,8 @@ class CollectionSecondPassBinderSpec extends HibernateGormDatastoreSpec { enumTypeBinderToUse, manyToOneBinder, compositeIdentifierToManyToOneBinder, - simpleValueColumnFetcher + simpleValueColumnFetcher, + columnNameForPropertyAndPathFetcher ) PropertyFromValueCreator propertyFromValueCreator = new PropertyFromValueCreator() ComponentUpdater componentUpdater = new ComponentUpdater(propertyFromValueCreator) diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ComponentBinderSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ComponentBinderSpec.groovy index 2fb24c3bb7..2c96f3bff2 100644 --- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ComponentBinderSpec.groovy +++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ComponentBinderSpec.groovy @@ -255,7 +255,7 @@ class ComponentBinderSpec extends HibernateGormDatastoreSpec { binder.bindComponentProperty(component, componentProperty, currentGrailsProp, root, "address", table, mappings) then: - 1 * enumTypeBinder.bindEnumType(currentGrailsProp, MyEnum, _ as BasicValue, "address_type_col") + 1 * enumTypeBinder.bindEnumType(currentGrailsProp, MyEnum, table, "address") 0 * componentUpdater.updateComponent(_, _, _, _) } 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 9fc50fc3db..4d8f432b47 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 @@ -3,7 +3,11 @@ package org.grails.orm.hibernate.cfg.domainbinding import grails.gorm.specs.HibernateGormDatastoreSpec import grails.persistence.Entity import org.grails.datastore.mapping.model.PersistentProperty +import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty import org.grails.orm.hibernate.cfg.IdentityEnumType +import org.grails.orm.hibernate.cfg.domainbinding.util.BackticksRemover +import org.grails.orm.hibernate.cfg.domainbinding.util.ColumnNameForPropertyAndPathFetcher +import org.grails.orm.hibernate.cfg.domainbinding.util.DefaultColumnNameFetcher import org.hibernate.engine.spi.SharedSessionContractImplementor import org.hibernate.mapping.BasicValue import org.hibernate.mapping.Column @@ -31,7 +35,16 @@ class EnumTypeBinderSpec extends HibernateGormDatastoreSpec { def columnBinder = Mock(ColumnConfigToColumnBinder) @Subject - EnumTypeBinder binder = new EnumTypeBinder(indexBinder, columnBinder) + EnumTypeBinder binder + + def setup() { + def grailsDomainBinder = getGrailsDomainBinder() + def metadataBuildingContext = grailsDomainBinder.getMetadataBuildingContext() + 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) + } @@ -122,6 +135,24 @@ class EnumTypeBinderSpec extends HibernateGormDatastoreSpec { Person02 | 1 } + def "should create BasicValue and bind enum type"() { + given: "A root entity and its enum property" + def grailsDomainBinder = getGrailsDomainBinder() + def owner = createPersistentEntity(Person01, grailsDomainBinder) + PersistentProperty property = owner.getPropertyByName("status") + def table = new Table("person") + + when: "the enum is bound using the new signature" + def result = binder.bindEnumType(property as GrailsHibernatePersistentProperty, Status01, table, "") + + then: "a BasicValue is returned and bound correctly" + result instanceof BasicValue + result.getTable() == table + result.getTypeName() == HibernateLegacyEnumType.class.getName() + result.getColumns().size() == 1 + result.getColumns()[0].getName() == "status" + } + } 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 11a16fab9f..ff8665247e 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 @@ -59,7 +59,7 @@ class GrailsPropertyBinderSpec extends HibernateGormDatastoreSpec { ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher = new ColumnNameForPropertyAndPathFetcher(namingStrategy, defaultColumnNameFetcher, backticksRemover) CollectionHolder collectionHolder = new CollectionHolder(metadataBuildingContext) SimpleValueBinder simpleValueBinder = new SimpleValueBinder(namingStrategy, jdbcEnvironment) - EnumTypeBinder enumTypeBinderToUse = new EnumTypeBinder() + EnumTypeBinder enumTypeBinderToUse = new EnumTypeBinder(metadataBuildingContext, columnNameForPropertyAndPathFetcher) SimpleValueColumnFetcher simpleValueColumnFetcher = new SimpleValueColumnFetcher() CompositeIdentifierToManyToOneBinder compositeIdentifierToManyToOneBinder = new CompositeIdentifierToManyToOneBinder( new org.grails.orm.hibernate.cfg.domainbinding.util.ForeignKeyColumnCountCalculator(), @@ -80,7 +80,8 @@ class GrailsPropertyBinderSpec extends HibernateGormDatastoreSpec { enumTypeBinderToUse, manyToOneBinder, compositeIdentifierToManyToOneBinder, - simpleValueColumnFetcher + simpleValueColumnFetcher, + columnNameForPropertyAndPathFetcher ) PropertyFromValueCreator propertyFromValueCreator = new PropertyFromValueCreator() ComponentUpdater componentUpdater = new ComponentUpdater(propertyFromValueCreator) diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ListSecondPassBinderSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ListSecondPassBinderSpec.groovy index 3a74ef261a..bf981f2753 100644 --- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ListSecondPassBinderSpec.groovy +++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ListSecondPassBinderSpec.groovy @@ -54,7 +54,7 @@ class ListSecondPassBinderSpec extends HibernateGormDatastoreSpec { ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher = new ColumnNameForPropertyAndPathFetcher(namingStrategy, defaultColumnNameFetcher, backticksRemover) CollectionHolder collectionHolder = new CollectionHolder(metadataBuildingContext) SimpleValueBinder simpleValueBinder = new SimpleValueBinder(namingStrategy, jdbcEnvironment) - EnumTypeBinder enumTypeBinderToUse = new EnumTypeBinder() + EnumTypeBinder enumTypeBinderToUse = new EnumTypeBinder(metadataBuildingContext, columnNameForPropertyAndPathFetcher) SimpleValueColumnFetcher simpleValueColumnFetcher = new SimpleValueColumnFetcher() CompositeIdentifierToManyToOneBinder compositeIdentifierToManyToOneBinder = new CompositeIdentifierToManyToOneBinder( new org.grails.orm.hibernate.cfg.domainbinding.util.ForeignKeyColumnCountCalculator(), @@ -75,7 +75,8 @@ class ListSecondPassBinderSpec extends HibernateGormDatastoreSpec { enumTypeBinderToUse, manyToOneBinder, compositeIdentifierToManyToOneBinder, - simpleValueColumnFetcher + simpleValueColumnFetcher, + columnNameForPropertyAndPathFetcher ) PropertyFromValueCreator propertyFromValueCreator = new PropertyFromValueCreator() ComponentUpdater componentUpdater = new ComponentUpdater(propertyFromValueCreator) diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/MapSecondPassBinderSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/MapSecondPassBinderSpec.groovy index d703278360..6c17a3e478 100644 --- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/MapSecondPassBinderSpec.groovy +++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/MapSecondPassBinderSpec.groovy @@ -54,7 +54,7 @@ class MapSecondPassBinderSpec extends HibernateGormDatastoreSpec { ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher = new ColumnNameForPropertyAndPathFetcher(namingStrategy, defaultColumnNameFetcher, backticksRemover) CollectionHolder collectionHolder = new CollectionHolder(metadataBuildingContext) SimpleValueBinder simpleValueBinder = new SimpleValueBinder(namingStrategy, jdbcEnvironment) - EnumTypeBinder enumTypeBinderToUse = new EnumTypeBinder() + EnumTypeBinder enumTypeBinderToUse = new EnumTypeBinder(metadataBuildingContext, columnNameForPropertyAndPathFetcher) SimpleValueColumnFetcher simpleValueColumnFetcher = new SimpleValueColumnFetcher() CompositeIdentifierToManyToOneBinder compositeIdentifierToManyToOneBinder = new CompositeIdentifierToManyToOneBinder( new org.grails.orm.hibernate.cfg.domainbinding.util.ForeignKeyColumnCountCalculator(), @@ -75,7 +75,8 @@ class MapSecondPassBinderSpec extends HibernateGormDatastoreSpec { enumTypeBinderToUse, manyToOneBinder, compositeIdentifierToManyToOneBinder, - simpleValueColumnFetcher + simpleValueColumnFetcher, + columnNameForPropertyAndPathFetcher ) PropertyFromValueCreator propertyFromValueCreator = new PropertyFromValueCreator() ComponentUpdater componentUpdater = new ComponentUpdater(propertyFromValueCreator)
