Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.hibernate.type.Type;

import static org.hibernate.internal.util.StringHelper.root;
import static org.hibernate.processor.validation.MockSessionFactory.typeConfiguration;

/**
* @author Gavin King
Expand Down Expand Up @@ -66,11 +65,11 @@ public Type getKeyType() {
@Override
public Type getIndexType() {
if (collectionType instanceof ListType) {
return typeConfiguration.getBasicTypeForJavaType(Integer.class);
return factory.getTypeConfiguration().getBasicTypeForJavaType(Integer.class);
}
else if (collectionType instanceof MapType) {
//TODO!!! this is incorrect, return the correct key type
return typeConfiguration.getBasicTypeForJavaType(String.class);
return factory.getTypeConfiguration().getBasicTypeForJavaType(String.class);
}
else {
return null;
Expand All @@ -84,7 +83,7 @@ public Type getElementType() {

@Override
public Type getIdentifierType() {
return typeConfiguration.getBasicTypeForJavaType(Long.class);
return factory.getTypeConfiguration().getBasicTypeForJavaType(Long.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import java.util.Objects;
import java.util.Set;

import static org.hibernate.processor.validation.MockSessionFactory.typeConfiguration;

/**
* @author Gavin King
*/
Expand Down Expand Up @@ -193,7 +191,7 @@ public DiscriminatorMetadata getTypeDiscriminatorMetadata() {

@Override
public Type getResolutionType() {
return typeConfiguration.getBasicTypeForJavaType(Class.class);
return factory.getTypeConfiguration().getBasicTypeForJavaType(Class.class);
}

@Override
Expand Down Expand Up @@ -223,6 +221,6 @@ public String getMappedSuperclass() {

@Override
public Type getDiscriminatorType() {
return typeConfiguration.getBasicTypeForJavaType(String.class);
return factory.getTypeConfiguration().getBasicTypeForJavaType(String.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ public abstract class MockSessionFactory
private static final BasicTypeImpl<Object> OBJECT_BASIC_TYPE =
new BasicTypeImpl<>(new UnknownBasicJavaType<>(Object.class), ObjectJdbcType.INSTANCE);

// static so other things can get at it
// TODO: make a static instance of this whole object instead!
static TypeConfiguration typeConfiguration;
private final TypeConfiguration typeConfiguration;

private final Map<String,MockEntityPersister> entityPersistersByName = new HashMap<>();
private final Map<String,MockCollectionPersister> collectionPersistersByName = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ private static Element dereference(AccessType defaultAccessType, Element symbol,
}
}

static Type propertyType(Element member, String entityName, String path, AccessType defaultAccessType) {
private Type propertyType(Element member, String entityName, String path, AccessType defaultAccessType) {
final TypeMirror memberType = memberType(member);
if (isEmbeddedProperty(member)) {
return component.make(asElement(memberType), entityName, path, defaultAccessType);
return component.make(asElement(memberType), entityName, path, defaultAccessType, this);
}
else if (isToOneAssociation(member)) {
return new ManyToOneType(typeConfiguration, getToOneTargetEntity(member));
return new ManyToOneType(getTypeConfiguration(), getToOneTargetEntity(member));
}
else if (isToManyAssociation(member)) {
return collectionType(memberType, qualify(entityName, path));
Expand All @@ -193,10 +193,10 @@ else if (isElementCollectionProperty(member)) {
return collectionType(memberType, qualify(entityName, path));
}
else if (isEnumProperty(member)) {
return enumType( member, memberType );
return enumType(member, memberType);
}
else {
return typeConfiguration.getBasicTypeRegistry()
return getTypeConfiguration().getBasicTypeRegistry()
.getRegisteredType(qualifiedName(memberType));
}
}
Expand Down Expand Up @@ -255,12 +255,13 @@ Set<String> getEnumTypesForValue(String value) {

private static Type elementCollectionElementType(TypeElement elementType,
String role, String path,
AccessType defaultAccessType) {
AccessType defaultAccessType,
MockSessionFactory factory) {
if (isEmbeddableType(elementType)) {
return component.make(elementType, role, path, defaultAccessType);
return component.make(elementType, role, path, defaultAccessType, factory);
}
else {
return typeConfiguration.getBasicTypeRegistry()
return factory.getTypeConfiguration().getBasicTypeRegistry()
.getRegisteredType(qualifiedName(elementType.asType()));
}
}
Expand All @@ -277,7 +278,8 @@ public static abstract class Component implements CompositeType {

public Component(TypeElement type,
String entityName, String path,
AccessType defaultAccessType) {
AccessType defaultAccessType,
ProcessorSessionFactory factory) {
this.type = type;

List<String> names = new ArrayList<>();
Expand All @@ -290,7 +292,7 @@ public Component(TypeElement type,
if (isPersistable(member, accessType)) {
String name = propertyName(member);
Type propertyType =
propertyType(member, entityName,
factory.propertyType(member, entityName,
qualify(path, name), defaultAccessType);
if (propertyType != null) {
names.add(name);
Expand Down Expand Up @@ -358,11 +360,13 @@ public int getColumnSpan(MappingContext mapping) {
public static abstract class EntityPersister extends MockEntityPersister {
private final TypeElement type;
private final Types typeUtil;
private final ProcessorSessionFactory factory;

public EntityPersister(String entityName, TypeElement type, ProcessorSessionFactory that) {
super(entityName, getDefaultAccessType(type), that);
public EntityPersister(String entityName, TypeElement type, ProcessorSessionFactory factory) {
super(entityName, getDefaultAccessType(type), factory);
this.type = type;
this.typeUtil = that.typeUtil;
this.typeUtil = factory.typeUtil;
this.factory = factory;
initSubclassPersisters();
}

Expand Down Expand Up @@ -397,7 +401,7 @@ boolean isSubclassPersister(MockEntityPersister entityPersister) {
Type createPropertyType(String propertyPath) {
Element symbol = findPropertyByPath(type, propertyPath, defaultAccessType);
return symbol == null ? null :
propertyType(symbol, getEntityName(), propertyPath, defaultAccessType);
factory.propertyType(symbol, getEntityName(), propertyPath, defaultAccessType);
}

@Override
Expand All @@ -414,7 +418,7 @@ public String identifierPropertyName() {
public Type identifierType() {
for (Element element : type.getEnclosedElements()) {
if ( hasAnnotation(element, "Id")|| hasAnnotation(element, "EmbeddedId") ) {
return propertyType(element, getEntityName(), EntityIdentifierMapping.ID_ROLE_NAME, defaultAccessType);
return factory.propertyType(element, getEntityName(), EntityIdentifierMapping.ID_ROLE_NAME, defaultAccessType);
}
}
return null;
Expand All @@ -424,7 +428,7 @@ public Type identifierType() {
public BasicType<?> versionType() {
for (Element element : type.getEnclosedElements()) {
if ( hasAnnotation(element, "Version") ) {
return (BasicType<?>) propertyType(element, getEntityName(), "{version}", defaultAccessType);
return (BasicType<?>) factory.propertyType(element, getEntityName(), "{version}", defaultAccessType);
}
}
return null;
Expand All @@ -434,7 +438,7 @@ public BasicType<?> versionType() {
public abstract static class ToManyAssociationPersister extends MockCollectionPersister {
public ToManyAssociationPersister(String role, CollectionType collectionType, String targetEntityName, ProcessorSessionFactory that) {
super(role, collectionType,
new ManyToOneType(typeConfiguration, targetEntityName),
new ManyToOneType(that.getTypeConfiguration(), targetEntityName),
that);
}

Expand All @@ -447,26 +451,29 @@ Type getElementPropertyType(String propertyPath) {
public abstract static class ElementCollectionPersister extends MockCollectionPersister {
private final TypeElement elementType;
private final AccessType defaultAccessType;
private final ProcessorSessionFactory factory;

public ElementCollectionPersister(String role,
CollectionType collectionType,
TypeElement elementType,
String propertyPath,
AccessType defaultAccessType,
ProcessorSessionFactory that) {
ProcessorSessionFactory factory) {
super(role, collectionType,
elementCollectionElementType(elementType, role,
propertyPath, defaultAccessType),
that);
propertyPath, defaultAccessType,
factory),
factory);
this.elementType = elementType;
this.defaultAccessType = defaultAccessType;
this.factory = factory;
}

@Override
Type getElementPropertyType(String propertyPath) {
Element symbol = findPropertyByPath(elementType, propertyPath, defaultAccessType);
return symbol == null ? null :
propertyType(symbol, getOwnerEntityName(), propertyPath, defaultAccessType);
factory.propertyType(symbol, getOwnerEntityName(), propertyPath, defaultAccessType);
}
}

Expand Down
Loading