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
The following commit(s) were added to refs/heads/8.0.x-hibernate7-dev by this
push:
new 407fdc8cca hibernate 7: Refactoring CollectionBinder
407fdc8cca is described below
commit 407fdc8cca644189abf77c0d0e3d69ff07b6cd6a
Author: Walter Duque de Estrada <[email protected]>
AuthorDate: Sun Mar 15 00:05:43 2026 -0500
hibernate 7: Refactoring CollectionBinder
---
.../cfg/domainbinding/binder/CollectionBinder.java | 7 ++++---
.../cfg/domainbinding/hibernate/HibernateBasicProperty.java | 11 +++++++++++
.../hibernate/HibernateEmbeddedCollectionProperty.java | 11 +++++++++++
.../hibernate/HibernateManyToManyProperty.java | 10 ++++++++++
.../domainbinding/hibernate/HibernateOneToManyProperty.java | 10 ++++++++++
.../domainbinding/hibernate/HibernateToManyProperty.java | 4 ++++
.../secondpass/CollectionSecondPassBinder.java | 2 --
.../cfg/domainbinding/secondpass/ListSecondPass.java | 13 +++----------
.../cfg/domainbinding/secondpass/ListSecondPassBinder.java | 2 +-
.../cfg/domainbinding/secondpass/MapSecondPass.java | 13 +++----------
.../cfg/domainbinding/secondpass/MapSecondPassBinder.java | 4 +---
.../cfg/domainbinding/secondpass/SetSecondPass.java | 13 +++----------
.../domainbinding/secondpass/MapSecondPassBinderSpec.groovy | 7 +++----
13 files changed, 64 insertions(+), 43 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 b3c13eab4f..bb96a1df23 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
@@ -141,6 +141,7 @@ public class CollectionBinder {
public Collection bindCollection(HibernateToManyProperty property,
PersistentClass owner, String path) {
CollectionType collectionType =
collectionHolder.get(property.getType());
Collection collection = collectionType.create(property, owner);
+ property.setCollection(collection);
// set role
String propertyName = getNameForPropertyAndPath(property, path);
@@ -183,11 +184,11 @@ public class CollectionBinder {
// set up second pass
if (collection instanceof org.hibernate.mapping.List) {
- mappings.addSecondPass(new ListSecondPass(listSecondPassBinder,
property, mappings, collection));
+ mappings.addSecondPass(new ListSecondPass(listSecondPassBinder,
property));
} else if (collection instanceof org.hibernate.mapping.Map) {
- mappings.addSecondPass(new MapSecondPass(mapSecondPassBinder,
property, mappings, collection));
+ mappings.addSecondPass(new MapSecondPass(mapSecondPassBinder,
property));
} else { // Collection -> Bag
- mappings.addSecondPass(new
SetSecondPass(collectionSecondPassBinder, property, mappings, collection));
+ mappings.addSecondPass(new
SetSecondPass(collectionSecondPassBinder, property));
}
mappings.addCollectionBinding(collection);
return collection;
diff --git
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateBasicProperty.java
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateBasicProperty.java
index 78a3d5ea39..eb1893c603 100644
---
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateBasicProperty.java
+++
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateBasicProperty.java
@@ -20,14 +20,25 @@ package
org.grails.orm.hibernate.cfg.domainbinding.hibernate;
import java.beans.PropertyDescriptor;
+import org.hibernate.mapping.Collection;
+
import org.grails.datastore.mapping.model.MappingContext;
import org.grails.datastore.mapping.model.types.mapping.BasicWithMapping;
+import org.grails.orm.hibernate.cfg.ColumnConfig;
import org.grails.orm.hibernate.cfg.PropertyConfig;
/** Hibernate implementation of {@link
org.grails.datastore.mapping.model.types.Basic} */
public class HibernateBasicProperty extends BasicWithMapping<PropertyConfig>
implements HibernateToManyProperty {
+ private Collection collection;
public HibernateBasicProperty(
GrailsHibernatePersistentEntity entity, MappingContext context,
PropertyDescriptor property) {
super(entity, context, property);
}
+
+ public Collection getCollection() {
+ return collection;
+ }
+ public void setCollection(Collection collection) {
+ this.collection = collection;
+ }
}
diff --git
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateEmbeddedCollectionProperty.java
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateEmbeddedCollectionProperty.java
index a01105432c..6a631888cb 100644
---
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateEmbeddedCollectionProperty.java
+++
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateEmbeddedCollectionProperty.java
@@ -20,6 +20,8 @@ package org.grails.orm.hibernate.cfg.domainbinding.hibernate;
import java.beans.PropertyDescriptor;
+import org.hibernate.mapping.Collection;
+
import org.grails.datastore.mapping.model.MappingContext;
import org.grails.datastore.mapping.model.PersistentEntity;
import
org.grails.datastore.mapping.model.types.mapping.EmbeddedCollectionWithMapping;
@@ -30,8 +32,17 @@ import org.grails.orm.hibernate.cfg.PropertyConfig;
*/
public class HibernateEmbeddedCollectionProperty extends
EmbeddedCollectionWithMapping<PropertyConfig>
implements HibernateToManyProperty {
+
+ private Collection collection;
public HibernateEmbeddedCollectionProperty(
PersistentEntity entity, MappingContext context,
PropertyDescriptor property) {
super(entity, context, property);
}
+
+ public Collection getCollection() {
+ return collection;
+ }
+ public void setCollection(Collection collection) {
+ this.collection = collection;
+ }
}
diff --git
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateManyToManyProperty.java
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateManyToManyProperty.java
index 80be615d83..c621840b16 100644
---
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateManyToManyProperty.java
+++
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateManyToManyProperty.java
@@ -20,6 +20,8 @@ package org.grails.orm.hibernate.cfg.domainbinding.hibernate;
import java.beans.PropertyDescriptor;
+import org.hibernate.mapping.Collection;
+
import org.grails.datastore.mapping.model.MappingContext;
import org.grails.datastore.mapping.model.PersistentEntity;
import org.grails.datastore.mapping.model.types.mapping.ManyToManyWithMapping;
@@ -28,6 +30,7 @@ import org.grails.orm.hibernate.cfg.PropertyConfig;
/** Hibernate implementation of {@link
org.grails.datastore.mapping.model.types.ManyToMany} */
public class HibernateManyToManyProperty extends
ManyToManyWithMapping<PropertyConfig>
implements HibernateToManyProperty {
+ private Collection collection;
public HibernateManyToManyProperty(PersistentEntity entity, MappingContext
context, PropertyDescriptor property) {
super(entity, context, property);
}
@@ -46,4 +49,11 @@ public class HibernateManyToManyProperty extends
ManyToManyWithMapping<PropertyC
public boolean isAssociationColumnNullable() {
return false;
}
+
+ public Collection getCollection() {
+ return collection;
+ }
+ public void setCollection(Collection collection) {
+ this.collection = collection;
+ }
}
diff --git
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateOneToManyProperty.java
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateOneToManyProperty.java
index 8c43e60c0a..7c88718418 100644
---
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateOneToManyProperty.java
+++
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateOneToManyProperty.java
@@ -20,6 +20,8 @@ package org.grails.orm.hibernate.cfg.domainbinding.hibernate;
import java.beans.PropertyDescriptor;
+import org.hibernate.mapping.Collection;
+
import org.grails.datastore.mapping.model.MappingContext;
import org.grails.datastore.mapping.model.PersistentEntity;
import org.grails.datastore.mapping.model.types.mapping.OneToManyWithMapping;
@@ -28,6 +30,7 @@ import org.grails.orm.hibernate.cfg.PropertyConfig;
/** Hibernate implementation of {@link
org.grails.datastore.mapping.model.types.OneToMany} */
public class HibernateOneToManyProperty extends
OneToManyWithMapping<PropertyConfig>
implements HibernateToManyProperty {
+ private Collection collection;
public HibernateOneToManyProperty(PersistentEntity entity, MappingContext
context, PropertyDescriptor property) {
super(entity, context, property);
}
@@ -40,4 +43,11 @@ public class HibernateOneToManyProperty extends
OneToManyWithMapping<PropertyCon
public String getReferencedEntityName() {
return getHibernateAssociatedEntity().getName();
}
+
+ public Collection getCollection() {
+ return collection;
+ }
+ public void setCollection(Collection collection) {
+ this.collection = collection;
+ }
}
diff --git
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateToManyProperty.java
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateToManyProperty.java
index 9c29cbcfb2..8c1bb50e50 100644
---
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateToManyProperty.java
+++
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/hibernate/HibernateToManyProperty.java
@@ -22,6 +22,7 @@ import java.util.Map;
import java.util.Optional;
import org.hibernate.FetchMode;
+import org.hibernate.mapping.Collection;
import org.hibernate.mapping.IndexedCollection;
import org.springframework.util.StringUtils;
@@ -128,4 +129,7 @@ public interface HibernateToManyProperty extends
PropertyWithMapping<PropertyCon
.getSimpleName())
+ GrailsDomainBinder.FOREIGN_KEY_SUFFIX);
}
+
+ void setCollection(Collection collection);
+ Collection getCollection();
}
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 cb0e360ecb..f097040a8f 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
@@ -24,7 +24,6 @@ import java.util.Map;
import jakarta.annotation.Nonnull;
import org.hibernate.MappingException;
-import org.hibernate.boot.spi.InFlightMetadataCollector;
import org.hibernate.mapping.*;
import org.hibernate.mapping.Collection;
@@ -68,7 +67,6 @@ public class CollectionSecondPassBinder {
/** Bind collection second pass. */
public void bindCollectionSecondPass(
@Nonnull HibernateToManyProperty property,
- @Nonnull InFlightMetadataCollector mappings,
Map<?, ?> persistentClasses,
@Nonnull Collection collection) {
diff --git
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPass.java
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPass.java
index ac79e90999..d1dee8d2e6 100644
---
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPass.java
+++
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPass.java
@@ -25,7 +25,6 @@ import jakarta.annotation.Nonnull;
import org.hibernate.MappingException;
import org.hibernate.boot.spi.InFlightMetadataCollector;
-import org.hibernate.mapping.Collection;
import
org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateToManyProperty;
@@ -36,23 +35,17 @@ public class ListSecondPass implements
org.hibernate.boot.spi.SecondPass, Grails
private final ListSecondPassBinder listSecondPassBinder;
protected final HibernateToManyProperty property;
- protected final @Nonnull InFlightMetadataCollector mappings;
- protected final Collection collection;
public ListSecondPass(
ListSecondPassBinder listSecondPassBinder,
- HibernateToManyProperty property,
- @Nonnull InFlightMetadataCollector mappings,
- Collection coll) {
+ HibernateToManyProperty property) {
this.listSecondPassBinder = listSecondPassBinder;
this.property = property;
- this.mappings = mappings;
- this.collection = coll;
}
@Override
public void doSecondPass(Map persistentClasses) throws MappingException {
- listSecondPassBinder.bindListSecondPass(property, persistentClasses,
(org.hibernate.mapping.List) collection);
- createCollectionKeys(collection);
+ listSecondPassBinder.bindListSecondPass(property, persistentClasses,
(org.hibernate.mapping.List) property.getCollection());
+ createCollectionKeys(property.getCollection());
}
}
diff --git
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPassBinder.java
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPassBinder.java
index bb5871eccf..e7faee3a26 100644
---
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPassBinder.java
+++
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/ListSecondPassBinder.java
@@ -71,7 +71,7 @@ public class ListSecondPassBinder {
public void bindListSecondPass(
@Nonnull HibernateToManyProperty property, Map<?, ?>
persistentClasses, @Nonnull List list) {
- collectionSecondPassBinder.bindCollectionSecondPass(property,
mappings, persistentClasses, list);
+ collectionSecondPassBinder.bindCollectionSecondPass(property,
persistentClasses, list);
String columnName = property.getIndexColumnName(namingStrategy);
final boolean isManyToMany = property instanceof
HibernateManyToManyProperty;
diff --git
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPass.java
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPass.java
index 349328673f..1ba1e856a0 100644
---
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPass.java
+++
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPass.java
@@ -25,7 +25,6 @@ import jakarta.annotation.Nonnull;
import org.hibernate.MappingException;
import org.hibernate.boot.spi.InFlightMetadataCollector;
-import org.hibernate.mapping.Collection;
import
org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateToManyProperty;
@@ -36,24 +35,18 @@ public class MapSecondPass implements
org.hibernate.boot.spi.SecondPass, GrailsS
private final MapSecondPassBinder mapSecondPassBinder;
protected final HibernateToManyProperty property;
- protected final @Nonnull InFlightMetadataCollector mappings;
- protected final Collection collection;
public MapSecondPass(
MapSecondPassBinder mapSecondPassBinder,
- HibernateToManyProperty property,
- @Nonnull InFlightMetadataCollector mappings,
- @Nonnull Collection coll) {
+ HibernateToManyProperty property) {
this.mapSecondPassBinder = mapSecondPassBinder;
this.property = property;
- this.mappings = mappings;
- this.collection = coll;
}
@Override
public void doSecondPass(Map persistentClasses) throws MappingException {
mapSecondPassBinder.bindMapSecondPass(
- property, mappings, persistentClasses,
(org.hibernate.mapping.Map) collection);
- createCollectionKeys(collection);
+ property, persistentClasses, (org.hibernate.mapping.Map)
property.getCollection());
+ createCollectionKeys(property.getCollection());
}
}
diff --git
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPassBinder.java
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPassBinder.java
index ddb97ded74..761fe0c7f0 100644
---
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPassBinder.java
+++
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/MapSecondPassBinder.java
@@ -24,7 +24,6 @@ import java.util.Map;
import jakarta.annotation.Nonnull;
import org.hibernate.MappingException;
-import org.hibernate.boot.spi.InFlightMetadataCollector;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.mapping.BasicValue;
import org.hibernate.mapping.Column;
@@ -67,10 +66,9 @@ public class MapSecondPassBinder {
public void bindMapSecondPass(
@Nonnull HibernateToManyProperty property,
- @Nonnull InFlightMetadataCollector mappings,
Map<?, ?> persistentClasses,
@Nonnull org.hibernate.mapping.Map map) {
- collectionSecondPassBinder.bindCollectionSecondPass(property,
mappings, persistentClasses, map);
+ collectionSecondPassBinder.bindCollectionSecondPass(property,
persistentClasses, map);
String type = property.getIndexColumnType("string");
String columnName1 = property.getIndexColumnName(namingStrategy);
diff --git
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/SetSecondPass.java
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/SetSecondPass.java
index 1a09e95b04..40a500ee27 100644
---
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/SetSecondPass.java
+++
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/SetSecondPass.java
@@ -25,7 +25,6 @@ import jakarta.annotation.Nonnull;
import org.hibernate.MappingException;
import org.hibernate.boot.spi.InFlightMetadataCollector;
-import org.hibernate.mapping.Collection;
import
org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateToManyProperty;
@@ -43,22 +42,16 @@ public class SetSecondPass implements
org.hibernate.boot.spi.SecondPass, GrailsS
private final CollectionSecondPassBinder collectionSecondPassBinder;
protected final HibernateToManyProperty property;
- protected final @Nonnull InFlightMetadataCollector mappings;
- protected final Collection collection;
public SetSecondPass(
CollectionSecondPassBinder collectionSecondPassBinder,
- HibernateToManyProperty property,
- @Nonnull InFlightMetadataCollector mappings,
- Collection coll) {
+ HibernateToManyProperty property) {
this.collectionSecondPassBinder = collectionSecondPassBinder;
this.property = property;
- this.mappings = mappings;
- this.collection = coll;
}
public void doSecondPass(Map persistentClasses) throws MappingException {
- collectionSecondPassBinder.bindCollectionSecondPass(property,
mappings, persistentClasses, collection);
- createCollectionKeys(collection);
+ collectionSecondPassBinder.bindCollectionSecondPass(property,
persistentClasses, property.getCollection());
+ createCollectionKeys(property.getCollection());
}
}
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 63fc272fa5..7c77072f58 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
@@ -2,9 +2,8 @@ package org.grails.orm.hibernate.cfg.domainbinding.secondpass
import grails.gorm.specs.HibernateGormDatastoreSpec
import
org.grails.orm.hibernate.cfg.domainbinding.hibernate.GrailsHibernatePersistentEntity
-import
org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernatePersistentProperty
import
org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateToManyProperty
-import org.hibernate.mapping.OneToMany
+
import org.hibernate.mapping.RootClass
import org.hibernate.boot.spi.MetadataBuildingContext
import org.grails.orm.hibernate.cfg.PersistentEntityNamingStrategy
@@ -199,7 +198,7 @@ class MapSecondPassBinderSpec extends
HibernateGormDatastoreSpec {
map.setCollectionTable(rootClass.getTable())
when:
- mapBinder.bindMapSecondPass(booksProp, collector, persistentClasses,
map)
+ mapBinder.bindMapSecondPass(booksProp, persistentClasses, map)
then:
noExceptionThrown()
@@ -251,7 +250,7 @@ class MapSecondPassBinderSpec extends
HibernateGormDatastoreSpec {
map.setElement(element)
when:
- mapBinder.bindMapSecondPass(booksProp, collector, persistentClasses,
map)
+ mapBinder.bindMapSecondPass(booksProp, persistentClasses, map)
then:
noExceptionThrown()