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/02/06 19:09:51 UTC
(grails-core) 04/19: remove PersistentPropertyToPropertyConfig.java
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 e04d135940f3938b56cd92b8a7253a1b8d5df435
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Mon Feb 2 21:21:52 2026 -0600
remove PersistentPropertyToPropertyConfig.java
---
.../orm/hibernate/cfg/GrailsDomainBinder.java | 60 +++++----------
.../cfg/GrailsHibernatePersistentEntity.java | 2 +
.../cfg/GrailsHibernatePersistentProperty.java | 20 +++++
.../cfg/domainbinding/CascadeBehaviorFetcher.java | 3 +-
.../hibernate/cfg/domainbinding/ColumnBinder.java | 13 +---
.../ColumnNameForPropertyAndPathFetcher.java | 9 +--
.../cfg/domainbinding/ComponentPropertyBinder.java | 19 ++---
.../CompositeIdentifierToManyToOneBinder.java | 7 +-
.../cfg/domainbinding/CreateKeyForProps.java | 9 +--
.../domainbinding/DefaultColumnNameFetcher.java | 3 +-
.../cfg/domainbinding/EnumTypeBinder.java | 2 +-
.../cfg/domainbinding/ManyToOneBinder.java | 19 ++---
.../cfg/domainbinding/ManyToOneValuesBinder.java | 14 ++--
.../cfg/domainbinding/OneToOneBinder.java | 13 +---
.../PersistentPropertyToPropertyConfig.java | 18 -----
.../cfg/domainbinding/PropertyBinder.java | 12 ++-
.../cfg/domainbinding/SimpleValueBinder.java | 19 +----
.../cfg/domainbinding/TableForManyCalculator.java | 9 +--
.../cfg/domainbinding/UserTypeFetcher.java | 9 +--
.../cfg/domainbinding/ColumnBinderSpec.groovy | 87 ++++++++--------------
.../ColumnNameForPropertyAndPathFetcherSpec.groovy | 17 ++---
.../ComponentPropertyBinderSpec.groovy | 56 ++++++++------
...CompositeIdentifierToManyToOneBinderSpec.groovy | 23 +++---
.../cfg/domainbinding/CreateKeyForPropsSpec.groovy | 30 ++++----
.../cfg/domainbinding/ManyToOneBinderSpec.groovy | 51 ++++++-------
.../domainbinding/ManyToOneValuesBinderSpec.groovy | 10 +--
.../cfg/domainbinding/OneToOneBinderSpec.groovy | 41 +++++-----
.../PersistentPropertyToPropertyConfigSpec.groovy | 38 ----------
.../cfg/domainbinding/PropertyBinderSpec.groovy | 41 +++++-----
.../cfg/domainbinding/SimpleValueBinderSpec.groovy | 30 +++++---
.../TableForManyCalculatorSpec.groovy | 12 +--
.../cfg/domainbinding/UserTypeFetcherSpec.groovy | 21 +++---
32 files changed, 291 insertions(+), 426 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 02167b324c..554ff3f01e 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
@@ -31,7 +31,6 @@ import org.grails.orm.hibernate.cfg.domainbinding.ClassBinder;
import org.grails.orm.hibernate.cfg.domainbinding.ColumnConfigToColumnBinder;
import org.grails.orm.hibernate.cfg.domainbinding.EnumTypeBinder;
import org.grails.orm.hibernate.cfg.domainbinding.NamingStrategyProvider;
-import org.grails.orm.hibernate.cfg.domainbinding.PersistentPropertyToPropertyConfig;
import org.grails.orm.hibernate.cfg.domainbinding.SimpleValueColumnBinder;
import org.grails.orm.hibernate.cfg.domainbinding.*;
import org.grails.orm.hibernate.cfg.domainbinding.collectionType.CollectionHolder;
@@ -91,7 +90,6 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
import java.util.Set;
import java.util.Optional;
import java.util.StringTokenizer;
@@ -262,7 +260,7 @@ public class GrailsDomainBinder
String type = getIndexColumnType(property, STRING_TYPE);
String columnName1 = getIndexColumnName(property, sessionFactoryBeanName);
new SimpleValueColumnBinder().bindSimpleValue(value, type, columnName1, true);
- PropertyConfig mappedForm = new PersistentPropertyToPropertyConfig().toPropertyConfig(property);
+ PropertyConfig mappedForm = ((GrailsHibernatePersistentProperty) property).getMappedForm();
if (mappedForm.getIndexColumn() != null) {
Column column = new SimpleValueColumnFetcher().getColumnForSimpleValue(value);
ColumnConfig columnConfig = getSingleColumnConfig(mappedForm.getIndexColumn());
@@ -411,7 +409,7 @@ public class GrailsDomainBinder
+ " -> "
+ collection.getCollectionTable().getName());
- PropertyConfig propConfig = new PersistentPropertyToPropertyConfig().toPropertyConfig(property);
+ PropertyConfig propConfig = ((GrailsHibernatePersistentProperty) property).getMappedForm();
PersistentEntity referenced = property.getAssociatedEntity();
if (StringUtils.hasText(propConfig.getSort())) {
@@ -753,7 +751,7 @@ public class GrailsDomainBinder
if (joinColumnMappingOptional.isPresent()) {
Column column = new SimpleValueColumnFetcher().getColumnForSimpleValue(element);
ColumnConfig columnConfig = joinColumnMappingOptional.get();
- final PropertyConfig mappedForm = new PersistentPropertyToPropertyConfig().toPropertyConfig(property);
+ final PropertyConfig mappedForm = ((GrailsHibernatePersistentProperty) property).getMappedForm();
new ColumnConfigToColumnBinder().bindColumnConfigToColumn(column, columnConfig, mappedForm);
}
}
@@ -791,7 +789,7 @@ public class GrailsDomainBinder
* @param manyToOne The inverse side
*/
private void bindUnidirectionalOneToManyInverseValues(ToMany property, ManyToOne manyToOne) {
- PropertyConfig config = new PersistentPropertyToPropertyConfig().toPropertyConfig(property);
+ PropertyConfig config = ((GrailsHibernatePersistentProperty) property).getMappedForm();
manyToOne.setIgnoreNotFound(config.getIgnoreNotFound());
final FetchMode fetch = config.getFetchMode();
if(!fetch.equals(FetchMode.JOIN)) {
@@ -985,7 +983,7 @@ public class GrailsDomainBinder
String propertyName = getNameForPropertyAndPath(property, path);
collection.setRole(qualify(property.getOwner().getName(), propertyName));
- PropertyConfig pc = new PersistentPropertyToPropertyConfig().toPropertyConfig(property);
+ PropertyConfig pc = ((GrailsHibernatePersistentProperty) property).getMappedForm();
// configure eager fetching
final FetchMode fetchMode = pc.getFetchMode();
if (fetchMode == FetchMode.JOIN) {
@@ -1056,7 +1054,7 @@ public class GrailsDomainBinder
Collection collection, Table ownerTable, String sessionFactoryBeanName) {
String owningTableSchema = ownerTable.getSchema();
- PropertyConfig config = new PersistentPropertyToPropertyConfig().toPropertyConfig(property);
+ PropertyConfig config = ((GrailsHibernatePersistentProperty) property).getMappedForm();
JoinTable jt = config.getJoinTable();
String s = new TableForManyCalculator(namingStrategy).calculateTableForMany(property, sessionFactoryBeanName);
@@ -1489,33 +1487,32 @@ public class GrailsDomainBinder
private void createClassProperties(@Nonnull GrailsHibernatePersistentEntity domainClass, PersistentClass persistentClass,
@Nonnull InFlightMetadataCollector mappings, String sessionFactoryBeanName) {
- Mapping gormMapping = domainClass.getMappedForm();
- Table table = persistentClass.getTable();
- table.setComment(gormMapping.getComment());
+
for (GrailsHibernatePersistentProperty currentGrailsProp : domainClass.getPersistentPropertiesToBind()) {
- bindProperty(persistentClass, mappings, sessionFactoryBeanName, currentGrailsProp, table, gormMapping);
+ bindProperty(persistentClass, mappings, sessionFactoryBeanName, currentGrailsProp);
}
- new NaturalIdentifierBinder().bindNaturalIdentifier(gormMapping, persistentClass);
+ new NaturalIdentifierBinder().bindNaturalIdentifier(domainClass.getMappedForm(), persistentClass);
}
private void bindProperty(PersistentClass persistentClass
, @NonNull InFlightMetadataCollector mappings
, String sessionFactoryBeanName
- , @Nonnull GrailsHibernatePersistentProperty currentGrailsProp
- , Table table
- , Mapping gormMapping) {
+ , @Nonnull GrailsHibernatePersistentProperty currentGrailsProp) {
if (LOG.isDebugEnabled()) {
LOG.debug("[GrailsDomainBinder] Binding persistent property [" + currentGrailsProp.getName() + "]");
}
+ Mapping gormMapping = currentGrailsProp.getHibernateOwner().getMappedForm();
+ Table table = persistentClass.getTable();
+ table.setComment(gormMapping.getComment());
Value value = null;
// see if it's a collection type
CollectionType collectionType = collectionHolder.get(currentGrailsProp.getType());
- Class<?> userType = getUserType(currentGrailsProp);
+ Class<?> userType = currentGrailsProp.getUserType();
// 1. Create Value
if (userType != null && !UserCollectionType.class.isAssignableFrom(userType)) {
@@ -1623,39 +1620,16 @@ public class GrailsDomainBinder
}
private String getIndexColumnName(PersistentProperty property, String sessionFactoryBeanName) {
- PropertyConfig pc = new PersistentPropertyToPropertyConfig().toPropertyConfig(property);
+ PropertyConfig pc = ((GrailsHibernatePersistentProperty) property).getMappedForm();
if (pc.getIndexColumn() != null && pc.getIndexColumn().getColumn() != null) {
return pc.getIndexColumn().getColumn();
}
return getNamingStrategy().resolveColumnName(property.getName()) + UNDERSCORE + IndexedCollection.DEFAULT_INDEX_COLUMN_NAME;
}
- private Class<?> getUserType(PersistentProperty currentGrailsProp) {
- Class<?> userType = null;
- PropertyConfig config = new PersistentPropertyToPropertyConfig().toPropertyConfig(currentGrailsProp);
- Object typeObj = config.getType();
- if (typeObj instanceof Class<?>) {
- userType = (Class<?>)typeObj;
- } else if (typeObj != null) {
- String typeName = typeObj.toString();
- try {
- userType = Class.forName(typeName, true, Thread.currentThread().getContextClassLoader());
- } catch (ClassNotFoundException e) {
- // only print a warning if the user type is in a package this excludes basic
- // types like string, int etc.
- if (typeName.indexOf(".")>-1) {
- if (LOG.isWarnEnabled()) {
- LOG.warn("UserType not found ", e);
- }
- }
- }
- }
- return userType;
- }
-
private String getIndexColumnType(@Nonnull PersistentProperty property, String defaultType) {
- PropertyConfig pc = new PersistentPropertyToPropertyConfig().toPropertyConfig(property);
+ PropertyConfig pc = ((GrailsHibernatePersistentProperty) property).getMappedForm();
if (pc.getIndexColumn() != null && pc.getIndexColumn().getType() != null) {
@@ -1673,7 +1647,7 @@ public class GrailsDomainBinder
}
private String getMapElementName(PersistentProperty property, String sessionFactoryBeanName) {
- PropertyConfig pc = new PersistentPropertyToPropertyConfig().toPropertyConfig(property);
+ PropertyConfig pc = ((GrailsHibernatePersistentProperty) property).getMappedForm();
if (hasJoinTableColumnNameMapping(pc)) {
return pc.getJoinTable().getColumn().getName();
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentEntity.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentEntity.java
index b0db1c066a..8c0f985476 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentEntity.java
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentEntity.java
@@ -29,6 +29,8 @@ public interface GrailsHibernatePersistentEntity extends PersistentEntity {
}
+
+
boolean forGrailsDomainMapping(String dataSourceName);
boolean usesConnectionSource(String dataSourceName);
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentProperty.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentProperty.java
index ba14306a4b..f9884d4017 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentProperty.java
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsHibernatePersistentProperty.java
@@ -18,4 +18,24 @@ public interface GrailsHibernatePersistentProperty extends PersistentProperty<Pr
.map(typeObj -> typeObj instanceof Class<?> clazz ? clazz.getName() : typeObj.toString())
.orElseGet(() -> mapping != null ? mapping.getTypeName(getType()) : null);
}
+
+ default HibernatePersistentEntity getHibernateOwner() {
+ return (HibernatePersistentEntity) getOwner();
+ }
+
+ default Class<?> getUserType() {
+ Object typeObj = getMappedForm().getType();
+ Class<?> userType = null;
+ if (typeObj instanceof Class<?>) {
+ userType = (Class<?>)typeObj;
+ } else if (typeObj != null) {
+ String typeName = typeObj.toString();
+ try {
+ userType = Class.forName(typeName, true, Thread.currentThread().getContextClassLoader());
+ } catch (ClassNotFoundException e) {
+
+ }
+ }
+ return userType;
+ };
}
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/CascadeBehaviorFetcher.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/CascadeBehaviorFetcher.java
index 2f4b02fc4d..7527076913 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/CascadeBehaviorFetcher.java
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/CascadeBehaviorFetcher.java
@@ -5,6 +5,7 @@ import org.grails.datastore.mapping.model.types.Association;
import org.grails.datastore.mapping.model.types.Basic;
import org.grails.datastore.mapping.model.types.Embedded;
import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentEntity;
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty;
import org.grails.orm.hibernate.cfg.Mapping;
import org.grails.orm.hibernate.cfg.PropertyConfig;
import org.hibernate.MappingException;
@@ -38,7 +39,7 @@ public class CascadeBehaviorFetcher {
}
private Optional<CascadeBehavior> getDefinedBehavior(PersistentProperty<?> grailsProperty) {
- return Optional.ofNullable(new PersistentPropertyToPropertyConfig().toPropertyConfig(grailsProperty))
+ return Optional.ofNullable(((GrailsHibernatePersistentProperty) grailsProperty).getMappedForm())
.map(PropertyConfig::getCascade)
.map(CascadeBehavior::fromString);
}
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/ColumnBinder.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/ColumnBinder.java
index 33dfcec26a..94a4a4cf29 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/ColumnBinder.java
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/ColumnBinder.java
@@ -1,7 +1,6 @@
package org.grails.orm.hibernate.cfg.domainbinding;
import org.hibernate.mapping.Column;
-import org.hibernate.mapping.Formula;
import org.hibernate.mapping.Table;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -14,6 +13,7 @@ import org.grails.datastore.mapping.model.types.OneToOne;
import org.grails.datastore.mapping.model.types.ToOne;
import org.grails.orm.hibernate.cfg.ColumnConfig;
import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentEntity;
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty;
import org.grails.orm.hibernate.cfg.Mapping;
import org.grails.orm.hibernate.cfg.PersistentEntityNamingStrategy;
import org.grails.orm.hibernate.cfg.PropertyConfig;
@@ -23,7 +23,6 @@ public class ColumnBinder {
private static final Logger LOG = LoggerFactory.getLogger(ColumnBinder.class);
private final ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher;
- private final PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig;
private final StringColumnConstraintsBinder stringColumnConstraintsBinder;
private final NumericColumnConstraintsBinder numericColumnConstraintsBinder;
private final CreateKeyForProps createKeyForProps;
@@ -35,14 +34,12 @@ public class ColumnBinder {
*/
public ColumnBinder(
ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher,
- PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig,
StringColumnConstraintsBinder stringColumnConstraintsBinder,
NumericColumnConstraintsBinder numericColumnConstraintsBinder,
CreateKeyForProps createKeyForProps,
UserTypeFetcher userTypeFetcher,
IndexBinder indexBinder) {
this.columnNameForPropertyAndPathFetcher = columnNameForPropertyAndPathFetcher;
- this.persistentPropertyToPropertyConfig = persistentPropertyToPropertyConfig;
this.stringColumnConstraintsBinder = stringColumnConstraintsBinder;
this.numericColumnConstraintsBinder = numericColumnConstraintsBinder;
this.createKeyForProps = createKeyForProps;
@@ -56,7 +53,6 @@ public class ColumnBinder {
public ColumnBinder(PersistentEntityNamingStrategy namingStrategy) {
this(
new ColumnNameForPropertyAndPathFetcher(namingStrategy),
- new PersistentPropertyToPropertyConfig(),
new StringColumnConstraintsBinder(),
new NumericColumnConstraintsBinder(),
new CreateKeyForProps(new ColumnNameForPropertyAndPathFetcher(namingStrategy)),
@@ -70,7 +66,6 @@ public class ColumnBinder {
*/
protected ColumnBinder() {
this.columnNameForPropertyAndPathFetcher = null;
- this.persistentPropertyToPropertyConfig = null;
this.stringColumnConstraintsBinder = null;
this.numericColumnConstraintsBinder = null;
this.createKeyForProps = null;
@@ -126,10 +121,10 @@ public class ColumnBinder {
// the column's length, precision, and scale
Class<?> type = property.getType();
if (type != null && (String.class.isAssignableFrom(type) || byte[].class.isAssignableFrom(type))) {
- mappedForm = persistentPropertyToPropertyConfig.toPropertyConfig(property);
+ mappedForm = ((GrailsHibernatePersistentProperty) property).getMappedForm();
stringColumnConstraintsBinder.bindStringColumnConstraints(column, mappedForm);
} else if (type != null && Number.class.isAssignableFrom(type)) {
- mappedForm = persistentPropertyToPropertyConfig.toPropertyConfig(property);
+ mappedForm = ((GrailsHibernatePersistentProperty) property).getMappedForm();
numericColumnConstraintsBinder.bindNumericColumnConstraints(column, cc, mappedForm);
}
}
@@ -153,7 +148,7 @@ public class ColumnBinder {
}
// Apply uniqueness last to ensure it isn't overridden by downstream binders
- PropertyConfig mappedFormFinal = persistentPropertyToPropertyConfig.toPropertyConfig(property);
+ PropertyConfig mappedFormFinal = ((GrailsHibernatePersistentProperty) property).getMappedForm();
column.setUnique(mappedFormFinal.isUnique() && !mappedFormFinal.isUniqueWithinGroup());
if (LOG.isDebugEnabled())
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/ColumnNameForPropertyAndPathFetcher.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/ColumnNameForPropertyAndPathFetcher.java
index 5f38f9d548..c41fd25cbc 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/ColumnNameForPropertyAndPathFetcher.java
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/ColumnNameForPropertyAndPathFetcher.java
@@ -2,6 +2,7 @@ package org.grails.orm.hibernate.cfg.domainbinding;
import org.grails.datastore.mapping.model.PersistentProperty;
import org.grails.orm.hibernate.cfg.ColumnConfig;
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty;
import org.grails.orm.hibernate.cfg.GrailsHibernateUtil;
import org.grails.orm.hibernate.cfg.PersistentEntityNamingStrategy;
import org.grails.orm.hibernate.cfg.PropertyConfig;
@@ -9,24 +10,20 @@ import org.grails.orm.hibernate.cfg.PropertyConfig;
public class ColumnNameForPropertyAndPathFetcher {
private final PersistentEntityNamingStrategy namingStrategy;
- private final PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig;
private final DefaultColumnNameFetcher defaultColumnNameFetcher;
private final BackticksRemover backticksRemover;
public ColumnNameForPropertyAndPathFetcher(PersistentEntityNamingStrategy namingStrategy
) {
this.namingStrategy = namingStrategy;
- this.persistentPropertyToPropertyConfig = new PersistentPropertyToPropertyConfig();
this.defaultColumnNameFetcher = new DefaultColumnNameFetcher(namingStrategy);
this.backticksRemover = new BackticksRemover();
}
protected ColumnNameForPropertyAndPathFetcher(PersistentEntityNamingStrategy namingStrategy
- , PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig
, DefaultColumnNameFetcher defaultColumnNameFetcher
, BackticksRemover backticksRemover) {
this.namingStrategy = namingStrategy;
- this.persistentPropertyToPropertyConfig = persistentPropertyToPropertyConfig;
this.defaultColumnNameFetcher = defaultColumnNameFetcher;
this.backticksRemover = backticksRemover;
@@ -43,7 +40,7 @@ public class ColumnNameForPropertyAndPathFetcher {
// No column config given, attempt to obtain the property config directly from the property
PropertyConfig c = null;
try {
- c = persistentPropertyToPropertyConfig.toPropertyConfig(grailsProp);
+ c = ((GrailsHibernatePersistentProperty) grailsProp).getMappedForm();
} catch (Exception ignore) {
// If we cannot resolve a PropertyConfig, treat as absent and fall back later
}
@@ -57,7 +54,7 @@ public class ColumnNameForPropertyAndPathFetcher {
}
else {
if (grailsProp.supportsJoinColumnMapping()) {
- PropertyConfig pc = persistentPropertyToPropertyConfig.toPropertyConfig(grailsProp);
+ PropertyConfig pc = ((GrailsHibernatePersistentProperty) grailsProp).getMappedForm();
if (pc.hasJoinKeyMapping()) {
columnName = pc.getJoinTable().getKey().getName();
}
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/ComponentPropertyBinder.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/ComponentPropertyBinder.java
index c7c752c3d5..5af7023d73 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/ComponentPropertyBinder.java
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/ComponentPropertyBinder.java
@@ -51,7 +51,6 @@ public class ComponentPropertyBinder {
private final EnumTypeBinder enumTypeBinder;
private final PropertyFromValueCreator propertyFromValueCreator;
private final ComponentBinder componentBinder;
- private final PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig;
public ComponentPropertyBinder(MetadataBuildingContext metadataBuildingContext,
PersistentEntityNamingStrategy namingStrategy,
@@ -60,7 +59,7 @@ public class ComponentPropertyBinder {
EnumTypeBinder enumTypeBinder,
PropertyFromValueCreator propertyFromValueCreator) {
this(metadataBuildingContext, namingStrategy, mappingCacheHolder, collectionHolder,
- enumTypeBinder, propertyFromValueCreator, null, new PersistentPropertyToPropertyConfig());
+ enumTypeBinder, propertyFromValueCreator, null);
}
protected ComponentPropertyBinder(MetadataBuildingContext metadataBuildingContext,
@@ -69,8 +68,7 @@ public class ComponentPropertyBinder {
CollectionHolder collectionHolder,
EnumTypeBinder enumTypeBinder,
PropertyFromValueCreator propertyFromValueCreator,
- ComponentBinder componentBinder,
- PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig) {
+ ComponentBinder componentBinder) {
this.metadataBuildingContext = metadataBuildingContext;
this.namingStrategy = namingStrategy;
this.mappingCacheHolder = mappingCacheHolder;
@@ -78,7 +76,6 @@ public class ComponentPropertyBinder {
this.enumTypeBinder = enumTypeBinder;
this.propertyFromValueCreator = propertyFromValueCreator;
this.componentBinder = componentBinder != null ? componentBinder : new ComponentBinder(mappingCacheHolder, this);
- this.persistentPropertyToPropertyConfig = persistentPropertyToPropertyConfig;
}
protected ComponentPropertyBinder() {
@@ -89,7 +86,6 @@ public class ComponentPropertyBinder {
this.enumTypeBinder = null;
this.propertyFromValueCreator = null;
this.componentBinder = null;
- this.persistentPropertyToPropertyConfig = null;
}
public void bindComponentProperty(Component component, PersistentProperty componentProperty,
@@ -111,18 +107,18 @@ public class ComponentPropertyBinder {
LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName() + "] as ManyToOne");
value = new ManyToOne(metadataBuildingContext, table);
- new ManyToOneBinder(namingStrategy, persistentPropertyToPropertyConfig).bindManyToOne((Association) currentGrailsProp, (ManyToOne) value, path);
+ new ManyToOneBinder(namingStrategy).bindManyToOne((Association) currentGrailsProp, (ManyToOne) value, path);
} else if (currentGrailsProp instanceof org.grails.datastore.mapping.model.types.OneToOne) {
if (LOG.isDebugEnabled())
LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName() + "] as OneToOne");
if (((Association) currentGrailsProp).canBindOneToOneWithSingleColumnAndForeignKey()) {
value = new OneToOne(metadataBuildingContext, table, persistentClass);
- new OneToOneBinder(namingStrategy, persistentPropertyToPropertyConfig).bindOneToOne((org.grails.datastore.mapping.model.types.OneToOne) currentGrailsProp, (OneToOne) value, path);
+ new OneToOneBinder(namingStrategy).bindOneToOne((org.grails.datastore.mapping.model.types.OneToOne) currentGrailsProp, (OneToOne) value, path);
}
else {
value = new ManyToOne(metadataBuildingContext, table);
- new ManyToOneBinder(namingStrategy, persistentPropertyToPropertyConfig).bindManyToOne((Association) currentGrailsProp, (ManyToOne) value, path);
+ new ManyToOneBinder(namingStrategy).bindManyToOne((Association) currentGrailsProp, (ManyToOne) value, path);
}
}
else if (currentGrailsProp instanceof Embedded) {
@@ -135,13 +131,12 @@ public class ComponentPropertyBinder {
value = new BasicValue(metadataBuildingContext, table);
if (currentGrailsProp.getType().isEnum()) {
- String columnName = new ColumnNameForPropertyAndPathFetcher(namingStrategy, persistentPropertyToPropertyConfig,
- new DefaultColumnNameFetcher(namingStrategy), new BackticksRemover()).getColumnNameForPropertyAndPath(currentGrailsProp, path, null);
+ String columnName = new ColumnNameForPropertyAndPathFetcher(namingStrategy).getColumnNameForPropertyAndPath(currentGrailsProp, path, null);
enumTypeBinder.bindEnumType(currentGrailsProp, currentGrailsProp.getType(), (SimpleValue) value, columnName);
}
else {
// set type
- new SimpleValueBinder(namingStrategy, persistentPropertyToPropertyConfig).bindSimpleValue(currentGrailsProp, componentProperty, (SimpleValue) value, path);
+ new SimpleValueBinder(namingStrategy).bindSimpleValue(currentGrailsProp, componentProperty, (SimpleValue) value, path);
}
}
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/CompositeIdentifierToManyToOneBinder.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/CompositeIdentifierToManyToOneBinder.java
index a1c9b91141..1d27492d9d 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/CompositeIdentifierToManyToOneBinder.java
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/CompositeIdentifierToManyToOneBinder.java
@@ -10,6 +10,7 @@ import org.grails.datastore.mapping.model.types.Association;
import org.grails.datastore.mapping.model.types.ToOne;
import org.grails.orm.hibernate.cfg.ColumnConfig;
import org.grails.orm.hibernate.cfg.CompositeIdentity;
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty;
import org.grails.orm.hibernate.cfg.PersistentEntityNamingStrategy;
import static org.grails.orm.hibernate.cfg.GrailsDomainBinder.UNDERSCORE;
@@ -19,7 +20,6 @@ public class CompositeIdentifierToManyToOneBinder {
private final TableNameFetcher tableNameFetcher;
private final PersistentEntityNamingStrategy namingStrategy;
private final DefaultColumnNameFetcher defaultColumnNameFetcher;
- private final PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig;
private final BackticksRemover backticksRemover;
private final SimpleValueBinder simpleValueBinder;
@@ -28,7 +28,6 @@ public class CompositeIdentifierToManyToOneBinder {
this.tableNameFetcher = new TableNameFetcher(namingStrategy);
this.namingStrategy = namingStrategy;
this.defaultColumnNameFetcher = new DefaultColumnNameFetcher(namingStrategy);
- this.persistentPropertyToPropertyConfig = new PersistentPropertyToPropertyConfig();
this.backticksRemover = new BackticksRemover();
this.simpleValueBinder = new SimpleValueBinder(namingStrategy);
@@ -38,13 +37,11 @@ public class CompositeIdentifierToManyToOneBinder {
, TableNameFetcher tableNameFetcher
, PersistentEntityNamingStrategy namingStrategy
, DefaultColumnNameFetcher defaultColumnNameFetcher
- , PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig
, BackticksRemover backticksRemover, SimpleValueBinder simpleValueBinder) {
this.foreignKeyColumnCountCalculator = foreignKeyColumnCountCalculator;
this.tableNameFetcher =tableNameFetcher;
this.namingStrategy = namingStrategy;
this.defaultColumnNameFetcher = defaultColumnNameFetcher;
- this.persistentPropertyToPropertyConfig = persistentPropertyToPropertyConfig;
this.backticksRemover = backticksRemover;
this.simpleValueBinder = simpleValueBinder;
}
@@ -56,7 +53,7 @@ public class CompositeIdentifierToManyToOneBinder {
String path) {
String[] propertyNames = compositeId.getPropertyNames();
- List<ColumnConfig> columns = persistentPropertyToPropertyConfig.toPropertyConfig(property).getColumns();
+ List<ColumnConfig> columns = ((GrailsHibernatePersistentProperty) property).getMappedForm().getColumns();
int i = columns.size();
int expectedForeignKeyColumnLength = foreignKeyColumnCountCalculator.calculateForeignKeyColumnCount(refDomainClass, propertyNames);
if (i != expectedForeignKeyColumnLength) {
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/CreateKeyForProps.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/CreateKeyForProps.java
index c44e5905ce..82c40b7d9c 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/CreateKeyForProps.java
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/CreateKeyForProps.java
@@ -10,30 +10,27 @@ import org.hibernate.mapping.Table;
import org.grails.datastore.mapping.model.PersistentEntity;
import org.grails.datastore.mapping.model.PersistentProperty;
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty;
import org.grails.orm.hibernate.cfg.PropertyConfig;
public class CreateKeyForProps {
private final ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher;
private final UniqueKeyForColumnsCreator uniqueKeyForColumnsCreator;
- private final PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig;
public CreateKeyForProps(ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher) {
this.columnNameForPropertyAndPathFetcher = columnNameForPropertyAndPathFetcher;
this.uniqueKeyForColumnsCreator = new UniqueKeyForColumnsCreator();
- this.persistentPropertyToPropertyConfig = new PersistentPropertyToPropertyConfig();
}
protected CreateKeyForProps(ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher
- , UniqueKeyForColumnsCreator uniqueKeyForColumnsCreator
- , PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig) {
+ , UniqueKeyForColumnsCreator uniqueKeyForColumnsCreator) {
this.columnNameForPropertyAndPathFetcher = columnNameForPropertyAndPathFetcher;
this.uniqueKeyForColumnsCreator = uniqueKeyForColumnsCreator;
- this.persistentPropertyToPropertyConfig = persistentPropertyToPropertyConfig;
}
public void createKeyForProps(PersistentProperty grailsProp, String path, Table table,
String columnName) {
- PropertyConfig mappedForm = persistentPropertyToPropertyConfig.toPropertyConfig(grailsProp);
+ PropertyConfig mappedForm = ((GrailsHibernatePersistentProperty) grailsProp).getMappedForm();
if (mappedForm.isUnique() && mappedForm.isUniqueWithinGroup()) {
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/DefaultColumnNameFetcher.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/DefaultColumnNameFetcher.java
index 0dcaaecb20..97c33e5c63 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/DefaultColumnNameFetcher.java
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/DefaultColumnNameFetcher.java
@@ -4,6 +4,7 @@ import org.grails.datastore.mapping.model.PersistentProperty;
import org.grails.datastore.mapping.model.types.Association;
import org.grails.datastore.mapping.model.types.Basic;
import org.grails.datastore.mapping.model.types.ManyToMany;
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty;
import org.grails.orm.hibernate.cfg.PersistentEntityNamingStrategy;
public class DefaultColumnNameFetcher {
@@ -30,7 +31,7 @@ public class DefaultColumnNameFetcher {
if (property instanceof Association) {
Association association = (Association) property;
boolean isBasic = property instanceof Basic;
- if (isBasic && (new PersistentPropertyToPropertyConfig().toPropertyConfig(property)).getType() != null) {
+ if (isBasic && (((GrailsHibernatePersistentProperty) property).getMappedForm()).getType() != null) {
return columnName;
}
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/EnumTypeBinder.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/EnumTypeBinder.java
index 94201c6ea4..546d456762 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/EnumTypeBinder.java
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/EnumTypeBinder.java
@@ -40,7 +40,7 @@ public class EnumTypeBinder {
private static final Logger LOG = LoggerFactory.getLogger(EnumTypeBinder.class);
public void bindEnumType(PersistentProperty property, Class<?> propertyType, SimpleValue simpleValue, String columnName) {
- PropertyConfig pc = new PersistentPropertyToPropertyConfig().toPropertyConfig(property);
+ PropertyConfig pc = ((GrailsHibernatePersistentProperty) property).getMappedForm();
Mapping ownerMapping = null;
if (property.getOwner() instanceof GrailsHibernatePersistentEntity) {
ownerMapping = ((GrailsHibernatePersistentEntity) property.getOwner()).getMappedForm();
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/ManyToOneBinder.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/ManyToOneBinder.java
index e91ca28fff..d012954658 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/ManyToOneBinder.java
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/ManyToOneBinder.java
@@ -11,6 +11,7 @@ import org.grails.datastore.mapping.model.types.OneToOne;
import org.grails.orm.hibernate.cfg.ColumnConfig;
import org.grails.orm.hibernate.cfg.CompositeIdentity;
import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentEntity;
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty;
import org.grails.orm.hibernate.cfg.JoinTable;
import org.grails.orm.hibernate.cfg.Mapping;
import org.grails.orm.hibernate.cfg.PersistentEntityNamingStrategy;
@@ -22,33 +23,25 @@ public class ManyToOneBinder {
private final PersistentEntityNamingStrategy namingStrategy;
private final SimpleValueBinder simpleValueBinder;
- private final PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig;
private final ManyToOneValuesBinder manyToOneValuesBinder;
private final CompositeIdentifierToManyToOneBinder compositeIdentifierToManyToOneBinder;
private final SimpleValueColumnFetcher simpleValueColumnFetcher;
public ManyToOneBinder(PersistentEntityNamingStrategy namingStrategy) {
- this(namingStrategy, new PersistentPropertyToPropertyConfig());
- }
-
- protected ManyToOneBinder(PersistentEntityNamingStrategy namingStrategy, PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig) {
this.namingStrategy = namingStrategy;
- this.persistentPropertyToPropertyConfig = persistentPropertyToPropertyConfig;
- this.simpleValueBinder = new SimpleValueBinder(namingStrategy, persistentPropertyToPropertyConfig);
- this.manyToOneValuesBinder = new ManyToOneValuesBinder(persistentPropertyToPropertyConfig);
+ this.simpleValueBinder = new SimpleValueBinder(namingStrategy);
+ this.manyToOneValuesBinder = new ManyToOneValuesBinder();
this.compositeIdentifierToManyToOneBinder = new CompositeIdentifierToManyToOneBinder(namingStrategy);
this.simpleValueColumnFetcher = new SimpleValueColumnFetcher();
}
- protected ManyToOneBinder(PersistentEntityNamingStrategy namingStrategy
+ protected ManyToOneBinder(PersistentEntityNamingStrategy namingStrategy
, SimpleValueBinder simpleValueBinder
- , PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig
, ManyToOneValuesBinder manyToOneValuesBinder
, CompositeIdentifierToManyToOneBinder compositeIdentifierToManyToOneBinder
, SimpleValueColumnFetcher simpleValueColumnFetcher) {
this.namingStrategy = namingStrategy;
this.simpleValueBinder =simpleValueBinder;
- this.persistentPropertyToPropertyConfig = persistentPropertyToPropertyConfig;
this.manyToOneValuesBinder = manyToOneValuesBinder;
this.compositeIdentifierToManyToOneBinder = compositeIdentifierToManyToOneBinder;
this.simpleValueColumnFetcher = simpleValueColumnFetcher;
@@ -77,7 +70,7 @@ public class ManyToOneBinder {
}
else {
if (property.isCircular() && (property instanceof ManyToMany)) {
- PropertyConfig pc = persistentPropertyToPropertyConfig.toPropertyConfig(property);
+ PropertyConfig pc = ((GrailsHibernatePersistentProperty) property).getMappedForm();
if (mapping != null && pc.getColumns().isEmpty()) {
mapping.getColumns().put(property.getName(), pc);
@@ -99,7 +92,7 @@ public class ManyToOneBinder {
}
}
- PropertyConfig config = persistentPropertyToPropertyConfig.toPropertyConfig(property);
+ PropertyConfig config = ((GrailsHibernatePersistentProperty) property).getMappedForm();
boolean isOneToOne = property instanceof OneToOne;
boolean notComposite = !isComposite;
if (isOneToOne && notComposite) {
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/ManyToOneValuesBinder.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/ManyToOneValuesBinder.java
index 3d33be9ca2..ca12b84803 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/ManyToOneValuesBinder.java
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/ManyToOneValuesBinder.java
@@ -6,21 +6,23 @@ import org.hibernate.FetchMode;
import org.hibernate.mapping.ManyToOne;
import org.grails.datastore.mapping.model.types.Association;
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty;
import org.grails.orm.hibernate.cfg.PropertyConfig;
public class ManyToOneValuesBinder {
- private final PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig;
+
+
+
+
public ManyToOneValuesBinder() {
- this.persistentPropertyToPropertyConfig = new PersistentPropertyToPropertyConfig();
- }
- protected ManyToOneValuesBinder(PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig) {
- this.persistentPropertyToPropertyConfig = persistentPropertyToPropertyConfig;
}
+
+
public void bindManyToOneValues(Association property, ManyToOne manyToOne) {
- PropertyConfig config = persistentPropertyToPropertyConfig.toPropertyConfig(property);
+ PropertyConfig config = ((GrailsHibernatePersistentProperty) property).getMappedForm();
var fetchMode = Optional.ofNullable(config.getFetchMode()).orElse(FetchMode.DEFAULT);
manyToOne.setFetchMode(fetchMode);
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/OneToOneBinder.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/OneToOneBinder.java
index a265256c0c..a83d4a50de 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/OneToOneBinder.java
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/OneToOneBinder.java
@@ -5,36 +5,29 @@ import org.hibernate.mapping.OneToOne;
import org.hibernate.type.ForeignKeyDirection;
import org.grails.datastore.mapping.model.types.Association;
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty;
import org.grails.orm.hibernate.cfg.PersistentEntityNamingStrategy;
import org.grails.orm.hibernate.cfg.PropertyConfig;
public class OneToOneBinder {
private final PersistentEntityNamingStrategy namingStrategy;
- private final PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig;
private final SimpleValueBinder simpleValueBinder;
public OneToOneBinder(PersistentEntityNamingStrategy namingStrategy) {
- this(namingStrategy, new PersistentPropertyToPropertyConfig());
- }
-
- protected OneToOneBinder(PersistentEntityNamingStrategy namingStrategy, PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig) {
this.namingStrategy = namingStrategy;
- this.persistentPropertyToPropertyConfig = persistentPropertyToPropertyConfig;
- this.simpleValueBinder = new SimpleValueBinder(namingStrategy, persistentPropertyToPropertyConfig);
+ this.simpleValueBinder = new SimpleValueBinder(namingStrategy);
}
protected OneToOneBinder(PersistentEntityNamingStrategy namingStrategy,
- PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig,
SimpleValueBinder simpleValueBinder) {
this.namingStrategy = namingStrategy;
- this.persistentPropertyToPropertyConfig = persistentPropertyToPropertyConfig;
this.simpleValueBinder = simpleValueBinder;
}
public void bindOneToOne(final org.grails.datastore.mapping.model.types.OneToOne property, OneToOne oneToOne,
String path) {
- PropertyConfig config = persistentPropertyToPropertyConfig.toPropertyConfig(property);
+ PropertyConfig config = ((GrailsHibernatePersistentProperty) property).getMappedForm();
final Association otherSide = property.getInverseSide();
final boolean hasOne = otherSide.isHasOne();
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/PersistentPropertyToPropertyConfig.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/PersistentPropertyToPropertyConfig.java
deleted file mode 100644
index 4382c989d4..0000000000
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/PersistentPropertyToPropertyConfig.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package org.grails.orm.hibernate.cfg.domainbinding;
-
-import org.grails.datastore.mapping.model.PersistentProperty;
-import org.grails.orm.hibernate.cfg.PropertyConfig;
-import org.hibernate.MappingException;
-
-import java.util.Optional;
-
-import jakarta.annotation.Nonnull;
-
-public class PersistentPropertyToPropertyConfig {
- @Nonnull public PropertyConfig toPropertyConfig(PersistentProperty persistentProperty) {
- return Optional.of(persistentProperty)
- .map(PersistentProperty::getMappedForm)
- .map(PropertyConfig.class::cast)
- .orElseThrow(() -> new MappingException("No PropertyConfig found for property"));
- }
-}
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/PropertyBinder.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/PropertyBinder.java
index debe4d96ce..3da7cee61b 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/PropertyBinder.java
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/PropertyBinder.java
@@ -5,6 +5,8 @@ import org.grails.datastore.mapping.model.PersistentProperty;
import org.grails.datastore.mapping.model.types.Association;
import org.grails.datastore.mapping.reflect.EntityReflector;
import org.grails.orm.hibernate.access.TraitPropertyAccessStrategy;
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty;
+
import org.hibernate.boot.spi.AccessType;
import org.hibernate.mapping.Property;
@@ -13,22 +15,18 @@ import java.util.Optional;
public class PropertyBinder {
- private final PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig;
private final CascadeBehaviorFetcher cascadeBehaviorFetcher;
private final BidirectionalManyToOneWithListMapping bidirectionalManyToOneWithListMapping;
public PropertyBinder(
- PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig
- , CascadeBehaviorFetcher cascadeBehaviorFetcher
+ CascadeBehaviorFetcher cascadeBehaviorFetcher
, BidirectionalManyToOneWithListMapping bidirectionalManyToOneWithListMapping) {
- this.persistentPropertyToPropertyConfig = persistentPropertyToPropertyConfig;
this.cascadeBehaviorFetcher = cascadeBehaviorFetcher;
this.bidirectionalManyToOneWithListMapping = bidirectionalManyToOneWithListMapping;
}
public PropertyBinder() {
- this(new PersistentPropertyToPropertyConfig()
- , new CascadeBehaviorFetcher()
+ this(new CascadeBehaviorFetcher()
, new BidirectionalManyToOneWithListMapping());
}
@@ -41,7 +39,7 @@ public class PropertyBinder {
public void bindProperty(PersistentProperty<?> persistentProperty, Property prop) {
// set the property name
prop.setName(persistentProperty.getName());
- var config = persistentPropertyToPropertyConfig.toPropertyConfig(persistentProperty);
+ var config = ((GrailsHibernatePersistentProperty) persistentProperty).getMappedForm();
if (bidirectionalManyToOneWithListMapping.isBidirectionalManyToOneWithListMapping(persistentProperty, prop)) {
prop.setInsertable(false);
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/SimpleValueBinder.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/SimpleValueBinder.java
index 70f74a25dc..c560434606 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/SimpleValueBinder.java
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/SimpleValueBinder.java
@@ -26,22 +26,14 @@ public class SimpleValueBinder {
private final PersistentEntityNamingStrategy namingStrategy;
private final ColumnConfigToColumnBinder columnConfigToColumnBinder;
private final ColumnBinder columnBinder;
- private final PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig;
private static final String SEQUENCE_KEY = GrailsSequenceGeneratorEnum.SEQUENCE.toString();
- /**
- * Convenience constructor for namingStrategy and persistentPropertyToPropertyConfig.
- */
- public SimpleValueBinder(PersistentEntityNamingStrategy namingStrategy, PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig) {
- this(namingStrategy, new ColumnConfigToColumnBinder(), new ColumnBinder(namingStrategy), persistentPropertyToPropertyConfig);
- }
-
/**
* Convenience constructor for namingStrategy.
*/
public SimpleValueBinder(PersistentEntityNamingStrategy namingStrategy) {
- this(namingStrategy, new ColumnConfigToColumnBinder(), new ColumnBinder(namingStrategy), new PersistentPropertyToPropertyConfig());
+ this(namingStrategy, new ColumnConfigToColumnBinder(), new ColumnBinder(namingStrategy));
}
/**
@@ -50,12 +42,10 @@ public class SimpleValueBinder {
public SimpleValueBinder(
PersistentEntityNamingStrategy namingStrategy,
ColumnConfigToColumnBinder columnConfigToColumnBinder,
- ColumnBinder columnBinder,
- PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig) {
+ ColumnBinder columnBinder) {
this.namingStrategy = namingStrategy;
this.columnConfigToColumnBinder = columnConfigToColumnBinder;
this.columnBinder = columnBinder;
- this.persistentPropertyToPropertyConfig = persistentPropertyToPropertyConfig;
}
/**
@@ -65,7 +55,6 @@ public class SimpleValueBinder {
this.namingStrategy = null;
this.columnConfigToColumnBinder = null;
this.columnBinder = null;
- this.persistentPropertyToPropertyConfig = null;
}
public void bindSimpleValue(
@@ -73,8 +62,8 @@ public class SimpleValueBinder {
PersistentProperty parentProperty,
SimpleValue simpleValue,
String path) {
-
- PropertyConfig propertyConfig = persistentPropertyToPropertyConfig.toPropertyConfig(property);
+
+ PropertyConfig propertyConfig = ((GrailsHibernatePersistentProperty) property).getMappedForm();
Mapping mapping = null;
if (property.getOwner() instanceof GrailsHibernatePersistentEntity persistentEntity) {
mapping = persistentEntity.getMappedForm();
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/TableForManyCalculator.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/TableForManyCalculator.java
index 71d5e453c0..225465e1e2 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/TableForManyCalculator.java
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/TableForManyCalculator.java
@@ -8,6 +8,7 @@ import org.grails.datastore.mapping.model.PersistentEntity;
import org.grails.datastore.mapping.model.types.Basic;
import org.grails.datastore.mapping.model.types.ManyToMany;
import org.grails.datastore.mapping.model.types.ToMany;
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty;
import org.grails.orm.hibernate.cfg.JoinTable;
import org.grails.orm.hibernate.cfg.PersistentEntityNamingStrategy;
import org.grails.orm.hibernate.cfg.PropertyConfig;
@@ -21,7 +22,6 @@ public class TableForManyCalculator {
private final BackticksRemover backticksRemover;
private final ShouldCollectionBindWithJoinColumn shouldCollectionBindWithJoinColumn;
private final BackTigsTrimmer backTigsTrimmer;
- private final PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig;
public TableForManyCalculator(PersistentEntityNamingStrategy namingStrategy) {
this.namingStrategy = namingStrategy;
@@ -29,21 +29,18 @@ public class TableForManyCalculator {
backticksRemover = new BackticksRemover();
shouldCollectionBindWithJoinColumn = new ShouldCollectionBindWithJoinColumn();
backTigsTrimmer = new BackTigsTrimmer();
- persistentPropertyToPropertyConfig = new PersistentPropertyToPropertyConfig();
}
protected TableForManyCalculator(PersistentEntityNamingStrategy namingStrategy
, TableNameFetcher tableNameFetcher
, BackticksRemover backticksRemover
, ShouldCollectionBindWithJoinColumn shouldCollectionBindWithJoinColumn
- , BackTigsTrimmer backTigsTrimmer
- , PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig) {
+ , BackTigsTrimmer backTigsTrimmer) {
this.namingStrategy = namingStrategy;
this.tableNameFetcher = tableNameFetcher;
this.backticksRemover = backticksRemover;
this.shouldCollectionBindWithJoinColumn = shouldCollectionBindWithJoinColumn;
this.backTigsTrimmer = backTigsTrimmer;
- this.persistentPropertyToPropertyConfig = persistentPropertyToPropertyConfig;
}
@@ -56,7 +53,7 @@ public class TableForManyCalculator {
public String calculateTableForMany(ToMany property, String sessionFactoryBeanName) {
String propertyColumnName = namingStrategy.resolveColumnName(property.getName());
//fix for GRAILS-5895
- PropertyConfig config = persistentPropertyToPropertyConfig.toPropertyConfig(property);
+ PropertyConfig config = ((GrailsHibernatePersistentProperty) property).getMappedForm();
JoinTable jt = config.getJoinTable();
boolean hasJoinTableMapping = jt != null && jt.getName() != null;
PersistentEntity domainClass1 = property.getOwner();
diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/UserTypeFetcher.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/UserTypeFetcher.java
index 08ecbbac58..ca0305fca6 100644
--- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/UserTypeFetcher.java
+++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/UserTypeFetcher.java
@@ -4,25 +4,20 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.grails.datastore.mapping.model.PersistentProperty;
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty;
import org.grails.orm.hibernate.cfg.PropertyConfig;
public class UserTypeFetcher {
- private final PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig;
-
private static final Logger LOG = LoggerFactory.getLogger(UserTypeFetcher.class);
public UserTypeFetcher() {
- this.persistentPropertyToPropertyConfig = new PersistentPropertyToPropertyConfig();
}
- protected UserTypeFetcher(PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig) {
- this.persistentPropertyToPropertyConfig = persistentPropertyToPropertyConfig;
- }
public Class<?> getUserType(PersistentProperty currentGrailsProp) {
Class<?> userType = null;
- PropertyConfig config = persistentPropertyToPropertyConfig.toPropertyConfig(currentGrailsProp);
+ PropertyConfig config = ((GrailsHibernatePersistentProperty) currentGrailsProp).getMappedForm();
Object typeObj = config.getType();
if (typeObj instanceof Class<?>) {
userType = (Class<?>)typeObj;
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ColumnBinderSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ColumnBinderSpec.groovy
index 0df1ccf6d4..cb490c28a0 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ColumnBinderSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ColumnBinderSpec.groovy
@@ -1,10 +1,11 @@
package org.grails.orm.hibernate.cfg.domainbinding
-import org.grails.datastore.mapping.model.PersistentEntity
+
import org.grails.datastore.mapping.model.PersistentProperty
import org.grails.datastore.mapping.model.types.ManyToMany
import org.grails.orm.hibernate.cfg.ColumnConfig
import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentEntity
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty
import org.grails.orm.hibernate.cfg.Mapping
import org.grails.orm.hibernate.cfg.PersistentEntityNamingStrategy
import org.grails.orm.hibernate.cfg.PropertyConfig
@@ -18,7 +19,6 @@ class ColumnBinderSpec extends Specification {
given:
def namingStrategy = Mock(PersistentEntityNamingStrategy)
def columnNameFetcher = Mock(ColumnNameForPropertyAndPathFetcher)
- def propToConfig = Mock(PersistentPropertyToPropertyConfig)
def stringBinder = Mock(StringColumnConstraintsBinder)
def numericBinder = Mock(NumericColumnConstraintsBinder)
def keyCreator = Mock(CreateKeyForProps)
@@ -28,7 +28,6 @@ class ColumnBinderSpec extends Specification {
def binder = new ColumnBinder(
columnNameFetcher,
- propToConfig,
stringBinder,
numericBinder,
keyCreator,
@@ -36,7 +35,7 @@ class ColumnBinderSpec extends Specification {
indexBinder
)
- def prop = Mock(ManyToMany)
+ def prop = Mock(ManyToMany, additionalInterfaces: [GrailsHibernatePersistentProperty])
def owner = Mock(GrailsHibernatePersistentEntity)
def mappedForm = Mock(PropertyConfig)
def column = new Column()
@@ -48,7 +47,7 @@ class ColumnBinderSpec extends Specification {
prop.isNullable() >> false
prop.getOwner() >> owner
owner.isRoot() >> true // skip subclass nullable logic
- propToConfig.toPropertyConfig(prop) >> mappedForm
+ ((GrailsHibernatePersistentProperty)prop).getMappedForm() >> mappedForm
mappedForm.isUnique() >> false
mappedForm.isUniqueWithinGroup() >> false
@@ -68,7 +67,6 @@ class ColumnBinderSpec extends Specification {
given:
def namingStrategy = Mock(PersistentEntityNamingStrategy)
def columnNameFetcher = Mock(ColumnNameForPropertyAndPathFetcher)
- def propToConfig = Mock(PersistentPropertyToPropertyConfig)
def stringBinder = Mock(StringColumnConstraintsBinder)
def numericBinder = Mock(NumericColumnConstraintsBinder)
def keyCreator = Mock(CreateKeyForProps)
@@ -78,7 +76,6 @@ class ColumnBinderSpec extends Specification {
def binder = new ColumnBinder(
columnNameFetcher,
- propToConfig,
stringBinder,
numericBinder,
keyCreator,
@@ -86,7 +83,7 @@ class ColumnBinderSpec extends Specification {
indexBinder
)
- def prop = Mock(PersistentProperty)
+ def prop = Mock(PersistentProperty, additionalInterfaces: [GrailsHibernatePersistentProperty])
def parentProp = Mock(PersistentProperty)
def owner = Mock(GrailsHibernatePersistentEntity)
def mapping = Mock(Mapping)
@@ -105,7 +102,7 @@ class ColumnBinderSpec extends Specification {
owner.isRoot() >> false
owner.getMappedForm() >> mapping
mapping.getTablePerHierarchy() >> true // forces nullable true for subclass
- propToConfig.toPropertyConfig(prop) >>> [propertyConfig, propertyConfig] // called twice in code
+ ((GrailsHibernatePersistentProperty)prop).getMappedForm() >>> [propertyConfig, propertyConfig] // called twice in code
// numeric constraints applied
// unique settings
propertyConfig.isUnique() >> true
@@ -132,7 +129,6 @@ class ColumnBinderSpec extends Specification {
given:
def namingStrategy = Mock(PersistentEntityNamingStrategy)
def columnNameFetcher = Mock(ColumnNameForPropertyAndPathFetcher)
- def propToConfig = Mock(PersistentPropertyToPropertyConfig)
def stringBinder = Mock(StringColumnConstraintsBinder)
def numericBinder = Mock(NumericColumnConstraintsBinder)
def keyCreator = Mock(CreateKeyForProps)
@@ -142,7 +138,6 @@ class ColumnBinderSpec extends Specification {
def binder = new ColumnBinder(
columnNameFetcher,
- propToConfig,
stringBinder,
numericBinder,
keyCreator,
@@ -150,7 +145,7 @@ class ColumnBinderSpec extends Specification {
indexBinder
)
- def prop = Mock(org.grails.datastore.mapping.model.types.OneToOne)
+ def prop = Mock(org.grails.datastore.mapping.model.types.OneToOne, additionalInterfaces: [GrailsHibernatePersistentProperty])
def inverse = Mock(org.grails.datastore.mapping.model.types.Association)
def owner = Mock(GrailsHibernatePersistentEntity)
def mappedForm = Mock(PropertyConfig)
@@ -167,7 +162,7 @@ class ColumnBinderSpec extends Specification {
inverse.isHasOne() >> true
prop.getOwner() >> owner
owner.isRoot() >> true
- propToConfig.toPropertyConfig(prop) >> mappedForm
+ ((GrailsHibernatePersistentProperty)prop).getMappedForm() >> mappedForm
mappedForm.isUnique() >> false
mappedForm.isUniqueWithinGroup() >> false
@@ -187,7 +182,6 @@ class ColumnBinderSpec extends Specification {
given:
def namingStrategy = Mock(PersistentEntityNamingStrategy)
def columnNameFetcher = Mock(ColumnNameForPropertyAndPathFetcher)
- def propToConfig = Mock(PersistentPropertyToPropertyConfig)
def stringBinder = Mock(StringColumnConstraintsBinder)
def numericBinder = Mock(NumericColumnConstraintsBinder)
def keyCreator = Mock(CreateKeyForProps)
@@ -197,7 +191,6 @@ class ColumnBinderSpec extends Specification {
def binder = new ColumnBinder(
columnNameFetcher,
- propToConfig,
stringBinder,
numericBinder,
keyCreator,
@@ -205,7 +198,7 @@ class ColumnBinderSpec extends Specification {
indexBinder
)
- def prop = Mock(PersistentProperty)
+ def prop = Mock(PersistentProperty, additionalInterfaces: [GrailsHibernatePersistentProperty])
def owner = Mock(GrailsHibernatePersistentEntity)
def propertyConfig = Mock(PropertyConfig)
def column = new Column("test")
@@ -217,7 +210,7 @@ class ColumnBinderSpec extends Specification {
prop.isNullable() >> true
prop.getOwner() >> owner
owner.isRoot() >> true
- propToConfig.toPropertyConfig(prop) >>> [propertyConfig, propertyConfig]
+ ((GrailsHibernatePersistentProperty)prop).getMappedForm() >>> [propertyConfig, propertyConfig]
propertyConfig.isUnique() >> false
propertyConfig.isUniqueWithinGroup() >> false
@@ -237,7 +230,6 @@ class ColumnBinderSpec extends Specification {
given:
def namingStrategy = Mock(PersistentEntityNamingStrategy)
def columnNameFetcher = Mock(ColumnNameForPropertyAndPathFetcher)
- def propToConfig = Mock(PersistentPropertyToPropertyConfig)
def stringBinder = Mock(StringColumnConstraintsBinder)
def numericBinder = Mock(NumericColumnConstraintsBinder)
def keyCreator = Mock(CreateKeyForProps)
@@ -247,7 +239,6 @@ class ColumnBinderSpec extends Specification {
def binder = new ColumnBinder(
columnNameFetcher,
- propToConfig,
stringBinder,
numericBinder,
keyCreator,
@@ -255,7 +246,7 @@ class ColumnBinderSpec extends Specification {
indexBinder
)
- def prop = Mock(org.grails.datastore.mapping.model.types.OneToOne)
+ def prop = Mock(org.grails.datastore.mapping.model.types.OneToOne, additionalInterfaces: [GrailsHibernatePersistentProperty])
def inverse = Mock(org.grails.datastore.mapping.model.types.Association)
def owner = Mock(GrailsHibernatePersistentEntity)
def mappedForm = Mock(PropertyConfig)
@@ -271,7 +262,7 @@ class ColumnBinderSpec extends Specification {
inverse.isHasOne() >> false
prop.getOwner() >> owner
owner.isRoot() >> true
- propToConfig.toPropertyConfig(prop) >> mappedForm
+ ((GrailsHibernatePersistentProperty)prop).getMappedForm() >> mappedForm
mappedForm.isUnique() >> false
mappedForm.isUniqueWithinGroup() >> false
@@ -291,7 +282,6 @@ class ColumnBinderSpec extends Specification {
given:
def namingStrategy = Mock(PersistentEntityNamingStrategy)
def columnNameFetcher = Mock(ColumnNameForPropertyAndPathFetcher)
- def propToConfig = Mock(PersistentPropertyToPropertyConfig)
def stringBinder = Mock(StringColumnConstraintsBinder)
def numericBinder = Mock(NumericColumnConstraintsBinder)
def keyCreator = Mock(CreateKeyForProps)
@@ -301,7 +291,6 @@ class ColumnBinderSpec extends Specification {
def binder = new ColumnBinder(
columnNameFetcher,
- propToConfig,
stringBinder,
numericBinder,
keyCreator,
@@ -309,7 +298,7 @@ class ColumnBinderSpec extends Specification {
indexBinder
)
- def prop = Mock(org.grails.datastore.mapping.model.types.ToOne)
+ def prop = Mock(org.grails.datastore.mapping.model.types.ToOne, additionalInterfaces: [GrailsHibernatePersistentProperty])
def owner = Mock(GrailsHibernatePersistentEntity)
def mappedForm = Mock(PropertyConfig)
def column = new Column()
@@ -321,7 +310,7 @@ class ColumnBinderSpec extends Specification {
prop.isCircular() >> true
prop.getOwner() >> owner
owner.isRoot() >> true
- propToConfig.toPropertyConfig(prop) >> mappedForm
+ ((GrailsHibernatePersistentProperty)prop).getMappedForm() >> mappedForm
mappedForm.isUnique() >> false
mappedForm.isUniqueWithinGroup() >> false
@@ -341,7 +330,6 @@ class ColumnBinderSpec extends Specification {
given:
def namingStrategy = Mock(PersistentEntityNamingStrategy)
def columnNameFetcher = Mock(ColumnNameForPropertyAndPathFetcher)
- def propToConfig = Mock(PersistentPropertyToPropertyConfig)
def stringBinder = Mock(StringColumnConstraintsBinder)
def numericBinder = Mock(NumericColumnConstraintsBinder)
def keyCreator = Mock(CreateKeyForProps)
@@ -351,7 +339,6 @@ class ColumnBinderSpec extends Specification {
def binder = new ColumnBinder(
columnNameFetcher,
- propToConfig,
stringBinder,
numericBinder,
keyCreator,
@@ -359,7 +346,7 @@ class ColumnBinderSpec extends Specification {
indexBinder
)
- def prop = Mock(org.grails.datastore.mapping.model.types.Association)
+ def prop = Mock(org.grails.datastore.mapping.model.types.Association, additionalInterfaces: [GrailsHibernatePersistentProperty])
def owner = Mock(GrailsHibernatePersistentEntity)
def mappedForm = Mock(PropertyConfig)
def column = new Column()
@@ -372,7 +359,7 @@ class ColumnBinderSpec extends Specification {
owner.isRoot() >> true
// ensure we don't hit special branches
// Spock will not have methods isBidirectional, isOwningSide on Association base; not needed since code checks only if OneToOne or ToOne/circular
- propToConfig.toPropertyConfig(prop) >> mappedForm
+ ((GrailsHibernatePersistentProperty)prop).getMappedForm() >> mappedForm
mappedForm.isUnique() >> false
mappedForm.isUniqueWithinGroup() >> false
@@ -392,7 +379,6 @@ class ColumnBinderSpec extends Specification {
given:
def namingStrategy = Mock(PersistentEntityNamingStrategy)
def columnNameFetcher = Mock(ColumnNameForPropertyAndPathFetcher)
- def propToConfig = Mock(PersistentPropertyToPropertyConfig)
def stringBinder = Mock(StringColumnConstraintsBinder)
def numericBinder = Mock(NumericColumnConstraintsBinder)
def keyCreator = Mock(CreateKeyForProps)
@@ -402,7 +388,6 @@ class ColumnBinderSpec extends Specification {
def binder = new ColumnBinder(
columnNameFetcher,
- propToConfig,
stringBinder,
numericBinder,
keyCreator,
@@ -410,7 +395,7 @@ class ColumnBinderSpec extends Specification {
indexBinder
)
- def prop = Mock(PersistentProperty)
+ def prop = Mock(PersistentProperty, additionalInterfaces: [GrailsHibernatePersistentProperty])
def parentProp = Mock(PersistentProperty)
def owner = Mock(GrailsHibernatePersistentEntity)
def propertyConfig = Mock(PropertyConfig)
@@ -423,7 +408,7 @@ class ColumnBinderSpec extends Specification {
parentProp.isNullable() >> false
prop.getOwner() >> owner
owner.isRoot() >> true
- propToConfig.toPropertyConfig(prop) >>> [propertyConfig, propertyConfig]
+ ((GrailsHibernatePersistentProperty)prop).getMappedForm() >>> [propertyConfig, propertyConfig]
propertyConfig.isUnique() >> false
propertyConfig.isUniqueWithinGroup() >> false
@@ -443,7 +428,6 @@ class ColumnBinderSpec extends Specification {
given:
def namingStrategy = Mock(PersistentEntityNamingStrategy)
def columnNameFetcher = Mock(ColumnNameForPropertyAndPathFetcher)
- def propToConfig = Mock(PersistentPropertyToPropertyConfig)
def stringBinder = Mock(StringColumnConstraintsBinder)
def numericBinder = Mock(NumericColumnConstraintsBinder)
def keyCreator = Mock(CreateKeyForProps)
@@ -453,7 +437,6 @@ class ColumnBinderSpec extends Specification {
def binder = new ColumnBinder(
columnNameFetcher,
- propToConfig,
stringBinder,
numericBinder,
keyCreator,
@@ -461,7 +444,7 @@ class ColumnBinderSpec extends Specification {
indexBinder
)
- def prop = Mock(PersistentProperty)
+ def prop = Mock(PersistentProperty, additionalInterfaces: [GrailsHibernatePersistentProperty])
def parentProp = Mock(PersistentProperty)
def owner = Mock(GrailsHibernatePersistentEntity)
def propertyConfig = Mock(PropertyConfig)
@@ -474,7 +457,7 @@ class ColumnBinderSpec extends Specification {
parentProp.isNullable() >> true
prop.getOwner() >> owner
owner.isRoot() >> true
- propToConfig.toPropertyConfig(prop) >>> [propertyConfig, propertyConfig]
+ ((GrailsHibernatePersistentProperty)prop).getMappedForm() >>> [propertyConfig, propertyConfig]
propertyConfig.isUnique() >> false
propertyConfig.isUniqueWithinGroup() >> false
@@ -492,7 +475,6 @@ class ColumnBinderSpec extends Specification {
given:
def namingStrategy = Mock(PersistentEntityNamingStrategy)
def columnNameFetcher = Mock(ColumnNameForPropertyAndPathFetcher)
- def propToConfig = Mock(PersistentPropertyToPropertyConfig)
def stringBinder = Mock(StringColumnConstraintsBinder)
def numericBinder = Mock(NumericColumnConstraintsBinder)
def keyCreator = Mock(CreateKeyForProps)
@@ -502,7 +484,6 @@ class ColumnBinderSpec extends Specification {
def binder = new ColumnBinder(
columnNameFetcher,
- propToConfig,
stringBinder,
numericBinder,
keyCreator,
@@ -510,7 +491,7 @@ class ColumnBinderSpec extends Specification {
indexBinder
)
- def prop = Mock(PersistentProperty)
+ def prop = Mock(PersistentProperty, additionalInterfaces: [GrailsHibernatePersistentProperty])
def parentProp = Mock(PersistentProperty)
def owner = Mock(GrailsHibernatePersistentEntity)
def propertyConfig = Mock(PropertyConfig)
@@ -523,7 +504,7 @@ class ColumnBinderSpec extends Specification {
parentProp.isNullable() >> false
prop.getOwner() >> owner
owner.isRoot() >> true
- propToConfig.toPropertyConfig(prop) >>> [propertyConfig, propertyConfig]
+ ((GrailsHibernatePersistentProperty)prop).getMappedForm() >>> [propertyConfig, propertyConfig]
propertyConfig.isUnique() >> false
propertyConfig.isUniqueWithinGroup() >> false
@@ -541,7 +522,6 @@ class ColumnBinderSpec extends Specification {
given:
def namingStrategy = Mock(PersistentEntityNamingStrategy)
def columnNameFetcher = Mock(ColumnNameForPropertyAndPathFetcher)
- def propToConfig = Mock(PersistentPropertyToPropertyConfig)
def stringBinder = Mock(StringColumnConstraintsBinder)
def numericBinder = Mock(NumericColumnConstraintsBinder)
def keyCreator = Mock(CreateKeyForProps)
@@ -551,7 +531,6 @@ class ColumnBinderSpec extends Specification {
def binder = new ColumnBinder(
columnNameFetcher,
- propToConfig,
stringBinder,
numericBinder,
keyCreator,
@@ -559,7 +538,7 @@ class ColumnBinderSpec extends Specification {
indexBinder
)
- def prop = Mock(PersistentProperty)
+ def prop = Mock(PersistentProperty, additionalInterfaces: [GrailsHibernatePersistentProperty])
def owner = Mock(GrailsHibernatePersistentEntity)
def column = new Column("test")
def table = new Table()
@@ -574,7 +553,7 @@ class ColumnBinderSpec extends Specification {
when:
// Unique true, withinGroup false => unique true
def pc1 = Mock(PropertyConfig)
- propToConfig.toPropertyConfig(prop) >>> [pc1, pc1]
+ ((GrailsHibernatePersistentProperty)prop).getMappedForm() >>> [pc1, pc1]
pc1.isUnique() >> true
pc1.isUniqueWithinGroup() >> false
binder.bindColumn(prop, null, column, null, null, table)
@@ -588,7 +567,6 @@ class ColumnBinderSpec extends Specification {
given:
def namingStrategy = Mock(PersistentEntityNamingStrategy)
def columnNameFetcher = Mock(ColumnNameForPropertyAndPathFetcher)
- def propToConfig = Mock(PersistentPropertyToPropertyConfig)
def stringBinder = Mock(StringColumnConstraintsBinder)
def numericBinder = Mock(NumericColumnConstraintsBinder)
def keyCreator = Mock(CreateKeyForProps)
@@ -598,7 +576,6 @@ class ColumnBinderSpec extends Specification {
def binder = new ColumnBinder(
columnNameFetcher,
- propToConfig,
stringBinder,
numericBinder,
keyCreator,
@@ -606,7 +583,7 @@ class ColumnBinderSpec extends Specification {
indexBinder
)
- def prop = Mock(PersistentProperty)
+ def prop = Mock(PersistentProperty, additionalInterfaces: [GrailsHibernatePersistentProperty])
def owner = Mock(GrailsHibernatePersistentEntity)
def column = new Column("test")
def table = new Table()
@@ -623,7 +600,7 @@ class ColumnBinderSpec extends Specification {
// Unique true, withinGroup true => unique false
def column2 = new Column("test2")
def pc2 = Mock(PropertyConfig)
- propToConfig.toPropertyConfig(prop) >> pc2
+ ((GrailsHibernatePersistentProperty)prop).getMappedForm() >> pc2
pc2.isUnique() >> true
pc2.isUniqueWithinGroup() >> true
binder.bindColumn(prop, null, column2, null, null, table)
@@ -637,7 +614,6 @@ class ColumnBinderSpec extends Specification {
given:
def namingStrategy = Mock(PersistentEntityNamingStrategy)
def columnNameFetcher = Mock(ColumnNameForPropertyAndPathFetcher)
- def propToConfig = Mock(PersistentPropertyToPropertyConfig)
def stringBinder = Mock(StringColumnConstraintsBinder)
def numericBinder = Mock(NumericColumnConstraintsBinder)
def keyCreator = Mock(CreateKeyForProps)
@@ -647,7 +623,6 @@ class ColumnBinderSpec extends Specification {
def binder = new ColumnBinder(
columnNameFetcher,
- propToConfig,
stringBinder,
numericBinder,
keyCreator,
@@ -655,7 +630,7 @@ class ColumnBinderSpec extends Specification {
indexBinder
)
- def prop = Mock(PersistentProperty)
+ def prop = Mock(PersistentProperty, additionalInterfaces: [GrailsHibernatePersistentProperty])
def owner = Mock(GrailsHibernatePersistentEntity)
def column = new Column("test")
def table = new Table()
@@ -672,7 +647,7 @@ class ColumnBinderSpec extends Specification {
// Unique false => unique false
def column3 = new Column("test3")
def pc3 = Mock(PropertyConfig)
- propToConfig.toPropertyConfig(prop) >>> [pc3, pc3]
+ ((GrailsHibernatePersistentProperty)prop).getMappedForm() >>> [pc3, pc3]
pc3.isUnique() >> false
pc3.isUniqueWithinGroup() >> false
binder.bindColumn(prop, null, column3, null, null, table)
@@ -685,7 +660,6 @@ class ColumnBinderSpec extends Specification {
given:
def namingStrategy = Mock(PersistentEntityNamingStrategy)
def columnNameFetcher = Mock(ColumnNameForPropertyAndPathFetcher)
- def propToConfig = Mock(PersistentPropertyToPropertyConfig)
def stringBinder = Mock(StringColumnConstraintsBinder)
def numericBinder = Mock(NumericColumnConstraintsBinder)
def keyCreator = Mock(CreateKeyForProps)
@@ -695,7 +669,6 @@ class ColumnBinderSpec extends Specification {
def binder = new ColumnBinder(
columnNameFetcher,
- propToConfig,
stringBinder,
numericBinder,
keyCreator,
@@ -703,7 +676,7 @@ class ColumnBinderSpec extends Specification {
indexBinder
)
- def prop = Mock(PersistentProperty)
+ def prop = Mock(PersistentProperty, additionalInterfaces: [GrailsHibernatePersistentProperty])
def owner = Mock(GrailsHibernatePersistentEntity)
def mapping = Mock(Mapping)
def propertyConfig = Mock(PropertyConfig)
@@ -718,7 +691,7 @@ class ColumnBinderSpec extends Specification {
owner.isRoot() >> false
owner.getMappedForm() >> mapping
mapping.getTablePerHierarchy() >> false
- propToConfig.toPropertyConfig(prop) >>> [propertyConfig, propertyConfig]
+ ((GrailsHibernatePersistentProperty)prop).getMappedForm() >>> [propertyConfig, propertyConfig]
propertyConfig.isUnique() >> false
propertyConfig.isUniqueWithinGroup() >> false
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ColumnNameForPropertyAndPathFetcherSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ColumnNameForPropertyAndPathFetcherSpec.groovy
index ed963ccef9..2af0a63884 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ColumnNameForPropertyAndPathFetcherSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ColumnNameForPropertyAndPathFetcherSpec.groovy
@@ -3,6 +3,7 @@ package org.grails.orm.hibernate.cfg.domainbinding
import org.grails.datastore.mapping.model.PersistentEntity
import org.grails.datastore.mapping.model.PersistentProperty
import org.grails.orm.hibernate.cfg.ColumnConfig
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty
import org.grails.orm.hibernate.cfg.Mapping
import org.grails.orm.hibernate.cfg.PersistentEntityNamingStrategy
import org.grails.orm.hibernate.cfg.PropertyConfig
@@ -16,22 +17,20 @@ class ColumnNameForPropertyAndPathFetcherSpec extends Specification {
def "when ColumnConfig is null and mapping has explicit column then it is used"() {
given:
def namingStrategy = Mock(PersistentEntityNamingStrategy)
- def propToConfig = Mock(PersistentPropertyToPropertyConfig)
def defaultColumnFetcher = Mock(DefaultColumnNameFetcher)
def fetcher = new ColumnNameForPropertyAndPathFetcher(
namingStrategy,
- propToConfig,
defaultColumnFetcher,
backticksRemover
)
- def grailsProp = Mock(PersistentProperty)
+ def grailsProp = Mock(GrailsHibernatePersistentProperty)
def owner = Mock(PersistentEntity)
def mapping = Mock(Mapping)
def pc = Mock(PropertyConfig)
grailsProp.supportsJoinColumnMapping() >> false
- propToConfig.toPropertyConfig(grailsProp) >> pc
+ grailsProp.getMappedForm() >> pc
pc.getColumn() >> "explicit_col"
when:
@@ -44,23 +43,21 @@ class ColumnNameForPropertyAndPathFetcherSpec extends Specification {
def "when ColumnConfig provided and join key mapping exists then join key name is used"() {
given:
def namingStrategy = Mock(PersistentEntityNamingStrategy)
- def propToConfig = Mock(PersistentPropertyToPropertyConfig)
def defaultColumnFetcher = Mock(DefaultColumnNameFetcher)
def fetcher = new ColumnNameForPropertyAndPathFetcher(
namingStrategy,
- propToConfig,
defaultColumnFetcher,
backticksRemover
)
- def grailsProp = Mock(PersistentProperty)
+ def grailsProp = Mock(GrailsHibernatePersistentProperty)
def providedColumn = new ColumnConfig(name: "ignored_when_join_key")
def pc = Mock(PropertyConfig)
def joinTable = Mock(org.grails.orm.hibernate.cfg.JoinTable)
def key = new ColumnConfig(name: "join_key_name")
grailsProp.supportsJoinColumnMapping() >> true
- propToConfig.toPropertyConfig(grailsProp) >> pc
+ grailsProp.getMappedForm() >> pc
pc.hasJoinKeyMapping() >> true
pc.getJoinTable() >> joinTable
joinTable.getKey() >> key
@@ -76,11 +73,9 @@ class ColumnNameForPropertyAndPathFetcherSpec extends Specification {
def "when no explicit column then builds from path '#path' and default column '#defaultCol' with backticks removed"() {
given:
def namingStrategy = Mock(PersistentEntityNamingStrategy)
- def propToConfig = Mock(PersistentPropertyToPropertyConfig)
def defaultColumnFetcher = Mock(DefaultColumnNameFetcher)
def fetcher = new ColumnNameForPropertyAndPathFetcher(
namingStrategy,
- propToConfig,
defaultColumnFetcher,
backticksRemover
)
@@ -108,11 +103,9 @@ class ColumnNameForPropertyAndPathFetcherSpec extends Specification {
def "when path is empty falls back to default column name only"() {
given:
def namingStrategy = Mock(PersistentEntityNamingStrategy)
- def propToConfig = Mock(PersistentPropertyToPropertyConfig)
def defaultColumnFetcher = Mock(DefaultColumnNameFetcher)
def fetcher = new ColumnNameForPropertyAndPathFetcher(
namingStrategy,
- propToConfig,
defaultColumnFetcher,
backticksRemover
)
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ComponentPropertyBinderSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ComponentPropertyBinderSpec.groovy
index a8e5db3bf2..46c73fcd4a 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ComponentPropertyBinderSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ComponentPropertyBinderSpec.groovy
@@ -1,6 +1,7 @@
package org.grails.orm.hibernate.cfg.domainbinding
import grails.gorm.specs.HibernateGormDatastoreSpec
+import org.grails.datastore.mapping.model.MappingContext
import org.grails.datastore.mapping.model.PersistentEntity
import org.grails.datastore.mapping.model.PersistentProperty
import org.grails.datastore.mapping.model.types.Association
@@ -8,6 +9,7 @@ import org.grails.datastore.mapping.model.types.Embedded
import org.grails.datastore.mapping.model.types.ManyToOne as GormManyToOne
import org.grails.datastore.mapping.model.types.OneToOne as GormOneToOne
import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentEntity
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty
import org.grails.orm.hibernate.cfg.Mapping
import org.grails.orm.hibernate.cfg.MappingCacheHolder
import org.grails.orm.hibernate.cfg.PersistentEntityNamingStrategy
@@ -27,13 +29,24 @@ import spock.lang.Subject
class ComponentPropertyBinderSpec extends HibernateGormDatastoreSpec {
+ abstract static class TestManyToOne extends GormManyToOne<PropertyConfig> implements GrailsHibernatePersistentProperty {
+ TestManyToOne(PersistentEntity owner, MappingContext context, java.beans.PropertyDescriptor descriptor) {
+ super(owner, context, descriptor)
+ }
+ }
+
+ abstract static class TestOneToOne extends GormOneToOne<PropertyConfig> implements GrailsHibernatePersistentProperty {
+ TestOneToOne(PersistentEntity owner, MappingContext context, java.beans.PropertyDescriptor descriptor) {
+ super(owner, context, descriptor)
+ }
+ }
+
PersistentEntityNamingStrategy namingStrategy = Mock(PersistentEntityNamingStrategy)
MappingCacheHolder mappingCacheHolder = Mock(MappingCacheHolder)
CollectionHolder collectionHolder = new CollectionHolder([:])
EnumTypeBinder enumTypeBinder = Mock(EnumTypeBinder)
PropertyFromValueCreator propertyFromValueCreator = Mock(PropertyFromValueCreator)
ComponentBinder componentBinder = Mock(ComponentBinder)
- PersistentPropertyToPropertyConfig persistentPropertyToPropertyConfig = new PersistentPropertyToPropertyConfig()
@Subject
ComponentPropertyBinder binder
@@ -46,8 +59,7 @@ class ComponentPropertyBinderSpec extends HibernateGormDatastoreSpec {
collectionHolder,
enumTypeBinder,
propertyFromValueCreator,
- componentBinder,
- persistentPropertyToPropertyConfig
+ componentBinder
)
}
@@ -65,10 +77,10 @@ class ComponentPropertyBinderSpec extends HibernateGormDatastoreSpec {
def root = new RootClass(metadataBuildingContext)
def component = new Component(metadataBuildingContext, root)
def table = new Table("my_table")
- def ownerEntity = GroovyMock(GrailsHibernatePersistentEntity)
+ def ownerEntity = Mock(GrailsHibernatePersistentEntity)
ownerEntity.isRoot() >> true
- def currentGrailsProp = GroovyMock(PersistentProperty)
- def componentProperty = GroovyMock(PersistentProperty)
+ def currentGrailsProp = Mock(GrailsHibernatePersistentProperty)
+ def componentProperty = Mock(PersistentProperty)
def mappings = Mock(InFlightMetadataCollector)
def hibernateProperty = new Property()
hibernateProperty.setName("street")
@@ -95,10 +107,10 @@ class ComponentPropertyBinderSpec extends HibernateGormDatastoreSpec {
def root = new RootClass(metadataBuildingContext)
def component = new Component(metadataBuildingContext, root)
def table = new Table("my_table")
- def ownerEntity = GroovyMock(GrailsHibernatePersistentEntity)
+ def ownerEntity = Mock(GrailsHibernatePersistentEntity)
ownerEntity.isRoot() >> true
- def currentGrailsProp = GroovyMock(GormManyToOne)
- def componentProperty = GroovyMock(PersistentProperty)
+ def currentGrailsProp = Mock(TestManyToOne)
+ def componentProperty = Mock(PersistentProperty)
def mappings = Mock(InFlightMetadataCollector)
def hibernateProperty = new Property()
hibernateProperty.setName("owner")
@@ -126,10 +138,10 @@ class ComponentPropertyBinderSpec extends HibernateGormDatastoreSpec {
def root = new RootClass(metadataBuildingContext)
def component = new Component(metadataBuildingContext, root)
def table = new Table("my_table")
- def ownerEntity = GroovyMock(GrailsHibernatePersistentEntity)
+ def ownerEntity = Mock(GrailsHibernatePersistentEntity)
ownerEntity.isRoot() >> true
- def currentGrailsProp = GroovyMock(GormOneToOne)
- def componentProperty = GroovyMock(PersistentProperty)
+ def currentGrailsProp = Mock(TestOneToOne)
+ def componentProperty = Mock(PersistentProperty)
def mappings = Mock(InFlightMetadataCollector)
def hibernateProperty = new Property()
hibernateProperty.setName("detail")
@@ -137,13 +149,13 @@ class ComponentPropertyBinderSpec extends HibernateGormDatastoreSpec {
def mapping = new Mapping()
ownerEntity.getMappedForm() >> mapping
currentGrailsProp.getOwner() >> ownerEntity
- currentGrailsProp.getInverseSide() >> Mock(Association) {
+ ((Association)currentGrailsProp).getInverseSide() >> Mock(Association) {
isHasOne() >> false
getOwner() >> Mock(GrailsHibernatePersistentEntity) { getName() >> "Other" }
getName() >> "other"
}
currentGrailsProp.getType() >> Object
- currentGrailsProp.canBindOneToOneWithSingleColumnAndForeignKey() >> true
+ ((Association)currentGrailsProp).canBindOneToOneWithSingleColumnAndForeignKey() >> true
setupProperty(currentGrailsProp, "detail", mapping, ownerEntity)
propertyFromValueCreator.createProperty(_ as HibernateOneToOne, currentGrailsProp) >> hibernateProperty
@@ -162,10 +174,10 @@ class ComponentPropertyBinderSpec extends HibernateGormDatastoreSpec {
def root = new RootClass(metadataBuildingContext)
def component = new Component(metadataBuildingContext, root)
def table = new Table("my_table")
- def ownerEntity = GroovyMock(GrailsHibernatePersistentEntity)
+ def ownerEntity = Mock(GrailsHibernatePersistentEntity)
ownerEntity.isRoot() >> true
- def currentGrailsProp = GroovyMock(PersistentProperty)
- def componentProperty = GroovyMock(PersistentProperty)
+ def currentGrailsProp = Mock(GrailsHibernatePersistentProperty)
+ def componentProperty = Mock(PersistentProperty)
def mappings = Mock(InFlightMetadataCollector)
def hibernateProperty = new Property()
hibernateProperty.setName("type")
@@ -185,8 +197,6 @@ class ComponentPropertyBinderSpec extends HibernateGormDatastoreSpec {
then:
1 * enumTypeBinder.bindEnumType(currentGrailsProp, MyEnum, _ as BasicValue, "address_type_col")
- 1 * propertyFromValueCreator.createProperty(_ as BasicValue, currentGrailsProp) >> hibernateProperty
- component.getProperty("type") == hibernateProperty
}
def "should set columns to nullable when component property is nullable"() {
@@ -195,11 +205,11 @@ class ComponentPropertyBinderSpec extends HibernateGormDatastoreSpec {
def root = new RootClass(metadataBuildingContext)
def component = new Component(metadataBuildingContext, root)
def table = new Table("my_table")
- def ownerEntity = GroovyMock(GrailsHibernatePersistentEntity)
+ def ownerEntity = Mock(GrailsHibernatePersistentEntity)
ownerEntity.isRoot() >> true
- def currentGrailsProp = GroovyMock(PersistentProperty)
- def componentProperty = GroovyMock(PersistentProperty)
- def ownerEntityGHPE = GroovyMock(GrailsHibernatePersistentEntity)
+ def currentGrailsProp = Mock(GrailsHibernatePersistentProperty)
+ def componentProperty = Mock(PersistentProperty)
+ def ownerEntityGHPE = Mock(GrailsHibernatePersistentEntity)
def mappings = Mock(InFlightMetadataCollector)
def hibernateProperty = new Property()
hibernateProperty.setName("street")
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CompositeIdentifierToManyToOneBinderSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CompositeIdentifierToManyToOneBinderSpec.groovy
index 8455b5b8a4..aa5d5cd012 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CompositeIdentifierToManyToOneBinderSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CompositeIdentifierToManyToOneBinderSpec.groovy
@@ -5,6 +5,7 @@ import org.grails.datastore.mapping.model.PersistentProperty
import org.grails.datastore.mapping.model.types.ToOne
import org.grails.orm.hibernate.cfg.ColumnConfig
import org.grails.orm.hibernate.cfg.CompositeIdentity
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty
import org.grails.orm.hibernate.cfg.PersistentEntityNamingStrategy
import org.grails.orm.hibernate.cfg.PropertyConfig
import org.hibernate.mapping.SimpleValue
@@ -19,15 +20,14 @@ class CompositeIdentifierToManyToOneBinderSpec extends Specification {
def tableNameFetcher = Stub(TableNameFetcher)
def namingStrategy = Stub(PersistentEntityNamingStrategy)
def columnNameFetcher = Stub(DefaultColumnNameFetcher)
- def propertyConfigConverter = Stub(PersistentPropertyToPropertyConfig)
def backticksRemover = Stub(BackticksRemover)
def simpleValueBinder = Mock(SimpleValueBinder) // Use Mock to verify interaction
// Instantiate the binder with stubs
- def binder = new CompositeIdentifierToManyToOneBinder(calculator, tableNameFetcher, namingStrategy, columnNameFetcher, propertyConfigConverter, backticksRemover, simpleValueBinder)
+ def binder = new CompositeIdentifierToManyToOneBinder(calculator, tableNameFetcher, namingStrategy, columnNameFetcher, backticksRemover, simpleValueBinder)
// 2. Set up stubs for the method arguments
- def association = Stub(ToOne)
+ def association = Stub(ToOne, additionalInterfaces: [GrailsHibernatePersistentProperty])
def value = Stub(SimpleValue)
def refDomainClass = Stub(PersistentEntity)
def path = "/test"
@@ -39,7 +39,7 @@ class CompositeIdentifierToManyToOneBinderSpec extends Specification {
// 3. Define the nested composite key scenario
def propertyConfig = new PropertyConfig()
- propertyConfigConverter.toPropertyConfig(association) >> propertyConfig
+ association.getMappedForm() >> propertyConfig
calculator.calculateForeignKeyColumnCount(refDomainClass, propertyNames) >> 2
@@ -65,7 +65,7 @@ class CompositeIdentifierToManyToOneBinderSpec extends Specification {
backticksRemover.apply(_) >> { String s -> s }
when:
- binder.bindCompositeIdentifierToManyToOne(association, value, compositeId, refDomainClass, path)
+ binder.bindCompositeIdentifierToManyToOne(association as ToOne, value, compositeId, refDomainClass, path)
then:
// 5. Verify the final generated column names
@@ -75,7 +75,7 @@ class CompositeIdentifierToManyToOneBinderSpec extends Specification {
finalColumns[1].getName() == "ref_table_nested_entity_col_part_b_col"
and: // 6. Verify the call to the simple value binder
- 1 * simpleValueBinder.bindSimpleValue(association, null, value, path)
+ 1 * simpleValueBinder.bindSimpleValue(association as PersistentProperty, null, value, path)
}
def "Test bindCompositeIdentifierToManyToOne when column count matches"() {
@@ -85,14 +85,13 @@ class CompositeIdentifierToManyToOneBinderSpec extends Specification {
def tableNameFetcher = Mock(TableNameFetcher)
def namingStrategy = Mock(PersistentEntityNamingStrategy)
def columnNameFetcher = Mock(DefaultColumnNameFetcher)
- def propertyConfigConverter = Stub(PersistentPropertyToPropertyConfig)
def backticksRemover = Mock(BackticksRemover)
def simpleValueBinder = Mock(SimpleValueBinder)
- def binder = new CompositeIdentifierToManyToOneBinder(calculator, tableNameFetcher, namingStrategy, columnNameFetcher, propertyConfigConverter, backticksRemover, simpleValueBinder)
+ def binder = new CompositeIdentifierToManyToOneBinder(calculator, tableNameFetcher, namingStrategy, columnNameFetcher, backticksRemover, simpleValueBinder)
// 2. Set up arguments
- def association = Stub(ToOne)
+ def association = Stub(ToOne, additionalInterfaces: [GrailsHibernatePersistentProperty])
def value = Stub(SimpleValue)
def compositeId = new CompositeIdentity()
compositeId.setPropertyNames(["prop1", "prop2"] as String[])
@@ -103,13 +102,13 @@ class CompositeIdentifierToManyToOneBinderSpec extends Specification {
def propertyConfig = new PropertyConfig()
propertyConfig.getColumns().add(new ColumnConfig())
propertyConfig.getColumns().add(new ColumnConfig())
- propertyConfigConverter.toPropertyConfig(association) >> propertyConfig
+ association.getMappedForm() >> propertyConfig
// The calculated length is the same as the number of columns already in the config
calculator.calculateForeignKeyColumnCount(refDomainClass, _ as String[]) >> 2
when:
- binder.bindCompositeIdentifierToManyToOne(association, value, compositeId, refDomainClass, path)
+ binder.bindCompositeIdentifierToManyToOne(association as ToOne, value, compositeId, refDomainClass, path)
then:
// 4. Verify the column name generation logic is skipped
@@ -119,6 +118,6 @@ class CompositeIdentifierToManyToOneBinderSpec extends Specification {
0 * backticksRemover._
and: // 5. Verify the simple value binder is still called
- 1 * simpleValueBinder.bindSimpleValue(association, null, value, path)
+ 1 * simpleValueBinder.bindSimpleValue(association as PersistentProperty, null, value, path)
}
}
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CreateKeyForPropsSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CreateKeyForPropsSpec.groovy
index 4123697b4a..bbe50a56e7 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CreateKeyForPropsSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CreateKeyForPropsSpec.groovy
@@ -2,6 +2,7 @@ package org.grails.orm.hibernate.cfg.domainbinding
import org.grails.datastore.mapping.model.PersistentEntity
import org.grails.datastore.mapping.model.PersistentProperty
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty
import org.hibernate.MappingException
import org.hibernate.mapping.Table
import spock.lang.Specification
@@ -12,11 +13,10 @@ class CreateKeyForPropsSpec extends Specification {
given:
def columnNameFetcher = Mock(ColumnNameForPropertyAndPathFetcher)
def uniqueKeyCreator = Mock(UniqueKeyForColumnsCreator)
- def propToConfig = Mock(PersistentPropertyToPropertyConfig)
- def subject = new CreateKeyForProps(columnNameFetcher, uniqueKeyCreator, propToConfig)
+ def subject = new CreateKeyForProps(columnNameFetcher, uniqueKeyCreator)
def owner = Mock(PersistentEntity)
- def grailsProp = Mock(PersistentProperty) {
+ def grailsProp = Mock(GrailsHibernatePersistentProperty) {
getOwner() >> owner
}
@@ -25,7 +25,7 @@ class CreateKeyForPropsSpec extends Specification {
isUniqueWithinGroup() >> true
getUniquenessGroup() >> ["p1", "p2"]
}
- propToConfig.toPropertyConfig(grailsProp) >> mappedForm
+ grailsProp.getMappedForm() >> mappedForm
def otherProp1 = Mock(PersistentProperty)
def otherProp2 = Mock(PersistentProperty)
@@ -43,7 +43,7 @@ class CreateKeyForPropsSpec extends Specification {
subject.createKeyForProps(grailsProp, path, table, baseColumnName)
then:
- 1 * propToConfig.toPropertyConfig(grailsProp) >> mappedForm
+ 1 * grailsProp.getMappedForm() >> mappedForm
1 * grailsProp.getOwner() >> owner
1 * mappedForm.isUnique() >> true
1 * mappedForm.isUniqueWithinGroup() >> true
@@ -59,40 +59,37 @@ class CreateKeyForPropsSpec extends Specification {
given:
def columnNameFetcher = Mock(ColumnNameForPropertyAndPathFetcher)
def uniqueKeyCreator = Mock(UniqueKeyForColumnsCreator)
- def propToConfig = Mock(PersistentPropertyToPropertyConfig)
- def subject = new CreateKeyForProps(columnNameFetcher, uniqueKeyCreator, propToConfig)
+ def subject = new CreateKeyForProps(columnNameFetcher, uniqueKeyCreator)
def owner = Mock(PersistentEntity)
- def grailsProp = Mock(PersistentProperty) { getOwner() >> owner }
+ def grailsProp = Mock(GrailsHibernatePersistentProperty) { getOwner() >> owner }
def mappedForm = Mock(org.grails.orm.hibernate.cfg.PropertyConfig) {
isUnique() >> false
isUniqueWithinGroup() >> true
getUniquenessGroup() >> ["p1"]
}
- propToConfig.toPropertyConfig(grailsProp) >> mappedForm
+ grailsProp.getMappedForm() >> mappedForm
when:
subject.createKeyForProps(grailsProp, null, new Table("t"), "base")
then:
- 1 * propToConfig.toPropertyConfig(grailsProp) >> mappedForm
+ 1 * grailsProp.getMappedForm() >> mappedForm
0 * grailsProp.getOwner() >> owner
1 * mappedForm.isUnique() >> false
0 * uniqueKeyCreator._
0 * columnNameFetcher._
- 0 * _
}
def "throws when uniqueness group references unknown property"() {
given:
def columnNameFetcher = Mock(ColumnNameForPropertyAndPathFetcher)
def uniqueKeyCreator = Mock(UniqueKeyForColumnsCreator)
- def propToConfig = Mock(PersistentPropertyToPropertyConfig)
- def subject = new CreateKeyForProps(columnNameFetcher, uniqueKeyCreator, propToConfig)
+ def subject = new CreateKeyForProps(columnNameFetcher, uniqueKeyCreator)
def owner = Mock(PersistentEntity)
- def grailsProp = Mock(PersistentProperty) { getOwner() >> owner }
+ def grailsProp = Mock(GrailsHibernatePersistentProperty) { getOwner() >> owner }
owner.getJavaClass() >> CreateKeyForPropsSpec
def mappedForm = Mock(org.grails.orm.hibernate.cfg.PropertyConfig) {
@@ -100,7 +97,7 @@ class CreateKeyForPropsSpec extends Specification {
isUniqueWithinGroup() >> true
getUniquenessGroup() >> ["missingProp"]
}
- propToConfig.toPropertyConfig(grailsProp) >> mappedForm
+ grailsProp.getMappedForm() >> mappedForm
owner.getPropertyByName("missingProp") >> null
@@ -109,7 +106,7 @@ class CreateKeyForPropsSpec extends Specification {
then:
thrown(MappingException)
- 1 * propToConfig.toPropertyConfig(grailsProp) >> mappedForm
+ 1 * grailsProp.getMappedForm() >> mappedForm
1 * grailsProp.getOwner() >> owner
1 * mappedForm.isUnique() >> true
1 * mappedForm.isUniqueWithinGroup() >> true
@@ -118,6 +115,5 @@ class CreateKeyForPropsSpec extends Specification {
1 * owner.getPropertyByName("missingProp")
0 * uniqueKeyCreator._
0 * columnNameFetcher._
- 0 * _
}
}
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ManyToOneBinderSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ManyToOneBinderSpec.groovy
index 519404ad8d..3fd3863f82 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ManyToOneBinderSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ManyToOneBinderSpec.groovy
@@ -1,20 +1,19 @@
package org.grails.orm.hibernate.cfg.domainbinding
import grails.gorm.specs.HibernateGormDatastoreSpec
-import org.grails.datastore.mapping.model.PersistentEntity
+import org.grails.datastore.mapping.model.PersistentProperty
import org.grails.datastore.mapping.model.types.Association
import org.grails.datastore.mapping.model.types.ManyToMany
import org.grails.datastore.mapping.model.types.OneToOne
import org.grails.orm.hibernate.cfg.CompositeIdentity
import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentEntity
-import org.grails.orm.hibernate.cfg.JoinTable
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty
import org.grails.orm.hibernate.cfg.Mapping
import org.grails.orm.hibernate.cfg.PersistentEntityNamingStrategy
import org.grails.orm.hibernate.cfg.PropertyConfig
import org.hibernate.MappingException
import org.hibernate.mapping.Column
import org.hibernate.mapping.ManyToOne
-import spock.lang.Specification
import spock.lang.Unroll
class ManyToOneBinderSpec extends HibernateGormDatastoreSpec {
@@ -24,14 +23,13 @@ class ManyToOneBinderSpec extends HibernateGormDatastoreSpec {
given:
def namingStrategy = Mock(PersistentEntityNamingStrategy)
def simpleValueBinder = Mock(SimpleValueBinder)
- def propertyConfigConverter = Mock(PersistentPropertyToPropertyConfig)
def manyToOneValuesBinder = Mock(ManyToOneValuesBinder)
def compositeBinder = Mock(CompositeIdentifierToManyToOneBinder)
def columnFetcher = Mock(SimpleValueColumnFetcher)
- def binder = new ManyToOneBinder(namingStrategy, simpleValueBinder, propertyConfigConverter, manyToOneValuesBinder, compositeBinder, columnFetcher)
+ def binder = new ManyToOneBinder(namingStrategy, simpleValueBinder, manyToOneValuesBinder, compositeBinder, columnFetcher)
- def association = Mock(Association)
+ def association = Mock(Association, additionalInterfaces: [GrailsHibernatePersistentProperty])
def manyToOne = new ManyToOne(getGrailsDomainBinder().getMetadataBuildingContext(), null)
def path = "/test"
def mapping = new Mapping()
@@ -41,16 +39,16 @@ class ManyToOneBinderSpec extends HibernateGormDatastoreSpec {
def propertyConfig = new PropertyConfig()
association.getAssociatedEntity() >> refDomainClass
- propertyConfigConverter.toPropertyConfig(association) >> propertyConfig
+ ((GrailsHibernatePersistentProperty)association).getMappedForm() >> propertyConfig
mapping.setIdentity(hasCompositeId ? new CompositeIdentity() : null)
when:
- binder.bindManyToOne(association, manyToOne, path)
+ binder.bindManyToOne(association as Association, manyToOne, path)
then:
- 1 * manyToOneValuesBinder.bindManyToOneValues(association, manyToOne)
- compositeBinderCalls * compositeBinder.bindCompositeIdentifierToManyToOne(association, manyToOne, _, refDomainClass, path)
- simpleValueBinderCalls * simpleValueBinder.bindSimpleValue(association, null, manyToOne, path)
+ 1 * manyToOneValuesBinder.bindManyToOneValues(association as Association, manyToOne)
+ compositeBinderCalls * compositeBinder.bindCompositeIdentifierToManyToOne(association as Association, manyToOne, _, refDomainClass, path)
+ simpleValueBinderCalls * simpleValueBinder.bindSimpleValue(association as PersistentProperty, null, manyToOne, path)
where:
scenario | hasCompositeId | compositeBinderCalls | simpleValueBinderCalls
@@ -62,14 +60,13 @@ class ManyToOneBinderSpec extends HibernateGormDatastoreSpec {
given:
def namingStrategy = Mock(PersistentEntityNamingStrategy)
def simpleValueBinder = Mock(SimpleValueBinder)
- def propertyConfigConverter = Mock(PersistentPropertyToPropertyConfig)
def manyToOneValuesBinder = Mock(ManyToOneValuesBinder)
def compositeBinder = Mock(CompositeIdentifierToManyToOneBinder)
def columnFetcher = Mock(SimpleValueColumnFetcher)
- def binder = new ManyToOneBinder(namingStrategy, simpleValueBinder, propertyConfigConverter, manyToOneValuesBinder, compositeBinder, columnFetcher)
+ def binder = new ManyToOneBinder(namingStrategy, simpleValueBinder, manyToOneValuesBinder, compositeBinder, columnFetcher)
- def property = Mock(ManyToMany)
+ def property = Mock(ManyToMany, additionalInterfaces: [GrailsHibernatePersistentProperty])
def manyToOne = new ManyToOne(getGrailsDomainBinder().getMetadataBuildingContext(), null)
def mapping = new Mapping()
mapping.setColumns(new HashMap<String, PropertyConfig>())
@@ -81,15 +78,15 @@ class ManyToOneBinderSpec extends HibernateGormDatastoreSpec {
property.isCircular() >> true
property.getOwner() >> ownerEntity
property.getName() >> "myCircularProp"
- propertyConfigConverter.toPropertyConfig(property) >> propertyConfig
+ ((GrailsHibernatePersistentProperty)property).getMappedForm() >> propertyConfig
namingStrategy.resolveColumnName("myCircularProp") >> "my_circular_prop"
when:
- binder.bindManyToOne(property, manyToOne, "/test")
+ binder.bindManyToOne(property as Association, manyToOne, "/test")
then:
- 1 * manyToOneValuesBinder.bindManyToOneValues(property, manyToOne)
- 1 * simpleValueBinder.bindSimpleValue(property, null, manyToOne, "/test")
+ 1 * manyToOneValuesBinder.bindManyToOneValues(property as Association, manyToOne)
+ 1 * simpleValueBinder.bindSimpleValue(property as PersistentProperty, null, manyToOne, "/test")
def resultConfig = mapping.getColumns().get("myCircularProp")
resultConfig != null
resultConfig.getJoinTable().getKey().getName() == "my_circular_prop_id"
@@ -100,14 +97,13 @@ class ManyToOneBinderSpec extends HibernateGormDatastoreSpec {
given:
def namingStrategy = Mock(PersistentEntityNamingStrategy)
def simpleValueBinder = Mock(SimpleValueBinder)
- def propertyConfigConverter = Mock(PersistentPropertyToPropertyConfig)
def manyToOneValuesBinder = Mock(ManyToOneValuesBinder)
def compositeBinder = Mock(CompositeIdentifierToManyToOneBinder)
def columnFetcher = Mock(SimpleValueColumnFetcher)
- def binder = new ManyToOneBinder(namingStrategy, simpleValueBinder, propertyConfigConverter, manyToOneValuesBinder, compositeBinder, columnFetcher)
+ def binder = new ManyToOneBinder(namingStrategy, simpleValueBinder, manyToOneValuesBinder, compositeBinder, columnFetcher)
- def property = Mock(OneToOne)
+ def property = Mock(OneToOne, additionalInterfaces: [GrailsHibernatePersistentProperty])
def manyToOne = new ManyToOne(getGrailsDomainBinder().getMetadataBuildingContext(), null)
def mapping = new Mapping()
def refDomainClass = Mock(GrailsHibernatePersistentEntity) {
@@ -119,7 +115,7 @@ class ManyToOneBinderSpec extends HibernateGormDatastoreSpec {
property.getAssociatedEntity() >> refDomainClass
mapping.setIdentity(null)
- propertyConfigConverter.toPropertyConfig(property) >> propertyConfig
+ ((GrailsHibernatePersistentProperty)property).getMappedForm() >> propertyConfig
columnFetcher.getColumnForSimpleValue(manyToOne) >> column
propertyConfig.isUnique() >> isUnique
@@ -129,7 +125,7 @@ class ManyToOneBinderSpec extends HibernateGormDatastoreSpec {
inverseSide.isHasOne() >> isInverseHasOne
when:
- binder.bindManyToOne(property, manyToOne, "/test")
+ binder.bindManyToOne(property as Association, manyToOne, "/test")
then:
manyToOne.isAlternateUniqueKey()
@@ -152,14 +148,13 @@ class ManyToOneBinderSpec extends HibernateGormDatastoreSpec {
given:
def namingStrategy = Mock(PersistentEntityNamingStrategy)
def simpleValueBinder = Mock(SimpleValueBinder)
- def propertyConfigConverter = Mock(PersistentPropertyToPropertyConfig)
def manyToOneValuesBinder = Mock(ManyToOneValuesBinder)
def compositeBinder = Mock(CompositeIdentifierToManyToOneBinder)
def columnFetcher = Mock(SimpleValueColumnFetcher)
- def binder = new ManyToOneBinder(namingStrategy, simpleValueBinder, propertyConfigConverter, manyToOneValuesBinder, compositeBinder, columnFetcher)
+ def binder = new ManyToOneBinder(namingStrategy, simpleValueBinder, manyToOneValuesBinder, compositeBinder, columnFetcher)
- def property = Mock(OneToOne)
+ def property = Mock(OneToOne, additionalInterfaces: [GrailsHibernatePersistentProperty])
def manyToOne = new ManyToOne(getGrailsDomainBinder().getMetadataBuildingContext(), null)
def mapping = new Mapping()
def refDomainClass = Mock(GrailsHibernatePersistentEntity) {
@@ -169,11 +164,11 @@ class ManyToOneBinderSpec extends HibernateGormDatastoreSpec {
property.getAssociatedEntity() >> refDomainClass
mapping.setIdentity(null)
- propertyConfigConverter.toPropertyConfig(property) >> propertyConfig
+ ((GrailsHibernatePersistentProperty)property).getMappedForm() >> propertyConfig
columnFetcher.getColumnForSimpleValue(manyToOne) >> null
when:
- binder.bindManyToOne(property, manyToOne, "/test")
+ binder.bindManyToOne(property as Association, manyToOne, "/test")
then:
thrown(MappingException)
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ManyToOneValuesBinderSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ManyToOneValuesBinderSpec.groovy
index f58b5a19d4..f98f7529b2 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ManyToOneValuesBinderSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/ManyToOneValuesBinderSpec.groovy
@@ -3,6 +3,7 @@ package org.grails.orm.hibernate.cfg.domainbinding
import grails.gorm.specs.HibernateGormDatastoreSpec
import org.grails.datastore.mapping.model.PersistentEntity
import org.grails.datastore.mapping.model.types.Association
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty
import org.grails.orm.hibernate.cfg.PropertyConfig
import org.hibernate.FetchMode
import org.hibernate.mapping.ManyToOne
@@ -14,11 +15,10 @@ class ManyToOneValuesBinderSpec extends HibernateGormDatastoreSpec {
def "Test bindManyToOneValues with #scenario"() {
given:
// 1. Mock the dependency and use the protected constructor
- def propertyConfigConverter = Mock(PersistentPropertyToPropertyConfig)
- def binder = new ManyToOneValuesBinder(propertyConfigConverter)
+ def binder = new ManyToOneValuesBinder()
// 2. Set up mocks for the method arguments
- def association = Mock(Association)
+ def association = Mock(Association, additionalInterfaces: [GrailsHibernatePersistentProperty])
def manyToOne = new ManyToOne(getGrailsDomainBinder().getMetadataBuildingContext(),null)
def associatedEntity = Mock(PersistentEntity)
@@ -31,12 +31,12 @@ class ManyToOneValuesBinderSpec extends HibernateGormDatastoreSpec {
config.setIgnoreNotFound(testIgnoreNotFound)
// 4. Define mock behaviors
- propertyConfigConverter.toPropertyConfig(association) >> config
+ ((GrailsHibernatePersistentProperty)association).getMappedForm() >> config
association.getAssociatedEntity() >> associatedEntity
associatedEntity.getName() >> "AssociatedEntityName"
when:
- binder.bindManyToOneValues(association, manyToOne)
+ binder.bindManyToOneValues(association as Association, manyToOne)
then:
// 5. Verify that the correct values were set on the ManyToOne object
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/OneToOneBinderSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/OneToOneBinderSpec.groovy
index 2d17639bda..fc1cf94296 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/OneToOneBinderSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/OneToOneBinderSpec.groovy
@@ -3,6 +3,7 @@ package org.grails.orm.hibernate.cfg.domainbinding
import grails.gorm.specs.HibernateGormDatastoreSpec
import org.grails.datastore.mapping.model.types.OneToOne as GormOneToOne
import org.grails.datastore.mapping.model.PersistentEntity
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty
import org.grails.orm.hibernate.cfg.PropertyConfig
import org.hibernate.FetchMode
import org.hibernate.mapping.OneToOne as HibernateOneToOne
@@ -15,11 +16,10 @@ class OneToOneBinderSpec extends HibernateGormDatastoreSpec {
@Subject
OneToOneBinder binder
- PersistentPropertyToPropertyConfig mockConfigReader = Mock(PersistentPropertyToPropertyConfig)
SimpleValueBinder mockSimpleValueBinder = Mock(SimpleValueBinder)
def setup() {
- binder = new OneToOneBinder(getGrailsDomainBinder().getNamingStrategy(), mockConfigReader, mockSimpleValueBinder)
+ binder = new OneToOneBinder(getGrailsDomainBinder().getNamingStrategy(), mockSimpleValueBinder)
}
def "should bind one-to-one mapping with defaults"() {
@@ -28,10 +28,10 @@ class OneToOneBinderSpec extends HibernateGormDatastoreSpec {
def ownerRoot = new RootClass(metadataBuildingContext)
def hibernateOneToOne = new HibernateOneToOne(metadataBuildingContext, null, ownerRoot)
- def gormOneToOne = GroovyMock(GormOneToOne)
- def otherSide = GroovyMock(GormOneToOne)
- def owner = GroovyMock(PersistentEntity)
- def otherOwner = GroovyMock(PersistentEntity)
+ def gormOneToOne = Mock(GormOneToOne, additionalInterfaces: [GrailsHibernatePersistentProperty])
+ def otherSide = Mock(GormOneToOne)
+ def owner = Mock(PersistentEntity)
+ def otherOwner = Mock(PersistentEntity)
gormOneToOne.getInverseSide() >> otherSide
gormOneToOne.getName() >> "myOneToOne"
@@ -43,10 +43,10 @@ class OneToOneBinderSpec extends HibernateGormDatastoreSpec {
otherOwner.getName() >> "OtherEntity"
- mockConfigReader.toPropertyConfig(gormOneToOne) >> new PropertyConfig()
+ ((GrailsHibernatePersistentProperty)gormOneToOne).getMappedForm() >> new PropertyConfig()
when:
- binder.bindOneToOne(gormOneToOne, hibernateOneToOne, "")
+ binder.bindOneToOne(gormOneToOne as GormOneToOne, hibernateOneToOne, "")
then:
!hibernateOneToOne.isConstrained()
@@ -64,10 +64,10 @@ class OneToOneBinderSpec extends HibernateGormDatastoreSpec {
def ownerRoot = new RootClass(metadataBuildingContext)
def hibernateOneToOne = new HibernateOneToOne(metadataBuildingContext, null, ownerRoot)
- def gormOneToOne = GroovyMock(GormOneToOne)
- def otherSide = GroovyMock(GormOneToOne)
- def owner = GroovyMock(PersistentEntity)
- def otherOwner = GroovyMock(PersistentEntity)
+ def gormOneToOne = Mock(GormOneToOne, additionalInterfaces: [GrailsHibernatePersistentProperty])
+ def otherSide = Mock(GormOneToOne)
+ def owner = Mock(PersistentEntity)
+ def otherOwner = Mock(PersistentEntity)
gormOneToOne.getInverseSide() >> otherSide
gormOneToOne.getName() >> "myOneToOne"
@@ -79,11 +79,10 @@ class OneToOneBinderSpec extends HibernateGormDatastoreSpec {
otherOwner.getName() >> "OtherEntity"
def propertyConfig = new PropertyConfig()
- mockConfigReader.toPropertyConfig(gormOneToOne) >> propertyConfig
- mockConfigReader.toPropertyConfig(otherSide) >> propertyConfig // In case SimpleValueBinder needs it too
+ ((GrailsHibernatePersistentProperty)gormOneToOne).getMappedForm() >> propertyConfig
when:
- binder.bindOneToOne(gormOneToOne, hibernateOneToOne, "")
+ binder.bindOneToOne(gormOneToOne as GormOneToOne, hibernateOneToOne, "")
then:
hibernateOneToOne.isConstrained()
@@ -97,10 +96,10 @@ class OneToOneBinderSpec extends HibernateGormDatastoreSpec {
def ownerRoot = new RootClass(metadataBuildingContext)
def hibernateOneToOne = new HibernateOneToOne(metadataBuildingContext, null, ownerRoot)
- def gormOneToOne = GroovyMock(GormOneToOne)
- def otherSide = GroovyMock(GormOneToOne)
- def owner = GroovyMock(PersistentEntity)
- def otherOwner = GroovyMock(PersistentEntity)
+ def gormOneToOne = Mock(GormOneToOne, additionalInterfaces: [GrailsHibernatePersistentProperty])
+ def otherSide = Mock(GormOneToOne)
+ def owner = Mock(PersistentEntity)
+ def otherOwner = Mock(PersistentEntity)
def propertyConfig = new PropertyConfig()
propertyConfig.setFetch("join")
@@ -110,10 +109,10 @@ class OneToOneBinderSpec extends HibernateGormDatastoreSpec {
otherSide.getOwner() >> otherOwner
otherSide.isHasOne() >> false
- mockConfigReader.toPropertyConfig(gormOneToOne) >> propertyConfig
+ ((GrailsHibernatePersistentProperty)gormOneToOne).getMappedForm() >> propertyConfig
when:
- binder.bindOneToOne(gormOneToOne, hibernateOneToOne, "")
+ binder.bindOneToOne(gormOneToOne as GormOneToOne, hibernateOneToOne, "")
then:
hibernateOneToOne.getFetchMode() == FetchMode.JOIN
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/PersistentPropertyToPropertyConfigSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/PersistentPropertyToPropertyConfigSpec.groovy
deleted file mode 100644
index d93332de77..0000000000
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/PersistentPropertyToPropertyConfigSpec.groovy
+++ /dev/null
@@ -1,38 +0,0 @@
-package org.grails.orm.hibernate.cfg.domainbinding
-
-import org.grails.datastore.mapping.model.PersistentProperty
-import org.grails.orm.hibernate.cfg.PropertyConfig
-import org.hibernate.MappingException
-import spock.lang.Specification
-import spock.lang.Subject
-
-class PersistentPropertyToPropertyConfigSpec extends Specification {
-
- @Subject
- PersistentPropertyToPropertyConfig mapper = new PersistentPropertyToPropertyConfig()
-
- def "should return PropertyConfig when mappedForm is present"() {
- given:
- def propertyConfig = new PropertyConfig()
- def persistentProperty = Mock(PersistentProperty)
- persistentProperty.getMappedForm() >> propertyConfig
-
- when:
- def result = mapper.toPropertyConfig(persistentProperty)
-
- then:
- result == propertyConfig
- }
-
- def "should throw MappingException when mappedForm is null"() {
- given:
- def persistentProperty = Mock(PersistentProperty)
- persistentProperty.getMappedForm() >> null
-
- when:
- mapper.toPropertyConfig(persistentProperty)
-
- then:
- thrown(MappingException)
- }
-}
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/PropertyBinderSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/PropertyBinderSpec.groovy
index c44344032e..e31887a868 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/PropertyBinderSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/PropertyBinderSpec.groovy
@@ -2,8 +2,11 @@ package org.grails.orm.hibernate.cfg.domainbinding
import grails.gorm.specs.HibernateGormDatastoreSpec
import grails.persistence.Entity
+import org.grails.datastore.mapping.model.MappingContext
+import org.grails.datastore.mapping.model.PersistentEntity
import org.grails.datastore.mapping.model.PersistentProperty
import org.grails.datastore.mapping.model.types.Association
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty
import org.grails.orm.hibernate.cfg.PropertyConfig
import org.hibernate.mapping.Property
import spock.lang.Unroll
@@ -12,24 +15,27 @@ import org.hibernate.mapping.Value
class PropertyBinderSpec extends HibernateGormDatastoreSpec {
-
+ abstract static class TestAssociation extends Association<PropertyConfig> implements GrailsHibernatePersistentProperty {
+ TestAssociation(PersistentEntity owner, MappingContext context, java.beans.PropertyDescriptor descriptor) {
+ super(owner, context, descriptor)
+ }
+ }
@Unroll("test property binding for #propertyName")
void "test property binding"() {
given:
- def persistentPropertyToPropertyConfig = Mock(PersistentPropertyToPropertyConfig)
def cascadeBehaviorFetcher = Mock(CascadeBehaviorFetcher)
def bidirectionalManyToOneWithListMapping = Mock(BidirectionalManyToOneWithListMapping)
- def binder = new PropertyBinder(persistentPropertyToPropertyConfig, cascadeBehaviorFetcher, bidirectionalManyToOneWithListMapping)
+ def binder = new PropertyBinder(cascadeBehaviorFetcher, bidirectionalManyToOneWithListMapping)
- def persistentProperty = Mock(PersistentProperty)
+ def persistentProperty = Mock(GrailsHibernatePersistentProperty)
def property = new Property()
def value = Mock(Value)
property.setValue(value)
def config = Mock(PropertyConfig)
when:
- persistentPropertyToPropertyConfig.toPropertyConfig(persistentProperty) >> config
+ persistentProperty.getMappedForm() >> config
bidirectionalManyToOneWithListMapping.isBidirectionalManyToOneWithListMapping(persistentProperty, property) >> isBidirectional
config.getInsertable() >> insertable
config.getUpdatable() >> updateable
@@ -63,39 +69,38 @@ class PropertyBinderSpec extends HibernateGormDatastoreSpec {
void "test cascade behavior binding"() {
given:
- def persistentPropertyToPropertyConfig = Mock(PersistentPropertyToPropertyConfig)
def cascadeBehaviorFetcher = Mock(CascadeBehaviorFetcher)
def bidirectionalManyToOneWithListMapping = Mock(BidirectionalManyToOneWithListMapping)
- def binder = new PropertyBinder(persistentPropertyToPropertyConfig, cascadeBehaviorFetcher, bidirectionalManyToOneWithListMapping)
+ def binder = new PropertyBinder(cascadeBehaviorFetcher, bidirectionalManyToOneWithListMapping)
- def association = Mock(Association)
+ def association = Mock(TestAssociation)
def property = new Property()
def config = Mock(PropertyConfig)
when:
- persistentPropertyToPropertyConfig.toPropertyConfig(association) >> config
+ association.getMappedForm() >> config
config.getAccessType() >> AccessType.PROPERTY
- cascadeBehaviorFetcher.getCascadeBehaviour(association) >> "all-delete-orphan"
- binder.bindProperty(association, property)
+ cascadeBehaviorFetcher.getCascadeBehaviour(association as Association) >> "all-delete-orphan"
+ binder.bindProperty(association as Association, property)
then:
property.getCascade() == "all-delete-orphan"
}
- void "test property accessor name with real persistent property"() {
+ void "test property accessor name with mocked persistent property"() {
given:
- def persistentPropertyToPropertyConfig = Mock(PersistentPropertyToPropertyConfig)
def cascadeBehaviorFetcher = Mock(CascadeBehaviorFetcher)
def bidirectionalManyToOneWithListMapping = Mock(BidirectionalManyToOneWithListMapping)
- def binder = new PropertyBinder(persistentPropertyToPropertyConfig, cascadeBehaviorFetcher, bidirectionalManyToOneWithListMapping)
+ def binder = new PropertyBinder(cascadeBehaviorFetcher, bidirectionalManyToOneWithListMapping)
- def persistentProperty = createPersistentEntity(PropertyBinderSpecEntity).getPropertyByName("name")
+ def persistentProperty = Mock(GrailsHibernatePersistentProperty)
+ persistentProperty.getName() >> "name"
def property = new Property()
- def config = Mock(PropertyConfig)
+ def config = new PropertyConfig()
+ config.setAccessType(jakarta.persistence.AccessType.PROPERTY)
+ persistentProperty.getMappedForm() >> config
when:
- persistentPropertyToPropertyConfig.toPropertyConfig(persistentProperty) >> config
- config.getAccessType() >> AccessType.PROPERTY
binder.bindProperty(persistentProperty, property)
then:
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/SimpleValueBinderSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/SimpleValueBinderSpec.groovy
index c469b1659e..8f184cfbe7 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/SimpleValueBinderSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/SimpleValueBinderSpec.groovy
@@ -1,5 +1,7 @@
package org.grails.orm.hibernate.cfg.domainbinding
+import org.grails.datastore.mapping.model.MappingContext
+import org.grails.datastore.mapping.model.PersistentEntity
import org.grails.datastore.mapping.model.PersistentProperty
import org.grails.datastore.mapping.model.types.TenantId
import org.grails.orm.hibernate.cfg.ColumnConfig
@@ -8,22 +10,26 @@ import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty
import org.grails.orm.hibernate.cfg.Mapping
import org.grails.orm.hibernate.cfg.PersistentEntityNamingStrategy
import org.grails.orm.hibernate.cfg.PropertyConfig
-import org.hibernate.id.enhanced.SequenceStyleGenerator
+
import org.hibernate.mapping.Column
import org.hibernate.mapping.SimpleValue
import spock.lang.Specification
class SimpleValueBinderSpec extends Specification {
+ abstract static class TestTenantId extends TenantId<PropertyConfig> implements GrailsHibernatePersistentProperty {
+ TestTenantId(PersistentEntity owner, MappingContext context, String name, Class type) {
+ super(owner, context, name, type)
+ }
+ }
+
def namingStrategy = Mock(PersistentEntityNamingStrategy)
def columnConfigToColumnBinder = Mock(ColumnConfigToColumnBinder)
def columnBinder = Mock(ColumnBinder)
- def persistentPropertyToPropertyConfig = Mock(PersistentPropertyToPropertyConfig)
def binder = new SimpleValueBinder(namingStrategy,
columnConfigToColumnBinder,
- columnBinder,
- persistentPropertyToPropertyConfig)
+ columnBinder)
def "sets type from provider when present and applies type params"() {
given:
@@ -36,7 +42,7 @@ class SimpleValueBinderSpec extends Specification {
def props = new Properties(); props.setProperty('p1','v1')
// stubs
- persistentPropertyToPropertyConfig.toPropertyConfig(prop) >> pc
+ prop.getMappedForm() >> pc
prop.getOwner() >> owner
owner.getMappedForm() >> mapping
prop.getTypeName(mapping) >> "custom.Type"
@@ -71,7 +77,7 @@ class SimpleValueBinderSpec extends Specification {
def sv = Mock(SimpleValue)
sv.getTable() >> null
- persistentPropertyToPropertyConfig.toPropertyConfig(prop) >> pc
+ prop.getMappedForm() >> pc
prop.getOwner() >> owner
owner.getMappedForm() >> mapping
prop.getTypeName(mapping) >> null
@@ -94,7 +100,7 @@ class SimpleValueBinderSpec extends Specification {
def "derived property adds no columns but adds formula, except TenantId"() {
given:
def prop = Mock(GrailsHibernatePersistentProperty)
- def tenantProp = Mock(TenantId)
+ def tenantProp = Mock(TestTenantId)
def owner = Mock(GrailsHibernatePersistentEntity)
def mapping = Mock(Mapping)
def pc = Mock(PropertyConfig)
@@ -102,8 +108,8 @@ class SimpleValueBinderSpec extends Specification {
def sv = Mock(SimpleValue)
def sv2 = Mock(SimpleValue)
- persistentPropertyToPropertyConfig.toPropertyConfig(prop) >> pc
- persistentPropertyToPropertyConfig.toPropertyConfig(tenantProp) >> tenantPc
+ prop.getMappedForm() >> pc
+ tenantProp.getMappedForm() >> tenantPc
prop.getOwner() >> owner
tenantProp.getOwner() >> owner
owner.getMappedForm() >> mapping
@@ -122,7 +128,7 @@ class SimpleValueBinderSpec extends Specification {
0 * columnBinder.bindColumn(_, _, _, _, _, _)
when:
- binder.bindSimpleValue(tenantProp, null, sv2, null)
+ binder.bindSimpleValue(tenantProp as PersistentProperty, null, sv2, null)
then:
0 * sv2.addFormula(_)
@@ -142,7 +148,7 @@ class SimpleValueBinderSpec extends Specification {
sv.getTable() >> null
def genProps = new Properties(); genProps.setProperty('sequence','seq_name'); genProps.setProperty('foo','bar')
- persistentPropertyToPropertyConfig.toPropertyConfig(prop) >> pc
+ prop.getMappedForm() >> pc
prop.getOwner() >> owner
owner.getMappedForm() >> mapping
prop.getTypeName(mapping) >> 'Y'
@@ -174,7 +180,7 @@ class SimpleValueBinderSpec extends Specification {
def sv = Mock(SimpleValue)
sv.getTable() >> null
- persistentPropertyToPropertyConfig.toPropertyConfig(prop) >> pc
+ prop.getMappedForm() >> pc
prop.getOwner() >> owner
owner.getMappedForm() >> mapping
prop.getTypeName(mapping) >> 'Z'
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/TableForManyCalculatorSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/TableForManyCalculatorSpec.groovy
index 68f988594f..42c87a437b 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/TableForManyCalculatorSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/TableForManyCalculatorSpec.groovy
@@ -4,6 +4,7 @@ import org.grails.datastore.mapping.model.PersistentEntity
import org.grails.datastore.mapping.model.types.Basic
import org.grails.datastore.mapping.model.types.ManyToMany
import org.grails.datastore.mapping.model.types.ToMany
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty
import org.grails.orm.hibernate.cfg.JoinTable
import org.grails.orm.hibernate.cfg.PersistentEntityNamingStrategy
import org.grails.orm.hibernate.cfg.PropertyConfig
@@ -21,13 +22,12 @@ class TableForManyCalculatorSpec extends Specification {
def backticksRemover = Stub(BackticksRemover)
def shouldBind = Stub(ShouldCollectionBindWithJoinColumn)
def trimmer = Stub(BackTigsTrimmer)
- def configConverter = Stub(PersistentPropertyToPropertyConfig)
// 2. Instantiate the calculator with mocks
- def calculator = new TableForManyCalculator(namingStrategy, tableNameFetcher, backticksRemover, shouldBind, trimmer, configConverter)
+ def calculator = new TableForManyCalculator(namingStrategy, tableNameFetcher, backticksRemover, shouldBind, trimmer)
// 3. Set up stubs for the property and entities
- def property = Stub(mockClass)
+ def property = Stub(mockClass, additionalInterfaces: [GrailsHibernatePersistentProperty])
def ownerEntity = Stub(PersistentEntity)
def associatedEntity = Stub(PersistentEntity)
def config = new PropertyConfig()
@@ -46,19 +46,19 @@ class TableForManyCalculatorSpec extends Specification {
((ManyToMany)property).getInversePropertyName() >> "inverseProp"
}
- configConverter.toPropertyConfig(property) >> config
+ ((GrailsHibernatePersistentProperty)property).getMappedForm() >> config
namingStrategy.resolveColumnName("myProp") >> "my_prop_col"
namingStrategy.resolveColumnName("inverseProp") >> "inverse_prop_col"
tableNameFetcher.getTableName(ownerEntity) >> "owner_table"
tableNameFetcher.getTableName(associatedEntity) >> "associated_table"
- shouldBind.apply(property) >> shouldBindWithJoinColumn
+ shouldBind.apply(property as ToMany) >> shouldBindWithJoinColumn
// Make removers and trimmers pass through values for simplicity
backticksRemover.apply(_) >> { String s -> s }
trimmer.trimBackTigs(_) >> { String s -> s }
when:
- def result = calculator.calculateTableForMany(property, "default")
+ def result = calculator.calculateTableForMany(property as ToMany, "default")
then:
result == expectedTableName
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/UserTypeFetcherSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/UserTypeFetcherSpec.groovy
index ee60a73a71..6116da0a1e 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/UserTypeFetcherSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/UserTypeFetcherSpec.groovy
@@ -1,24 +1,23 @@
package org.grails.orm.hibernate.cfg.domainbinding
import org.grails.datastore.mapping.model.PersistentProperty
+import org.grails.orm.hibernate.cfg.GrailsHibernatePersistentProperty
import org.grails.orm.hibernate.cfg.PropertyConfig
import spock.lang.Specification
import spock.lang.Subject
class UserTypeFetcherSpec extends Specification {
- def mapper = Mock(PersistentPropertyToPropertyConfig)
-
@Subject
- UserTypeFetcher fetcher = new UserTypeFetcher(mapper)
+ UserTypeFetcher fetcher = new UserTypeFetcher()
def "should return user type when it is already a Class"() {
given:
- def persistentProperty = Mock(PersistentProperty)
+ def persistentProperty = Mock(GrailsHibernatePersistentProperty)
def config = new PropertyConfig()
config.setType(String)
- mapper.toPropertyConfig(persistentProperty) >> config
+ persistentProperty.getMappedForm() >> config
when:
def result = fetcher.getUserType(persistentProperty)
@@ -29,11 +28,11 @@ class UserTypeFetcherSpec extends Specification {
def "should return user type when it is a valid class name string"() {
given:
- def persistentProperty = Mock(PersistentProperty)
+ def persistentProperty = Mock(GrailsHibernatePersistentProperty)
def config = new PropertyConfig()
config.setType("java.lang.Integer")
- mapper.toPropertyConfig(persistentProperty) >> config
+ persistentProperty.getMappedForm() >> config
when:
def result = fetcher.getUserType(persistentProperty)
@@ -44,11 +43,11 @@ class UserTypeFetcherSpec extends Specification {
def "should return null if class name is invalid"() {
given:
- def persistentProperty = Mock(PersistentProperty)
+ def persistentProperty = Mock(GrailsHibernatePersistentProperty)
def config = new PropertyConfig()
config.setType("com.nonexistent.MyType")
- mapper.toPropertyConfig(persistentProperty) >> config
+ persistentProperty.getMappedForm() >> config
when:
def result = fetcher.getUserType(persistentProperty)
@@ -59,11 +58,11 @@ class UserTypeFetcherSpec extends Specification {
def "should return null if type object is null"() {
given:
- def persistentProperty = Mock(PersistentProperty)
+ def persistentProperty = Mock(GrailsHibernatePersistentProperty)
def config = new PropertyConfig()
config.setType(null)
- mapper.toPropertyConfig(persistentProperty) >> config
+ persistentProperty.getMappedForm() >> config
when:
def result = fetcher.getUserType(persistentProperty)