Skip to content

Commit

Permalink
Hibernate - fix conflicting classes in Hibernate 5.1 #9915
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed May 20, 2016
1 parent 824dbfa commit 0fc3a49
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 165 deletions.
Expand Up @@ -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<Class<?>, CollectionType> INSTANCES = new HashMap<Class<?>, CollectionType>();
protected static final Map<Class<?>, CollectionType> INSTANCES = new HashMap<Class<?>, 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);
}
}

}

Expand Up @@ -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<Class<?>, CollectionType> INSTANCES = new HashMap<Class<?>, 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<Class<?>, CollectionType> INSTANCES = new HashMap<Class<?>, 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);
}
}


}

0 comments on commit 0fc3a49

Please sign in to comment.