Skip to content

Commit 12b3322

Browse files
authoredJul 19, 2022
Replace ClassTypeInformation usages with TypeInformation.
Original Pull Request #2235 Closes #2234
·
6.0.0-M35.0.0-M6
1 parent 47c0e18 commit 12b3322

File tree

6 files changed

+52
-47
lines changed

6 files changed

+52
-47
lines changed
 

‎src/main/java/org/springframework/data/elasticsearch/core/convert/DefaultElasticsearchTypeMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.springframework.data.mapping.Alias;
2727
import org.springframework.data.mapping.PersistentEntity;
2828
import org.springframework.data.mapping.context.MappingContext;
29-
import org.springframework.data.util.ClassTypeInformation;
3029
import org.springframework.data.util.TypeInformation;
3130
import org.springframework.lang.Nullable;
3231

@@ -41,7 +40,7 @@ public class DefaultElasticsearchTypeMapper extends DefaultTypeMapper<Map<String
4140
implements ElasticsearchTypeMapper {
4241

4342
@SuppressWarnings("rawtypes") //
44-
private static final TypeInformation<Map> MAP_TYPE_INFO = ClassTypeInformation.from(Map.class);
43+
private static final TypeInformation<Map> MAP_TYPE_INFO = TypeInformation.of(Map.class);
4544

4645
private final @Nullable String typeKey;
4746

‎src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,16 @@
5353
import org.springframework.data.mapping.PersistentPropertyAccessor;
5454
import org.springframework.data.mapping.SimplePropertyHandler;
5555
import org.springframework.data.mapping.context.MappingContext;
56-
import org.springframework.data.mapping.model.*;
57-
import org.springframework.data.util.ClassTypeInformation;
56+
import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
57+
import org.springframework.data.mapping.model.DefaultSpELExpressionEvaluator;
58+
import org.springframework.data.mapping.model.EntityInstantiator;
59+
import org.springframework.data.mapping.model.EntityInstantiators;
60+
import org.springframework.data.mapping.model.ParameterValueProvider;
61+
import org.springframework.data.mapping.model.PersistentEntityParameterValueProvider;
62+
import org.springframework.data.mapping.model.PropertyValueProvider;
63+
import org.springframework.data.mapping.model.SpELContext;
64+
import org.springframework.data.mapping.model.SpELExpressionEvaluator;
65+
import org.springframework.data.mapping.model.SpELExpressionParameterValueProvider;
5866
import org.springframework.data.util.TypeInformation;
5967
import org.springframework.format.datetime.DateFormatterRegistrar;
6068
import org.springframework.lang.Nullable;
@@ -213,7 +221,7 @@ public Reader(
213221
@SuppressWarnings("unchecked")
214222
<R> R read(Class<R> type, Document source) {
215223

216-
TypeInformation<R> typeHint = ClassTypeInformation.from((Class<R>) ClassUtils.getUserClass(type));
224+
TypeInformation<R> typeHint = TypeInformation.of((Class<R>) ClassUtils.getUserClass(type));
217225
R r = read(typeHint, source);
218226

219227
if (r == null) {
@@ -244,7 +252,7 @@ private <R> R read(TypeInformation<R> type, Map<String, Object> source) {
244252
return readMap(typeToUse, source);
245253
}
246254

247-
if (typeToUse.equals(ClassTypeInformation.OBJECT)) {
255+
if (typeToUse.equals(TypeInformation.OBJECT)) {
248256
return (R) source;
249257
}
250258
// Retrieve persistent entity info
@@ -286,13 +294,13 @@ private <R> R readMap(TypeInformation<?> type, Map<String, Object> source) {
286294
}
287295

288296
Object value = entry.getValue();
289-
TypeInformation<?> defaultedValueType = valueType != null ? valueType : ClassTypeInformation.OBJECT;
297+
TypeInformation<?> defaultedValueType = valueType != null ? valueType : TypeInformation.OBJECT;
290298

291299
if (value instanceof Map) {
292300
map.put(key, read(defaultedValueType, (Map<String, Object>) value));
293301
} else if (value instanceof List) {
294302
map.put(key,
295-
readCollectionOrArray(valueType != null ? valueType : ClassTypeInformation.LIST, (List<Object>) value));
303+
readCollectionOrArray(valueType != null ? valueType : TypeInformation.LIST, (List<Object>) value));
296304
} else {
297305
map.put(key, getPotentiallyConvertedSimpleRead(value, rawValueType));
298306
}
@@ -397,7 +405,7 @@ protected <R> R readProperties(ElasticsearchPersistentEntity<?> entity, R instan
397405

398406
for (ElasticsearchPersistentProperty prop : entity) {
399407

400-
if (entity.isConstructorArgument(prop) || !prop.isReadable()) {
408+
if (entity.isCreatorArgument(prop) || !prop.isReadable()) {
401409
continue;
402410
}
403411

@@ -504,7 +512,7 @@ private Object readCollectionOrArray(TypeInformation<?> targetType, Collection<?
504512

505513
TypeInformation<?> componentType = targetType.getComponentType() != null //
506514
? targetType.getComponentType() //
507-
: ClassTypeInformation.OBJECT;
515+
: TypeInformation.OBJECT;
508516
Class<?> rawComponentType = componentType.getType();
509517

510518
Collection<Object> items = targetType.getType().isArray() //
@@ -649,7 +657,8 @@ public ConverterAwareSpELExpressionParameterValueProvider(SpELExpressionEvaluato
649657
* @see org.springframework.data.mapping.model.SpELExpressionParameterValueProvider#potentiallyConvertSpelValue(java.lang.Object, org.springframework.data.mapping.PreferredConstructor.Parameter)
650658
*/
651659
@Override
652-
protected <T> T potentiallyConvertSpelValue(Object object, Parameter<T, ElasticsearchPersistentProperty> parameter) {
660+
protected <T> T potentiallyConvertSpelValue(Object object,
661+
Parameter<T, ElasticsearchPersistentProperty> parameter) {
653662
return readValue(object, parameter.getType());
654663
}
655664
}
@@ -694,7 +703,7 @@ void write(Object source, Document sink) {
694703
writeTypeHints = entity.writeTypeHints();
695704
}
696705

697-
TypeInformation<?> typeInformation = ClassTypeInformation.from(entityType);
706+
TypeInformation<?> typeInformation = TypeInformation.of(entityType);
698707

699708
if (writeTypeHints && requiresTypeHint(entityType)) {
700709
typeMapper.writeType(typeInformation, sink);
@@ -707,7 +716,7 @@ void write(Object source, Document sink) {
707716
* Internal write conversion method which should be used for nested invocations.
708717
*
709718
* @param source the object to write
710-
* @param sink the write destination
719+
* @param sink the destination
711720
* @param typeInformation type information for the source
712721
*/
713722
@SuppressWarnings("unchecked")
@@ -731,12 +740,12 @@ private void writeInternal(@Nullable Object source, Map<String, Object> sink,
731740
}
732741

733742
if (Map.class.isAssignableFrom(entityType)) {
734-
writeMapInternal((Map<Object, Object>) source, sink, ClassTypeInformation.MAP);
743+
writeMapInternal((Map<Object, Object>) source, sink, TypeInformation.MAP);
735744
return;
736745
}
737746

738747
if (Collection.class.isAssignableFrom(entityType)) {
739-
writeCollectionInternal((Collection<?>) source, ClassTypeInformation.LIST, (Collection<?>) sink);
748+
writeCollectionInternal((Collection<?>) source, TypeInformation.LIST, (Collection<?>) sink);
740749
return;
741750
}
742751

@@ -749,7 +758,7 @@ private void writeInternal(@Nullable Object source, Map<String, Object> sink,
749758
* Internal write conversion method which should be used for nested invocations.
750759
*
751760
* @param source the object to write
752-
* @param sink the write destination
761+
* @param sink the destination
753762
* @param entity entity for the source
754763
*/
755764
private void writeInternal(@Nullable Object source, Map<String, Object> sink,
@@ -813,7 +822,7 @@ private Map<String, Object> writeMapInternal(Map<?, ?> source, Map<String, Objec
813822
} else {
814823
Map<String, Object> document = Document.create();
815824
TypeInformation<?> valueTypeInfo = propertyType.isMap() ? propertyType.getMapValueType()
816-
: ClassTypeInformation.OBJECT;
825+
: TypeInformation.OBJECT;
817826
writeInternal(value, document, valueTypeInfo);
818827

819828
sink.put(simpleKey, document);
@@ -923,7 +932,7 @@ protected void writeProperty(ElasticsearchPersistentProperty property, Object va
923932
return;
924933
}
925934

926-
TypeInformation<?> valueType = ClassTypeInformation.from(value.getClass());
935+
TypeInformation<?> valueType = TypeInformation.of(value.getClass());
927936
TypeInformation<?> type = property.getTypeInformation();
928937

929938
if (valueType.isCollectionLike()) {
@@ -955,7 +964,7 @@ protected void writeProperty(ElasticsearchPersistentProperty property, Object va
955964
Map<String, Object> document = existingValue instanceof Map ? (Map<String, Object>) existingValue
956965
: Document.create();
957966

958-
addCustomTypeKeyIfNecessary(value, document, ClassTypeInformation.from(property.getRawType()));
967+
addCustomTypeKeyIfNecessary(value, document, TypeInformation.of(property.getRawType()));
959968
writeInternal(value, document, entity);
960969
sink.set(property, document);
961970
}

‎src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchQueryMethod.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.springframework.data.projection.ProjectionFactory;
3535
import org.springframework.data.repository.core.RepositoryMetadata;
3636
import org.springframework.data.repository.query.QueryMethod;
37-
import org.springframework.data.util.ClassTypeInformation;
3837
import org.springframework.data.util.Lazy;
3938
import org.springframework.data.util.TypeInformation;
4039
import org.springframework.lang.Nullable;
@@ -78,7 +77,7 @@ public ElasticsearchQueryMethod(Method method, RepositoryMetadata repositoryMeta
7877
protected void verifyCountQueryTypes() {
7978

8079
if (hasCountQueryAnnotation()) {
81-
TypeInformation<?> returnType = ClassTypeInformation.fromReturnTypeOf(method);
80+
TypeInformation<?> returnType = TypeInformation.fromReturnTypeOf(method);
8281

8382
if (returnType.getType() != long.class && !Long.class.isAssignableFrom(returnType.getType())) {
8483
throw new InvalidDataAccessApiUsageException("count query methods must return a Long");

‎src/main/java/org/springframework/data/elasticsearch/repository/query/ReactiveElasticsearchQueryMethod.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.springframework.data.repository.core.RepositoryMetadata;
3838
import org.springframework.data.repository.util.ReactiveWrapperConverters;
3939
import org.springframework.data.repository.util.ReactiveWrappers;
40-
import org.springframework.data.util.ClassTypeInformation;
4140
import org.springframework.data.util.Lazy;
4241
import org.springframework.data.util.TypeInformation;
4342
import org.springframework.util.ClassUtils;
@@ -49,8 +48,8 @@
4948
*/
5049
public class ReactiveElasticsearchQueryMethod extends ElasticsearchQueryMethod {
5150

52-
private static final ClassTypeInformation<Page> PAGE_TYPE = ClassTypeInformation.from(Page.class);
53-
private static final ClassTypeInformation<Slice> SLICE_TYPE = ClassTypeInformation.from(Slice.class);
51+
private static final TypeInformation<Page> PAGE_TYPE = TypeInformation.of(Page.class);
52+
private static final TypeInformation<Slice> SLICE_TYPE = TypeInformation.of(Slice.class);
5453
private final Lazy<Boolean> isCollectionQuery;
5554

5655
public ReactiveElasticsearchQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory,
@@ -60,7 +59,7 @@ public ReactiveElasticsearchQueryMethod(Method method, RepositoryMetadata metada
6059

6160
if (hasParameterOfType(method, Pageable.class)) {
6261

63-
TypeInformation<?> returnType = ClassTypeInformation.fromReturnTypeOf(method);
62+
TypeInformation<?> returnType = TypeInformation.fromReturnTypeOf(method);
6463
boolean multiWrapper = ReactiveWrappers.isMultiValueType(returnType.getType());
6564
boolean singleWrapperWithWrappedPageableResult = ReactiveWrappers.isSingleValueType(returnType.getType())
6665
&& (PAGE_TYPE.isAssignableFrom(returnType.getRequiredComponentType())
@@ -75,12 +74,12 @@ public ReactiveElasticsearchQueryMethod(Method method, RepositoryMetadata metada
7574
if (!multiWrapper) {
7675
throw new IllegalStateException(String.format(
7776
"Method has to use a either multi-item reactive wrapper return type or a wrapped Page/Slice type. Offending method: %s",
78-
method.toString()));
77+
method));
7978
}
8079

8180
if (hasParameterOfType(method, Sort.class)) {
8281
throw new IllegalStateException(String.format("Method must not have Pageable *and* Sort parameter. "
83-
+ "Use sorting capabilities on Pageble instead! Offending method: %s", method.toString()));
82+
+ "Use sorting capabilities on Pageble instead! Offending method: %s", method));
8483
}
8584
}
8685

@@ -91,7 +90,7 @@ public ReactiveElasticsearchQueryMethod(Method method, RepositoryMetadata metada
9190
@Override
9291
protected void verifyCountQueryTypes() {
9392
if (hasCountQueryAnnotation()) {
94-
TypeInformation<?> returnType = ClassTypeInformation.fromReturnTypeOf(method);
93+
TypeInformation<?> returnType = TypeInformation.fromReturnTypeOf(method);
9594
List<TypeInformation<?>> typeArguments = returnType.getTypeArguments();
9695

9796
if (!Mono.class.isAssignableFrom(returnType.getType()) || typeArguments.size() != 1

‎src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntityTests.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.springframework.data.mapping.model.Property;
3838
import org.springframework.data.mapping.model.PropertyNameFieldNamingStrategy;
3939
import org.springframework.data.mapping.model.SimpleTypeHolder;
40-
import org.springframework.data.util.ClassTypeInformation;
4140
import org.springframework.data.util.TypeInformation;
4241
import org.springframework.lang.Nullable;
4342
import org.springframework.util.ReflectionUtils;
@@ -62,8 +61,8 @@ class PropertiesTests {
6261
@Test
6362
public void shouldThrowExceptionGivenVersionPropertyIsNotLong() {
6463

65-
TypeInformation<EntityWithWrongVersionType> typeInformation = ClassTypeInformation
66-
.from(EntityWithWrongVersionType.class);
64+
TypeInformation<EntityWithWrongVersionType> typeInformation = TypeInformation
65+
.of(EntityWithWrongVersionType.class);
6766
SimpleElasticsearchPersistentEntity<EntityWithWrongVersionType> entity = new SimpleElasticsearchPersistentEntity<>(
6867
typeInformation, contextConfiguration);
6968

@@ -73,8 +72,8 @@ public void shouldThrowExceptionGivenVersionPropertyIsNotLong() {
7372
@Test
7473
public void shouldThrowExceptionGivenMultipleVersionPropertiesArePresent() {
7574

76-
TypeInformation<EntityWithMultipleVersionField> typeInformation = ClassTypeInformation
77-
.from(EntityWithMultipleVersionField.class);
75+
TypeInformation<EntityWithMultipleVersionField> typeInformation = TypeInformation
76+
.of(EntityWithMultipleVersionField.class);
7877
SimpleElasticsearchPersistentEntity<EntityWithMultipleVersionField> entity = new SimpleElasticsearchPersistentEntity<>(
7978
typeInformation, contextConfiguration);
8079
SimpleElasticsearchPersistentProperty persistentProperty1 = createProperty(entity, "version1");
@@ -102,8 +101,8 @@ void shouldFindPropertiesByMappedName() {
102101
@Test
103102
// DATAES-799
104103
void shouldReportThatThereIsNoSeqNoPrimaryTermPropertyWhenThereIsNoSuchProperty() {
105-
TypeInformation<EntityWithoutSeqNoPrimaryTerm> typeInformation = ClassTypeInformation
106-
.from(EntityWithoutSeqNoPrimaryTerm.class);
104+
TypeInformation<EntityWithoutSeqNoPrimaryTerm> typeInformation = TypeInformation
105+
.of(EntityWithoutSeqNoPrimaryTerm.class);
107106
SimpleElasticsearchPersistentEntity<EntityWithoutSeqNoPrimaryTerm> entity = new SimpleElasticsearchPersistentEntity<>(
108107
typeInformation, contextConfiguration);
109108

@@ -113,8 +112,8 @@ void shouldReportThatThereIsNoSeqNoPrimaryTermPropertyWhenThereIsNoSuchProperty(
113112
@Test
114113
// DATAES-799
115114
void shouldReportThatThereIsSeqNoPrimaryTermPropertyWhenThereIsSuchProperty() {
116-
TypeInformation<EntityWithSeqNoPrimaryTerm> typeInformation = ClassTypeInformation
117-
.from(EntityWithSeqNoPrimaryTerm.class);
115+
TypeInformation<EntityWithSeqNoPrimaryTerm> typeInformation = TypeInformation
116+
.of(EntityWithSeqNoPrimaryTerm.class);
118117
SimpleElasticsearchPersistentEntity<EntityWithSeqNoPrimaryTerm> entity = new SimpleElasticsearchPersistentEntity<>(
119118
typeInformation, contextConfiguration);
120119

@@ -127,8 +126,8 @@ void shouldReportThatThereIsSeqNoPrimaryTermPropertyWhenThereIsSuchProperty() {
127126
// DATAES-799
128127
void shouldReturnSeqNoPrimaryTermPropertyWhenThereIsSuchProperty() {
129128

130-
TypeInformation<EntityWithSeqNoPrimaryTerm> typeInformation = ClassTypeInformation
131-
.from(EntityWithSeqNoPrimaryTerm.class);
129+
TypeInformation<EntityWithSeqNoPrimaryTerm> typeInformation = TypeInformation
130+
.of(EntityWithSeqNoPrimaryTerm.class);
132131
SimpleElasticsearchPersistentEntity<EntityWithSeqNoPrimaryTerm> entity = new SimpleElasticsearchPersistentEntity<>(
133132
typeInformation, contextConfiguration);
134133
entity.addPersistentProperty(createProperty(entity, "seqNoPrimaryTerm"));
@@ -146,8 +145,8 @@ void shouldReturnSeqNoPrimaryTermPropertyWhenThereIsSuchProperty() {
146145
@Test
147146
// DATAES-799
148147
void shouldNotAllowMoreThanOneSeqNoPrimaryTermProperties() {
149-
TypeInformation<EntityWithSeqNoPrimaryTerm> typeInformation = ClassTypeInformation
150-
.from(EntityWithSeqNoPrimaryTerm.class);
148+
TypeInformation<EntityWithSeqNoPrimaryTerm> typeInformation = TypeInformation
149+
.of(EntityWithSeqNoPrimaryTerm.class);
151150
SimpleElasticsearchPersistentEntity<EntityWithSeqNoPrimaryTerm> entity = new SimpleElasticsearchPersistentEntity<>(
152151
typeInformation, contextConfiguration);
153152
entity.addPersistentProperty(createProperty(entity, "seqNoPrimaryTerm"));
@@ -199,7 +198,7 @@ void shouldWriteSortParametersToSettingsObject() throws JSONException {
199198
]
200199
}
201200
}
202-
} """;
201+
}""";
203202

204203
ElasticsearchPersistentEntity<?> entity = elasticsearchConverter.get().getMappingContext()
205204
.getRequiredPersistentEntity(SettingsValidSortParameterSizes.class);

‎src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentPropertyUnitTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import org.springframework.data.mapping.model.PropertyNameFieldNamingStrategy;
4242
import org.springframework.data.mapping.model.SimpleTypeHolder;
4343
import org.springframework.data.mapping.model.SnakeCaseFieldNamingStrategy;
44-
import org.springframework.data.util.ClassTypeInformation;
44+
import org.springframework.data.util.TypeInformation;
4545
import org.springframework.lang.Nullable;
4646
import org.springframework.util.ReflectionUtils;
4747

@@ -207,8 +207,8 @@ void shouldUseDefaultFieldNamingStrategy() {
207207
PropertyNameFieldNamingStrategy.INSTANCE, true);
208208

209209
ElasticsearchPersistentEntity<FieldNamingStrategyEntity> entity = new SimpleElasticsearchPersistentEntity<>(
210-
ClassTypeInformation.from(FieldNamingStrategyEntity.class), contextConfiguration);
211-
ClassTypeInformation<FieldNamingStrategyEntity> type = ClassTypeInformation.from(FieldNamingStrategyEntity.class);
210+
TypeInformation.of(FieldNamingStrategyEntity.class), contextConfiguration);
211+
TypeInformation<FieldNamingStrategyEntity> type = TypeInformation.of(FieldNamingStrategyEntity.class);
212212

213213
java.lang.reflect.Field field = ReflectionUtils.findField(FieldNamingStrategyEntity.class,
214214
"withoutCustomFieldName");
@@ -232,8 +232,8 @@ void shouldUseCustomFieldNamingStrategy() {
232232
fieldNamingStrategy, true);
233233

234234
ElasticsearchPersistentEntity<FieldNamingStrategyEntity> entity = new SimpleElasticsearchPersistentEntity<>(
235-
ClassTypeInformation.from(FieldNamingStrategyEntity.class), contextConfiguration);
236-
ClassTypeInformation<FieldNamingStrategyEntity> type = ClassTypeInformation.from(FieldNamingStrategyEntity.class);
235+
TypeInformation.of(FieldNamingStrategyEntity.class), contextConfiguration);
236+
TypeInformation<FieldNamingStrategyEntity> type = TypeInformation.of(FieldNamingStrategyEntity.class);
237237

238238
java.lang.reflect.Field field = ReflectionUtils.findField(FieldNamingStrategyEntity.class,
239239
"withoutCustomFieldName");

0 commit comments

Comments
 (0)
Please sign in to comment.