Skip to content

Commit 938f592

Browse files
committed
HHH-18667 attempt to fix by making TypeConfiguration nonstatic
1 parent cda7dad commit 938f592

File tree

4 files changed

+33
-31
lines changed

4 files changed

+33
-31
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
@@ -18,7 +18,6 @@
1818
import org.hibernate.type.Type;
1919

2020
import static org.hibernate.internal.util.StringHelper.root;
21-
import static org.hibernate.processor.validation.MockSessionFactory.typeConfiguration;
2221

2322
/**
2423
* @author Gavin King
@@ -96,11 +95,11 @@ public Type getKeyType() {
9695
@Override
9796
public Type getIndexType() {
9897
if (collectionType instanceof ListType) {
99-
return typeConfiguration.getBasicTypeForJavaType(Integer.class);
98+
return factory.getTypeConfiguration().getBasicTypeForJavaType(Integer.class);
10099
}
101100
else if (collectionType instanceof MapType) {
102101
//TODO!!! this is incorrect, return the correct key type
103-
return typeConfiguration.getBasicTypeForJavaType(String.class);
102+
return factory.getTypeConfiguration().getBasicTypeForJavaType(String.class);
104103
}
105104
else {
106105
return null;
@@ -114,7 +113,7 @@ public Type getElementType() {
114113

115114
@Override
116115
public Type getIdentifierType() {
117-
return typeConfiguration.getBasicTypeForJavaType(Long.class);
116+
return factory.getTypeConfiguration().getBasicTypeForJavaType(Long.class);
118117
}
119118

120119
@Override

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import java.util.Objects;
2525
import java.util.Set;
2626

27-
import static org.hibernate.processor.validation.MockSessionFactory.typeConfiguration;
28-
2927
/**
3028
* @author Gavin King
3129
*/
@@ -120,7 +118,7 @@ public final Type getPropertyType(String propertyPath) {
120118
@Override
121119
public Type getIdentifierType() {
122120
//TODO: propertyType(getIdentifierPropertyName())
123-
return typeConfiguration.getBasicTypeForJavaType(Long.class);
121+
return factory.getTypeConfiguration().getBasicTypeForJavaType(Long.class);
124122
}
125123

126124
@Override
@@ -204,7 +202,7 @@ public DiscriminatorMetadata getTypeDiscriminatorMetadata() {
204202

205203
@Override
206204
public Type getResolutionType() {
207-
return typeConfiguration.getBasicTypeForJavaType(Class.class);
205+
return factory.getTypeConfiguration().getBasicTypeForJavaType(Class.class);
208206
}
209207

210208
@Override
@@ -234,6 +232,6 @@ public boolean consumesEntityAlias() {
234232

235233
@Override
236234
public Type getDiscriminatorType() {
237-
return typeConfiguration.getBasicTypeForJavaType(String.class);
235+
return factory.getTypeConfiguration().getBasicTypeForJavaType(String.class);
238236
}
239237
}

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
@@ -140,9 +140,7 @@ public abstract class MockSessionFactory
140140
private static final BasicTypeImpl<Object> OBJECT_BASIC_TYPE =
141141
new BasicTypeImpl<>(new UnknownBasicJavaType<>(Object.class), ObjectJdbcType.INSTANCE);
142142

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

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

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

Lines changed: 26 additions & 19 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(Mapping 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

@@ -376,15 +380,15 @@ boolean isSubclassPersister(MockEntityPersister entityPersister) {
376380
Type createPropertyType(String propertyPath) {
377381
Element symbol = findPropertyByPath(type, propertyPath, defaultAccessType);
378382
return symbol == null ? null :
379-
propertyType(symbol, getEntityName(), propertyPath, defaultAccessType);
383+
factory.propertyType(symbol, getEntityName(), propertyPath, defaultAccessType);
380384
}
381385

382386
}
383387

384388
public abstract static class ToManyAssociationPersister extends MockCollectionPersister {
385389
public ToManyAssociationPersister(String role, CollectionType collectionType, String targetEntityName, ProcessorSessionFactory that) {
386390
super(role, collectionType,
387-
new ManyToOneType(typeConfiguration, targetEntityName),
391+
new ManyToOneType(that.getTypeConfiguration(), targetEntityName),
388392
that);
389393
}
390394

@@ -397,26 +401,29 @@ Type getElementPropertyType(String propertyPath) {
397401
public abstract static class ElementCollectionPersister extends MockCollectionPersister {
398402
private final TypeElement elementType;
399403
private final AccessType defaultAccessType;
404+
private final ProcessorSessionFactory factory;
400405

401406
public ElementCollectionPersister(String role,
402407
CollectionType collectionType,
403408
TypeElement elementType,
404409
String propertyPath,
405410
AccessType defaultAccessType,
406-
ProcessorSessionFactory that) {
411+
ProcessorSessionFactory factory) {
407412
super(role, collectionType,
408413
elementCollectionElementType(elementType, role,
409-
propertyPath, defaultAccessType),
410-
that);
414+
propertyPath, defaultAccessType,
415+
factory),
416+
factory);
411417
this.elementType = elementType;
412418
this.defaultAccessType = defaultAccessType;
419+
this.factory = factory;
413420
}
414421

415422
@Override
416423
Type getElementPropertyType(String propertyPath) {
417424
Element symbol = findPropertyByPath(elementType, propertyPath, defaultAccessType);
418425
return symbol == null ? null :
419-
propertyType(symbol, getOwnerEntityName(), propertyPath, defaultAccessType);
426+
factory.propertyType(symbol, getOwnerEntityName(), propertyPath, defaultAccessType);
420427
}
421428
}
422429

0 commit comments

Comments
 (0)