Skip to content

Commit 1568c52

Browse files
committed
HHH-18667 attempt to fix by making TypeConfiguration nonstatic
1 parent cbdbb27 commit 1568c52

File tree

4 files changed

+34
-32
lines changed

4 files changed

+34
-32
lines changed

tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockCollectionPersister.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.hibernate.type.Type;
1616

1717
import static org.hibernate.internal.util.StringHelper.root;
18-
import static org.hibernate.processor.validation.MockSessionFactory.typeConfiguration;
1918

2019
/**
2120
* @author Gavin King
@@ -66,11 +65,11 @@ public Type getKeyType() {
6665
@Override
6766
public Type getIndexType() {
6867
if (collectionType instanceof ListType) {
69-
return typeConfiguration.getBasicTypeForJavaType(Integer.class);
68+
return factory.getTypeConfiguration().getBasicTypeForJavaType(Integer.class);
7069
}
7170
else if (collectionType instanceof MapType) {
7271
//TODO!!! this is incorrect, return the correct key type
73-
return typeConfiguration.getBasicTypeForJavaType(String.class);
72+
return factory.getTypeConfiguration().getBasicTypeForJavaType(String.class);
7473
}
7574
else {
7675
return null;
@@ -84,7 +83,7 @@ public Type getElementType() {
8483

8584
@Override
8685
public Type getIdentifierType() {
87-
return typeConfiguration.getBasicTypeForJavaType(Long.class);
86+
return factory.getTypeConfiguration().getBasicTypeForJavaType(Long.class);
8887
}
8988

9089
@Override

tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockEntityPersister.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import java.util.Objects;
2323
import java.util.Set;
2424

25-
import static org.hibernate.processor.validation.MockSessionFactory.typeConfiguration;
26-
2725
/**
2826
* @author Gavin King
2927
*/
@@ -193,7 +191,7 @@ public DiscriminatorMetadata getTypeDiscriminatorMetadata() {
193191

194192
@Override
195193
public Type getResolutionType() {
196-
return typeConfiguration.getBasicTypeForJavaType(Class.class);
194+
return factory.getTypeConfiguration().getBasicTypeForJavaType(Class.class);
197195
}
198196

199197
@Override
@@ -223,6 +221,6 @@ public String getMappedSuperclass() {
223221

224222
@Override
225223
public Type getDiscriminatorType() {
226-
return typeConfiguration.getBasicTypeForJavaType(String.class);
224+
return factory.getTypeConfiguration().getBasicTypeForJavaType(String.class);
227225
}
228226
}

tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockSessionFactory.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@ public abstract class MockSessionFactory
145145
private static final BasicTypeImpl<Object> OBJECT_BASIC_TYPE =
146146
new BasicTypeImpl<>(new UnknownBasicJavaType<>(Object.class), ObjectJdbcType.INSTANCE);
147147

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

152150
private final Map<String,MockEntityPersister> entityPersistersByName = new HashMap<>();
153151
private final Map<String,MockCollectionPersister> collectionPersistersByName = new HashMap<>();

tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/ProcessorSessionFactory.java

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,13 @@ private static Element dereference(AccessType defaultAccessType, Element symbol,
178178
}
179179
}
180180

