You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by bo...@apache.org on 2026/03/17 03:27:01 UTC
(grails-core) 03/05: hibernate 7 refactoring EnumTypeBinder
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 bb3c44fcc72ede27bbb46bf87b1a4685cfc50e7b
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Sun Mar 15 18:11:52 2026 -0500
hibernate 7 refactoring EnumTypeBinder
---
.../cfg/domainbinding/binder/ClassPropertiesBinder.java | 1 -
.../cfg/domainbinding/binder/EnumTypeBinder.java | 4 ++--
.../cfg/domainbinding/binder/GrailsPropertyBinder.java | 2 +-
.../secondpass/BasicCollectionElementBinder.java | 2 +-
.../hibernate/cfg/domainbinding/EnumTypeBinderSpec.groovy | 8 ++++----
.../secondpass/BasicCollectionElementBinderSpec.groovy | 15 +++++++++++----
6 files changed, 19 insertions(+), 13 deletions(-)
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/ClassPropertiesBinder.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/ClassPropertiesBinder.java
index 0750d96e0b..6290290316 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/ClassPropertiesBinder.java
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/ClassPropertiesBinder.java
@@ -61,7 +61,6 @@ public class ClassPropertiesBinder {
public void bindClassProperties(HibernatePersistentEntity hibernatePersistentEntity) {
PersistentClass persistentClass = hibernatePersistentEntity.getPersistentClass();
getTable(persistentClass).setComment(hibernatePersistentEntity.getComment());
- Table table = hibernatePersistentEntity.getPersistentClass().getTable();
for (HibernatePersistentProperty currentGrailsProp : hibernatePersistentEntity.getPersistentPropertiesToBind()) {
Value value = grailsPropertyBinder.bindProperty(
currentGrailsProp, null, GrailsDomainBinder.EMPTY_PATH);
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 9dc940fdae..0f4cfd99e2 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
@@ -72,7 +72,7 @@ public class EnumTypeBinder {
private static final Logger LOG = LoggerFactory.getLogger(EnumTypeBinder.class);
public BasicValue bindEnumType(
- @Nonnull HibernateEnumProperty property, Class<?> propertyType, Table table, String path) {
+ @Nonnull HibernateEnumProperty property, Class<?> propertyType, String path) {
String columnName = columnNameForPropertyAndPathFetcher.getColumnNameForPropertyAndPath(property, path, null);
BasicValue simpleValue = new BasicValue(metadataBuildingContext, property.getTable());
bindEnumType(property, propertyType, simpleValue, columnName);
@@ -80,7 +80,7 @@ public class EnumTypeBinder {
}
public BasicValue bindEnumTypeForColumn(
- @Nonnull HibernateToManyProperty property, Class<?> propertyType, Table table, @Nonnull String columnName) {
+ @Nonnull HibernateToManyProperty property, Class<?> propertyType, @Nonnull String columnName) {
BasicValue simpleValue = new BasicValue(metadataBuildingContext, property.getTable());
bindEnumType(property, propertyType, simpleValue, columnName);
return simpleValue;
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 ef6db12b79..d7577fd1b8 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
@@ -75,7 +75,7 @@ public class GrailsPropertyBinder {
// 1. Create Value and apply binders (consolidated block)
if (currentGrailsProp instanceof HibernateEnumProperty hibernateEnumProperty) {
- value = enumTypeBinder.bindEnumType(hibernateEnumProperty, currentGrailsProp.getType(), table, path);
+ value = enumTypeBinder.bindEnumType(hibernateEnumProperty, currentGrailsProp.getType(), path);
} else if (currentGrailsProp instanceof HibernateOneToOneProperty oneToOne
&& oneToOne.isValidHibernateOneToOne()) {
value = oneToOneBinder.bindOneToOne(oneToOne, path);
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 77ba8313ac..80870f4fa8 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
@@ -81,7 +81,7 @@ public class BasicCollectionElementBinder {
: new BackticksRemover().apply(prop) + UNDERSCORE + new BackticksRemover().apply(clazz);
}
if (isEnum) {
- return enumTypeBinder.bindEnumTypeForColumn(property, referencedType, collection.getCollectionTable(), columnName);
+ return enumTypeBinder.bindEnumTypeForColumn(property, referencedType, columnName);
} else {
String typeName = property.getTypeName(referencedType);
BasicValue element = simpleValueColumnBinder.bindSimpleValue(
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 2c7d7f3c3e..68cae61fa4 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
@@ -68,7 +68,7 @@ class EnumTypeBinderSpec extends HibernateGormDatastoreSpec {
PersistentProperty property = setupEntity(clazz, table)
when: "the enum is bound"
- def simpleValue = binder.bindEnumTypeForColumn(property as HibernateToManyProperty, Status01, table, "status_col")
+ def simpleValue = binder.bindEnumTypeForColumn(property as HibernateToManyProperty, Status01, "status_col")
then: "the correct hibernate type is set"
simpleValue.getTypeName() == expectedHibernateType
@@ -95,7 +95,7 @@ class EnumTypeBinderSpec extends HibernateGormDatastoreSpec {
PersistentProperty property = setupEntity(clazz, table)
when: "the enum is bound"
- def simpleValue = binder.bindEnumTypeForColumn(property as HibernateToManyProperty, Status01, table, columnName)
+ def simpleValue = binder.bindEnumTypeForColumn(property as HibernateToManyProperty, Status01, columnName)
then:
table.columns.size() == 1
@@ -121,7 +121,7 @@ class EnumTypeBinderSpec extends HibernateGormDatastoreSpec {
PersistentProperty property = setupEntity(clazz, table)
when: "the enum is bound"
- binder.bindEnumTypeForColumn(property as HibernateToManyProperty, Status01, table, columnName)
+ binder.bindEnumTypeForColumn(property as HibernateToManyProperty, Status01, columnName)
then: "the index and column binders are invoked the correct number of times"
times * indexBinder.bindIndex(columnName, _ as Column, _, table)
@@ -139,7 +139,7 @@ class EnumTypeBinderSpec extends HibernateGormDatastoreSpec {
PersistentProperty property = setupEntity(Person01, table)
when: "the enum is bound using the new signature"
- def result = binder.bindEnumType(property as HibernateEnumProperty, Status01, table, "")
+ def result = binder.bindEnumType(property as HibernateEnumProperty, Status01, "")
then: "a BasicValue is returned and bound correctly"
result instanceof BasicValue
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BasicCollectionElementBinderSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BasicCollectionElementBinderSpec.groovy
index 4e3e35b933..f06343e511 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BasicCollectionElementBinderSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BasicCollectionElementBinderSpec.groovy
@@ -12,7 +12,6 @@ import org.hibernate.mapping.Collection
import org.hibernate.mapping.RootClass
import org.hibernate.mapping.Set
import org.hibernate.mapping.Table
-import org.hibernate.type.spi.TypeConfiguration
import spock.lang.Subject
class BasicCollectionElementBinderSpec extends HibernateGormDatastoreSpec {
@@ -20,10 +19,13 @@ class BasicCollectionElementBinderSpec extends HibernateGormDatastoreSpec {
@Subject
BasicCollectionElementBinder binder
+ // Mock the collaborator
EnumTypeBinder enumTypeBinder = Mock(EnumTypeBinder)
void setup() {
def domainBinder = getGrailsDomainBinder()
+
+ // Inject the mocked enumTypeBinder into the Subject
binder = new BasicCollectionElementBinder(
domainBinder.metadataBuildingContext,
domainBinder.namingStrategy,
@@ -55,7 +57,8 @@ class BasicCollectionElementBinderSpec extends HibernateGormDatastoreSpec {
then:
element != null
element.getColumnSpan() > 0
- 0 * enumTypeBinder._
+ // Ensure the enum binder is NOT called for a String collection
+ 0 * enumTypeBinder.bindEnumTypeForColumn(_, _, _)
}
void "bind delegates to enumTypeBinder for enum collection"() {
@@ -66,12 +69,16 @@ class BasicCollectionElementBinderSpec extends HibernateGormDatastoreSpec {
property.setCollection(collection)
+ // Create a dummy BasicValue to return from the mock
+ def mockValue = new BasicValue(getGrailsDomainBinder().metadataBuildingContext, collection.getCollectionTable())
+
when:
BasicValue element = binder.bind(property)
then:
element != null
- 1 * enumTypeBinder.bindEnumTypeForColumn(property, BCEBStatus, collection.getCollectionTable(), _) >> Mock(BasicValue)
+ // Corrected: Match the 3-argument signature (Property, Class, String)
+ 1 * enumTypeBinder.bindEnumTypeForColumn(property, BCEBStatus, _ as String) >> mockValue
}
}
@@ -83,4 +90,4 @@ class BCEBAuthor {
java.util.Set<String> tags
java.util.Set<BCEBStatus> statuses
static hasMany = [tags: String, statuses: BCEBStatus]
-}
+}
\ No newline at end of file