diff --git a/grails-datastore-gorm-hibernate-core/src/main/groovy/org/grails/orm/hibernate/cfg/AbstractGrailsDomainBinder.java b/grails-datastore-gorm-hibernate-core/src/main/groovy/org/grails/orm/hibernate/cfg/AbstractGrailsDomainBinder.java index 0a6927109a5..66c293e56bb 100644 --- a/grails-datastore-gorm-hibernate-core/src/main/groovy/org/grails/orm/hibernate/cfg/AbstractGrailsDomainBinder.java +++ b/grails-datastore-gorm-hibernate-core/src/main/groovy/org/grails/orm/hibernate/cfg/AbstractGrailsDomainBinder.java @@ -3170,98 +3170,100 @@ protected int getMaxSize(List inListValues) { protected abstract void handleLazyProxy(PersistentEntity domainClass, PersistentProperty grailsProperty); protected abstract boolean identityEnumTypeSupports(Class propertyType); -} -/** - * A Collection type, for the moment only Set is supported - * - * @author Graeme - */ -abstract class CollectionType { + /** + * A Collection type, for the moment only Set is supported + * + * @author Graeme + */ + static abstract class CollectionType { - protected Class clazz; - protected AbstractGrailsDomainBinder binder; + protected Class clazz; + protected AbstractGrailsDomainBinder binder; - protected static CollectionType SET; - protected static CollectionType LIST; - protected static CollectionType BAG; - protected static CollectionType MAP; - protected static boolean initialized; + protected static CollectionType SET; + protected static CollectionType LIST; + protected static CollectionType BAG; + protected static CollectionType MAP; + protected static boolean initialized; - protected static final Map, CollectionType> INSTANCES = new HashMap, CollectionType>(); + protected static final Map, CollectionType> INSTANCES = new HashMap, CollectionType>(); - public abstract Collection create(ToMany property, PersistentClass owner, - String path, Mappings mappings, String sessionFactoryBeanName) throws MappingException; + public abstract Collection create(ToMany property, PersistentClass owner, + String path, Mappings mappings, String sessionFactoryBeanName) throws MappingException; - protected CollectionType(Class clazz, AbstractGrailsDomainBinder binder) { - this.clazz = clazz; - this.binder = binder; - } + protected CollectionType(Class clazz, AbstractGrailsDomainBinder binder) { + this.clazz = clazz; + this.binder = binder; + } - @Override - public String toString() { - return clazz.getName(); - } + @Override + public String toString() { + return clazz.getName(); + } - protected void createInstances() { + protected void createInstances() { - if (initialized) { - return; + if (initialized) { + return; + } + + initialized = true; + + SET = new CollectionType(Set.class, binder) { + @Override + public Collection create(ToMany property, PersistentClass owner, + String path, Mappings mappings, String sessionFactoryBeanName) throws MappingException { + org.hibernate.mapping.Set coll = new org.hibernate.mapping.Set(mappings, owner); + coll.setCollectionTable(owner.getTable()); + binder.bindCollection(property, coll, owner, mappings, path, sessionFactoryBeanName); + return coll; + } + }; + INSTANCES.put(Set.class, SET); + INSTANCES.put(SortedSet.class, SET); + + LIST = new CollectionType(List.class, binder) { + @Override + public Collection create(ToMany property, PersistentClass owner, + String path, Mappings mappings, String sessionFactoryBeanName) throws MappingException { + org.hibernate.mapping.List coll = new org.hibernate.mapping.List(mappings, owner); + coll.setCollectionTable(owner.getTable()); + binder.bindCollection(property, coll, owner, mappings, path, sessionFactoryBeanName); + return coll; + } + }; + INSTANCES.put(List.class, LIST); + + BAG = new CollectionType(java.util.Collection.class, binder) { + @Override + public Collection create(ToMany property, PersistentClass owner, + String path, Mappings mappings, String sessionFactoryBeanName) throws MappingException { + Bag coll = new Bag(mappings, owner); + coll.setCollectionTable(owner.getTable()); + binder.bindCollection(property, coll, owner, mappings, path, sessionFactoryBeanName); + return coll; + } + }; + INSTANCES.put(java.util.Collection.class, BAG); + + MAP = new CollectionType(Map.class, binder) { + @Override + public Collection create(ToMany property, PersistentClass owner, + String path, Mappings mappings, String sessionFactoryBeanName) throws MappingException { + org.hibernate.mapping.Map map = new org.hibernate.mapping.Map(mappings, owner); + binder.bindCollection(property, map, owner, mappings, path, sessionFactoryBeanName); + return map; + } + }; + INSTANCES.put(Map.class, MAP); } - initialized = true; - - SET = new CollectionType(Set.class, binder) { - @Override - public Collection create(ToMany property, PersistentClass owner, - String path, Mappings mappings, String sessionFactoryBeanName) throws MappingException { - org.hibernate.mapping.Set coll = new org.hibernate.mapping.Set(mappings, owner); - coll.setCollectionTable(owner.getTable()); - binder.bindCollection(property, coll, owner, mappings, path, sessionFactoryBeanName); - return coll; - } - }; - INSTANCES.put(Set.class, SET); - INSTANCES.put(SortedSet.class, SET); - - LIST = new CollectionType(List.class, binder) { - @Override - public Collection create(ToMany property, PersistentClass owner, - String path, Mappings mappings, String sessionFactoryBeanName) throws MappingException { - org.hibernate.mapping.List coll = new org.hibernate.mapping.List(mappings, owner); - coll.setCollectionTable(owner.getTable()); - binder.bindCollection(property, coll, owner, mappings, path, sessionFactoryBeanName); - return coll; - } - }; - INSTANCES.put(List.class, LIST); - - BAG = new CollectionType(java.util.Collection.class, binder) { - @Override - public Collection create(ToMany property, PersistentClass owner, - String path, Mappings mappings, String sessionFactoryBeanName) throws MappingException { - Bag coll = new Bag(mappings, owner); - coll.setCollectionTable(owner.getTable()); - binder.bindCollection(property, coll, owner, mappings, path, sessionFactoryBeanName); - return coll; - } - }; - INSTANCES.put(java.util.Collection.class, BAG); - - MAP = new CollectionType(Map.class, binder) { - @Override - public Collection create(ToMany property, PersistentClass owner, - String path, Mappings mappings, String sessionFactoryBeanName) throws MappingException { - org.hibernate.mapping.Map map = new org.hibernate.mapping.Map(mappings, owner); - binder.bindCollection(property, map, owner, mappings, path, sessionFactoryBeanName); - return map; - } - }; - INSTANCES.put(Map.class, MAP); - } - - public CollectionType collectionTypeForClass(Class clazz) { - createInstances(); - return INSTANCES.get(clazz); + public CollectionType collectionTypeForClass(Class clazz) { + createInstances(); + return INSTANCES.get(clazz); + } } + } + diff --git a/grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java b/grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java index 80173cf0e94..3e9f2c59ae0 100644 --- a/grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java +++ b/grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java @@ -3276,104 +3276,104 @@ public void doSecondPass(Map persistentClasses) throws MappingException { (org.hibernate.mapping.Map) collection, sessionFactoryBeanName); } } + /** + * A Collection type, for the moment only Set is supported + * + * @author Graeme + */ + static abstract class CollectionType { + protected final Class clazz; + protected final GrailsDomainBinder binder; + protected final MetadataBuildingContext buildingContext; -} - -/** - * A Collection type, for the moment only Set is supported - * - * @author Graeme - */ -abstract class CollectionType { + protected static CollectionType SET; + protected static CollectionType LIST; + protected static CollectionType BAG; + protected static CollectionType MAP; + protected static boolean initialized; - protected final Class clazz; - protected final GrailsDomainBinder binder; - protected final MetadataBuildingContext buildingContext; + protected static final Map, CollectionType> INSTANCES = new HashMap, CollectionType>(); - protected static CollectionType SET; - protected static CollectionType LIST; - protected static CollectionType BAG; - protected static CollectionType MAP; - protected static boolean initialized; + public abstract Collection create(ToMany property, PersistentClass owner, + String path, InFlightMetadataCollector mappings, String sessionFactoryBeanName) throws MappingException; - protected static final Map, CollectionType> INSTANCES = new HashMap, CollectionType>(); + protected CollectionType(Class clazz, GrailsDomainBinder binder) { + this.clazz = clazz; + this.binder = binder; + this.buildingContext = binder.getMetadataBuildingContext(); + } - public abstract Collection create(ToMany property, PersistentClass owner, - String path, InFlightMetadataCollector mappings, String sessionFactoryBeanName) throws MappingException; + @Override + public String toString() { + return clazz.getName(); + } - protected CollectionType(Class clazz, GrailsDomainBinder binder) { - this.clazz = clazz; - this.binder = binder; - this.buildingContext = binder.getMetadataBuildingContext(); - } + protected void createInstances() { - @Override - public String toString() { - return clazz.getName(); - } + if (initialized) { + return; + } - protected void createInstances() { + initialized = true; - if (initialized) { - return; + SET = new CollectionType(Set.class, binder) { + @Override + public Collection create(ToMany property, PersistentClass owner, + String path, InFlightMetadataCollector mappings, String sessionFactoryBeanName) throws MappingException { + org.hibernate.mapping.Set coll = new org.hibernate.mapping.Set(mappings, owner); + coll.setCollectionTable(owner.getTable()); + binder.bindCollection(property, coll, owner, mappings, path, sessionFactoryBeanName); + return coll; + } + }; + INSTANCES.put(Set.class, SET); + INSTANCES.put(SortedSet.class, SET); + + LIST = new CollectionType(List.class, binder) { + @Override + public Collection create(ToMany property, PersistentClass owner, + String path, InFlightMetadataCollector mappings, String sessionFactoryBeanName) throws MappingException { + org.hibernate.mapping.List coll = new org.hibernate.mapping.List(mappings, owner); + coll.setCollectionTable(owner.getTable()); + binder.bindCollection(property, coll, owner, mappings, path, sessionFactoryBeanName); + return coll; + } + }; + INSTANCES.put(List.class, LIST); + + BAG = new CollectionType(java.util.Collection.class, binder) { + @Override + public Collection create(ToMany property, PersistentClass owner, + String path, InFlightMetadataCollector mappings, String sessionFactoryBeanName) throws MappingException { + Bag coll = new Bag(mappings, owner); + coll.setCollectionTable(owner.getTable()); + binder.bindCollection(property, coll, owner, mappings, path, sessionFactoryBeanName); + return coll; + } + }; + INSTANCES.put(java.util.Collection.class, BAG); + + MAP = new CollectionType(Map.class, binder) { + @Override + public Collection create(ToMany property, PersistentClass owner, + String path, InFlightMetadataCollector mappings, String sessionFactoryBeanName) throws MappingException { + org.hibernate.mapping.Map map = new org.hibernate.mapping.Map(mappings, owner); + binder.bindCollection(property, map, owner, mappings, path, sessionFactoryBeanName); + return map; + } + }; + INSTANCES.put(Map.class, MAP); } - initialized = true; - - SET = new CollectionType(Set.class, binder) { - @Override - public Collection create(ToMany property, PersistentClass owner, - String path, InFlightMetadataCollector mappings, String sessionFactoryBeanName) throws MappingException { - org.hibernate.mapping.Set coll = new org.hibernate.mapping.Set(mappings, owner); - coll.setCollectionTable(owner.getTable()); - binder.bindCollection(property, coll, owner, mappings, path, sessionFactoryBeanName); - return coll; - } - }; - INSTANCES.put(Set.class, SET); - INSTANCES.put(SortedSet.class, SET); - - LIST = new CollectionType(List.class, binder) { - @Override - public Collection create(ToMany property, PersistentClass owner, - String path, InFlightMetadataCollector mappings, String sessionFactoryBeanName) throws MappingException { - org.hibernate.mapping.List coll = new org.hibernate.mapping.List(mappings, owner); - coll.setCollectionTable(owner.getTable()); - binder.bindCollection(property, coll, owner, mappings, path, sessionFactoryBeanName); - return coll; - } - }; - INSTANCES.put(List.class, LIST); + public CollectionType collectionTypeForClass(Class clazz) { + createInstances(); + return INSTANCES.get(clazz); + } - BAG = new CollectionType(java.util.Collection.class, binder) { - @Override - public Collection create(ToMany property, PersistentClass owner, - String path, InFlightMetadataCollector mappings, String sessionFactoryBeanName) throws MappingException { - Bag coll = new Bag(mappings, owner); - coll.setCollectionTable(owner.getTable()); - binder.bindCollection(property, coll, owner, mappings, path, sessionFactoryBeanName); - return coll; - } - }; - INSTANCES.put(java.util.Collection.class, BAG); - MAP = new CollectionType(Map.class, binder) { - @Override - public Collection create(ToMany property, PersistentClass owner, - String path, InFlightMetadataCollector mappings, String sessionFactoryBeanName) throws MappingException { - org.hibernate.mapping.Map map = new org.hibernate.mapping.Map(mappings, owner); - binder.bindCollection(property, map, owner, mappings, path, sessionFactoryBeanName); - return map; - } - }; - INSTANCES.put(Map.class, MAP); } - public CollectionType collectionTypeForClass(Class clazz) { - createInstances(); - return INSTANCES.get(clazz); - } +} -}