181-
static Type propertyType(Element member, String entityName, String path, AccessType defaultAccessType) {
181+
private Type propertyType(Element member, String entityName, String path, AccessType defaultAccessType) {
182182
final TypeMirror memberType = memberType(member);
183183
if (isEmbeddedProperty(member)) {
184-
return component.make(asElement(memberType), entityName, path, defaultAccessType);
184+
return component.make(asElement(memberType), entityName, path, defaultAccessType, this);
185185
}
186186
else if (isToOneAssociation(member)) {
187-
return new ManyToOneType(typeConfiguration, getToOneTargetEntity(member));
187+
return new ManyToOneType(getTypeConfiguration(), getToOneTargetEntity(member));
188188
}
189189
else if (isToManyAssociation(member)) {
190190
return collectionType(memberType, qualify(entityName, path));
@@ -193,10 +193,10 @@ else if (isElementCollectionProperty(member)) {
193193
return collectionType(memberType, qualify(entityName, path));
194194
}
195195
else if (isEnumProperty(member)) {
196-
return enumType( member, memberType );
196+
return enumType(member, memberType);
197197
}
198198
else {
199-
return typeConfiguration.getBasicTypeRegistry()
199+
return getTypeConfiguration().getBasicTypeRegistry()
200200
.getRegisteredType(qualifiedName(memberType));
201201
}
202202
}
@@ -255,12 +255,13 @@ Set<String> getEnumTypesForValue(String value) {
255255

256256
private static Type elementCollectionElementType(TypeElement elementType,
257257
String role, String path,
258-
AccessType defaultAccessType) {
258+
AccessType defaultAccessType,
259+
MockSessionFactory factory) {
259260
if (isEmbeddableType(elementType)) {
260-
return component.make(elementType, role, path, defaultAccessType);
261+
return component.make(elementType, role, path, defaultAccessType, factory);
261262
}
262263
else {
263-
return typeConfiguration.getBasicTypeRegistry()
264+
return factory.getTypeConfiguration().getBasicTypeRegistry()
264265
.getRegisteredType(qualifiedName(elementType.asType()));
265266
}
266267
}
@@ -277,7 +278,8 @@ public static abstract class Component implements CompositeType {
277278

278279
public Component(TypeElement type,
279280
String entityName, String path,
280-
AccessType defaultAccessType) {
281+
AccessType defaultAccessType,
282+
ProcessorSessionFactory factory) {
281283
this.type = type;
282284

283285
List<String> names = new ArrayList<>();
@@ -290,7 +292,7 @@ public Component(TypeElement type,
290292
if (isPersistable(member, accessType)) {
291293
String name = propertyName(member);
292294
Type propertyType =
293-
propertyType(member, entityName,
295+
factory.propertyType(member, entityName,
294296
qualify(path, name), defaultAccessType);
295297
if (propertyType != null) {
296298
names.add(name);
@@ -358,11 +360,13 @@ public int getColumnSpan(MappingContext mapping) {
358360
public static abstract class EntityPersister extends MockEntityPersister {
359361
private final TypeElement type;
360362
private final Types typeUtil;
363+
private final ProcessorSessionFactory factory;
361364

362-
public EntityPersister(String entityName, TypeElement type, ProcessorSessionFactory that) {
363-
super(entityName, getDefaultAccessType(type), that);
365+
public EntityPersister(String entityName, TypeElement type, ProcessorSessionFactory factory) {
366+
super(entityName, getDefaultAccessType(type), factory);
364367
this.type = type;
365-
this.typeUtil = that.typeUtil;
368+
this.typeUtil = factory.typeUtil;
369+
this.factory = factory;
366370
initSubclassPersisters();
367371
}
368372

@@ -397,7 +401,7 @@ boolean isSubclassPersister(MockEntityPersister entityPersister) {
397401
Type createPropertyType(String propertyPath) {
398402
Element symbol = findPropertyByPath(type, propertyPath, defaultAccessType);
399403
return symbol == null ? null :
400-
propertyType(symbol, getEntityName(), propertyPath, defaultAccessType);
404+
factory.propertyType(symbol, getEntityName(), propertyPath, defaultAccessType);
401405
}
402406

403407
@Override
@@ -414,7 +418,7 @@ public String identifierPropertyName() {
414418
public Type identifierType() {
415419
for (Element element : type.getEnclosedElements()) {
416420
if ( hasAnnotation(element, "Id")|| hasAnnotation(element, "EmbeddedId") ) {
417-
return propertyType(element, getEntityName(), EntityIdentifierMapping.ID_ROLE_NAME, defaultAccessType);
421+
return factory.propertyType(element, getEntityName(), EntityIdentifierMapping.ID_ROLE_NAME, defaultAccessType);
418422
}
419423
}
420424
return null;
@@ -424,7 +428,7 @@ public Type identifierType() {
424428
public BasicType<?> versionType() {
425429
for (Element element : type.getEnclosedElements()) {
426430
if ( hasAnnotation(element, "Version") ) {
427-
return (BasicType<?>) propertyType(element, getEntityName(), "{version}", defaultAccessType);
431+
return (BasicType<?>) factory.propertyType(element, getEntityName(), "{version}", defaultAccessType);
428432
}
429433
}
430434
return null;
@@ -434,7 +438,7 @@ public BasicType<?> versionType() {
434438
public abstract static class ToManyAssociationPersister extends MockCollectionPersister {
435439
public ToManyAssociationPersister(String role, CollectionType collectionType, String targetEntityName, ProcessorSessionFactory that) {
436440
super(role, collectionType,
437-
new ManyToOneType(typeConfiguration, targetEntityName),
441+
new ManyToOneType(that.getTypeConfiguration(), targetEntityName),
438442
that);
439443
}
440444

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

451456
public ElementCollectionPersister(String role,
452457
CollectionType collectionType,
453458
TypeElement elementType,
454459
String propertyPath,
455460
AccessType defaultAccessType,
456-
ProcessorSessionFactory that) {
461+
ProcessorSessionFactory factory) {
457462
super(role, collectionType,
458463
elementCollectionElementType(elementType, role,
459-
propertyPath, defaultAccessType),
460-
that);
464+
propertyPath, defaultAccessType,
465+
factory),
466+
factory);
461467
this.elementType = elementType;
462468
this.defaultAccessType = defaultAccessType;
469+
this.factory = factory;
463470
}
464471

465472
@Override
466473
Type getElementPropertyType(String propertyPath) {
467474
Element symbol = findPropertyByPath(elementType, propertyPath, defaultAccessType);
468475
return symbol == null ? null :
469-
propertyType(symbol, getOwnerEntityName(), propertyPath, defaultAccessType);
476+
factory.propertyType(symbol, getOwnerEntityName(), propertyPath, defaultAccessType);
470477
}
471478
}
472479

0 commit comments

Comments
 (0)