Replace ClassTypeInformation usages with TypeInformation.

Original Pull Request #2235
Closes #2234
This commit is contained in:
Peter-Josef Meisch 2022-07-19 22:37:05 +02:00 committed by GitHub
parent 47c0e186ec
commit 12b332223f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 47 deletions

View File

@ -26,7 +26,6 @@ import org.springframework.data.convert.TypeInformationMapper;
import org.springframework.data.mapping.Alias;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
@ -41,7 +40,7 @@ public class DefaultElasticsearchTypeMapper extends DefaultTypeMapper<Map<String
implements ElasticsearchTypeMapper {
@SuppressWarnings("rawtypes") //
private static final TypeInformation<Map> MAP_TYPE_INFO = ClassTypeInformation.from(Map.class);
private static final TypeInformation<Map> MAP_TYPE_INFO = TypeInformation.of(Map.class);
private final @Nullable String typeKey;

View File

@ -53,8 +53,16 @@ import org.springframework.data.mapping.Parameter;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.mapping.SimplePropertyHandler;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.*;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
import org.springframework.data.mapping.model.DefaultSpELExpressionEvaluator;
import org.springframework.data.mapping.model.EntityInstantiator;
import org.springframework.data.mapping.model.EntityInstantiators;
import org.springframework.data.mapping.model.ParameterValueProvider;
import org.springframework.data.mapping.model.PersistentEntityParameterValueProvider;
import org.springframework.data.mapping.model.PropertyValueProvider;
import org.springframework.data.mapping.model.SpELContext;
import org.springframework.data.mapping.model.SpELExpressionEvaluator;
import org.springframework.data.mapping.model.SpELExpressionParameterValueProvider;
import org.springframework.data.util.TypeInformation;
import org.springframework.format.datetime.DateFormatterRegistrar;
import org.springframework.lang.Nullable;
@ -213,7 +221,7 @@ public class MappingElasticsearchConverter
@SuppressWarnings("unchecked")
<R> R read(Class<R> type, Document source) {
TypeInformation<R> typeHint = ClassTypeInformation.from((Class<R>) ClassUtils.getUserClass(type));
TypeInformation<R> typeHint = TypeInformation.of((Class<R>) ClassUtils.getUserClass(type));
R r = read(typeHint, source);
if (r == null) {
@ -244,7 +252,7 @@ public class MappingElasticsearchConverter
return readMap(typeToUse, source);
}
if (typeToUse.equals(ClassTypeInformation.OBJECT)) {
if (typeToUse.equals(TypeInformation.OBJECT)) {
return (R) source;
}
// Retrieve persistent entity info
@ -286,13 +294,13 @@ public class MappingElasticsearchConverter
}
Object value = entry.getValue();
TypeInformation<?> defaultedValueType = valueType != null ? valueType : ClassTypeInformation.OBJECT;
TypeInformation<?> defaultedValueType = valueType != null ? valueType : TypeInformation.OBJECT;
if (value instanceof Map) {
map.put(key, read(defaultedValueType, (Map<String, Object>) value));
} else if (value instanceof List) {
map.put(key,
readCollectionOrArray(valueType != null ? valueType : ClassTypeInformation.LIST, (List<Object>) value));
readCollectionOrArray(valueType != null ? valueType : TypeInformation.LIST, (List<Object>) value));
} else {
map.put(key, getPotentiallyConvertedSimpleRead(value, rawValueType));
}
@ -397,7 +405,7 @@ public class MappingElasticsearchConverter
for (ElasticsearchPersistentProperty prop : entity) {
if (entity.isConstructorArgument(prop) || !prop.isReadable()) {
if (entity.isCreatorArgument(prop) || !prop.isReadable()) {
continue;
}
@ -504,7 +512,7 @@ public class MappingElasticsearchConverter
TypeInformation<?> componentType = targetType.getComponentType() != null //
? targetType.getComponentType() //
: ClassTypeInformation.OBJECT;
: TypeInformation.OBJECT;
Class<?> rawComponentType = componentType.getType();
Collection<Object> items = targetType.getType().isArray() //
@ -649,7 +657,8 @@ public class MappingElasticsearchConverter
* @see org.springframework.data.mapping.model.SpELExpressionParameterValueProvider#potentiallyConvertSpelValue(java.lang.Object, org.springframework.data.mapping.PreferredConstructor.Parameter)
*/
@Override
protected <T> T potentiallyConvertSpelValue(Object object, Parameter<T, ElasticsearchPersistentProperty> parameter) {
protected <T> T potentiallyConvertSpelValue(Object object,
Parameter<T, ElasticsearchPersistentProperty> parameter) {
return readValue(object, parameter.getType());
}
}
@ -694,7 +703,7 @@ public class MappingElasticsearchConverter
writeTypeHints = entity.writeTypeHints();
}
TypeInformation<?> typeInformation = ClassTypeInformation.from(entityType);
TypeInformation<?> typeInformation = TypeInformation.of(entityType);
if (writeTypeHints && requiresTypeHint(entityType)) {
typeMapper.writeType(typeInformation, sink);
@ -707,7 +716,7 @@ public class MappingElasticsearchConverter
* Internal write conversion method which should be used for nested invocations.
*
* @param source the object to write
* @param sink the write destination
* @param sink the destination
* @param typeInformation type information for the source
*/
@SuppressWarnings("unchecked")
@ -731,12 +740,12 @@ public class MappingElasticsearchConverter
}
if (Map.class.isAssignableFrom(entityType)) {
writeMapInternal((Map<Object, Object>) source, sink, ClassTypeInformation.MAP);
writeMapInternal((Map<Object, Object>) source, sink, TypeInformation.MAP);
return;
}
if (Collection.class.isAssignableFrom(entityType)) {
writeCollectionInternal((Collection<?>) source, ClassTypeInformation.LIST, (Collection<?>) sink);
writeCollectionInternal((Collection<?>) source, TypeInformation.LIST, (Collection<?>) sink);
return;
}
@ -749,7 +758,7 @@ public class MappingElasticsearchConverter
* Internal write conversion method which should be used for nested invocations.
*
* @param source the object to write
* @param sink the write destination
* @param sink the destination
* @param entity entity for the source
*/
private void writeInternal(@Nullable Object source, Map<String, Object> sink,
@ -813,7 +822,7 @@ public class MappingElasticsearchConverter
} else {
Map<String, Object> document = Document.create();
TypeInformation<?> valueTypeInfo = propertyType.isMap() ? propertyType.getMapValueType()
: ClassTypeInformation.OBJECT;
: TypeInformation.OBJECT;
writeInternal(value, document, valueTypeInfo);
sink.put(simpleKey, document);
@ -923,7 +932,7 @@ public class MappingElasticsearchConverter
return;
}
TypeInformation<?> valueType = ClassTypeInformation.from(value.getClass());
TypeInformation<?> valueType = TypeInformation.of(value.getClass());
TypeInformation<?> type = property.getTypeInformation();
if (valueType.isCollectionLike()) {
@ -955,7 +964,7 @@ public class MappingElasticsearchConverter
Map<String, Object> document = existingValue instanceof Map ? (Map<String, Object>) existingValue
: Document.create();
addCustomTypeKeyIfNecessary(value, document, ClassTypeInformation.from(property.getRawType()));
addCustomTypeKeyIfNecessary(value, document, TypeInformation.of(property.getRawType()));
writeInternal(value, document, entity);
sink.set(property, document);
}

View File

@ -34,7 +34,6 @@ import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.query.QueryMethod;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.Lazy;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
@ -78,7 +77,7 @@ public class ElasticsearchQueryMethod extends QueryMethod {
protected void verifyCountQueryTypes() {
if (hasCountQueryAnnotation()) {
TypeInformation<?> returnType = ClassTypeInformation.fromReturnTypeOf(method);
TypeInformation<?> returnType = TypeInformation.fromReturnTypeOf(method);
if (returnType.getType() != long.class && !Long.class.isAssignableFrom(returnType.getType())) {
throw new InvalidDataAccessApiUsageException("count query methods must return a Long");

View File

@ -37,7 +37,6 @@ import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.util.ReactiveWrapperConverters;
import org.springframework.data.repository.util.ReactiveWrappers;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.Lazy;
import org.springframework.data.util.TypeInformation;
import org.springframework.util.ClassUtils;
@ -49,8 +48,8 @@ import org.springframework.util.ClassUtils;
*/
public class ReactiveElasticsearchQueryMethod extends ElasticsearchQueryMethod {
private static final ClassTypeInformation<Page> PAGE_TYPE = ClassTypeInformation.from(Page.class);
private static final ClassTypeInformation<Slice> SLICE_TYPE = ClassTypeInformation.from(Slice.class);
private static final TypeInformation<Page> PAGE_TYPE = TypeInformation.of(Page.class);
private static final TypeInformation<Slice> SLICE_TYPE = TypeInformation.of(Slice.class);
private final Lazy<Boolean> isCollectionQuery;
public ReactiveElasticsearchQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory,
@ -60,7 +59,7 @@ public class ReactiveElasticsearchQueryMethod extends ElasticsearchQueryMethod {
if (hasParameterOfType(method, Pageable.class)) {
TypeInformation<?> returnType = ClassTypeInformation.fromReturnTypeOf(method);
TypeInformation<?> returnType = TypeInformation.fromReturnTypeOf(method);
boolean multiWrapper = ReactiveWrappers.isMultiValueType(returnType.getType());
boolean singleWrapperWithWrappedPageableResult = ReactiveWrappers.isSingleValueType(returnType.getType())
&& (PAGE_TYPE.isAssignableFrom(returnType.getRequiredComponentType())
@ -75,12 +74,12 @@ public class ReactiveElasticsearchQueryMethod extends ElasticsearchQueryMethod {
if (!multiWrapper) {
throw new IllegalStateException(String.format(
"Method has to use a either multi-item reactive wrapper return type or a wrapped Page/Slice type. Offending method: %s",
method.toString()));
method));
}
if (hasParameterOfType(method, Sort.class)) {
throw new IllegalStateException(String.format("Method must not have Pageable *and* Sort parameter. "
+ "Use sorting capabilities on Pageble instead! Offending method: %s", method.toString()));
+ "Use sorting capabilities on Pageble instead! Offending method: %s", method));
}
}
@ -91,7 +90,7 @@ public class ReactiveElasticsearchQueryMethod extends ElasticsearchQueryMethod {
@Override
protected void verifyCountQueryTypes() {
if (hasCountQueryAnnotation()) {
TypeInformation<?> returnType = ClassTypeInformation.fromReturnTypeOf(method);
TypeInformation<?> returnType = TypeInformation.fromReturnTypeOf(method);
List<TypeInformation<?>> typeArguments = returnType.getTypeArguments();
if (!Mono.class.isAssignableFrom(returnType.getType()) || typeArguments.size() != 1

View File

@ -37,7 +37,6 @@ import org.springframework.data.mapping.model.FieldNamingStrategy;
import org.springframework.data.mapping.model.Property;
import org.springframework.data.mapping.model.PropertyNameFieldNamingStrategy;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
import org.springframework.util.ReflectionUtils;
@ -62,8 +61,8 @@ public class SimpleElasticsearchPersistentEntityTests extends MappingContextBase
@Test
public void shouldThrowExceptionGivenVersionPropertyIsNotLong() {
TypeInformation<EntityWithWrongVersionType> typeInformation = ClassTypeInformation
.from(EntityWithWrongVersionType.class);
TypeInformation<EntityWithWrongVersionType> typeInformation = TypeInformation
.of(EntityWithWrongVersionType.class);
SimpleElasticsearchPersistentEntity<EntityWithWrongVersionType> entity = new SimpleElasticsearchPersistentEntity<>(
typeInformation, contextConfiguration);
@ -73,8 +72,8 @@ public class SimpleElasticsearchPersistentEntityTests extends MappingContextBase
@Test
public void shouldThrowExceptionGivenMultipleVersionPropertiesArePresent() {
TypeInformation<EntityWithMultipleVersionField> typeInformation = ClassTypeInformation
.from(EntityWithMultipleVersionField.class);
TypeInformation<EntityWithMultipleVersionField> typeInformation = TypeInformation
.of(EntityWithMultipleVersionField.class);
SimpleElasticsearchPersistentEntity<EntityWithMultipleVersionField> entity = new SimpleElasticsearchPersistentEntity<>(
typeInformation, contextConfiguration);
SimpleElasticsearchPersistentProperty persistentProperty1 = createProperty(entity, "version1");
@ -102,8 +101,8 @@ public class SimpleElasticsearchPersistentEntityTests extends MappingContextBase
@Test
// DATAES-799
void shouldReportThatThereIsNoSeqNoPrimaryTermPropertyWhenThereIsNoSuchProperty() {
TypeInformation<EntityWithoutSeqNoPrimaryTerm> typeInformation = ClassTypeInformation
.from(EntityWithoutSeqNoPrimaryTerm.class);
TypeInformation<EntityWithoutSeqNoPrimaryTerm> typeInformation = TypeInformation
.of(EntityWithoutSeqNoPrimaryTerm.class);
SimpleElasticsearchPersistentEntity<EntityWithoutSeqNoPrimaryTerm> entity = new SimpleElasticsearchPersistentEntity<>(
typeInformation, contextConfiguration);
@ -113,8 +112,8 @@ public class SimpleElasticsearchPersistentEntityTests extends MappingContextBase
@Test
// DATAES-799
void shouldReportThatThereIsSeqNoPrimaryTermPropertyWhenThereIsSuchProperty() {
TypeInformation<EntityWithSeqNoPrimaryTerm> typeInformation = ClassTypeInformation
.from(EntityWithSeqNoPrimaryTerm.class);
TypeInformation<EntityWithSeqNoPrimaryTerm> typeInformation = TypeInformation
.of(EntityWithSeqNoPrimaryTerm.class);
SimpleElasticsearchPersistentEntity<EntityWithSeqNoPrimaryTerm> entity = new SimpleElasticsearchPersistentEntity<>(
typeInformation, contextConfiguration);
@ -127,8 +126,8 @@ public class SimpleElasticsearchPersistentEntityTests extends MappingContextBase
// DATAES-799
void shouldReturnSeqNoPrimaryTermPropertyWhenThereIsSuchProperty() {
TypeInformation<EntityWithSeqNoPrimaryTerm> typeInformation = ClassTypeInformation
.from(EntityWithSeqNoPrimaryTerm.class);
TypeInformation<EntityWithSeqNoPrimaryTerm> typeInformation = TypeInformation
.of(EntityWithSeqNoPrimaryTerm.class);
SimpleElasticsearchPersistentEntity<EntityWithSeqNoPrimaryTerm> entity = new SimpleElasticsearchPersistentEntity<>(
typeInformation, contextConfiguration);
entity.addPersistentProperty(createProperty(entity, "seqNoPrimaryTerm"));
@ -146,8 +145,8 @@ public class SimpleElasticsearchPersistentEntityTests extends MappingContextBase
@Test
// DATAES-799
void shouldNotAllowMoreThanOneSeqNoPrimaryTermProperties() {
TypeInformation<EntityWithSeqNoPrimaryTerm> typeInformation = ClassTypeInformation
.from(EntityWithSeqNoPrimaryTerm.class);
TypeInformation<EntityWithSeqNoPrimaryTerm> typeInformation = TypeInformation
.of(EntityWithSeqNoPrimaryTerm.class);
SimpleElasticsearchPersistentEntity<EntityWithSeqNoPrimaryTerm> entity = new SimpleElasticsearchPersistentEntity<>(
typeInformation, contextConfiguration);
entity.addPersistentProperty(createProperty(entity, "seqNoPrimaryTerm"));

View File

@ -41,7 +41,7 @@ import org.springframework.data.mapping.model.Property;
import org.springframework.data.mapping.model.PropertyNameFieldNamingStrategy;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.mapping.model.SnakeCaseFieldNamingStrategy;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
import org.springframework.util.ReflectionUtils;
@ -207,8 +207,8 @@ public class SimpleElasticsearchPersistentPropertyUnitTests {
PropertyNameFieldNamingStrategy.INSTANCE, true);
ElasticsearchPersistentEntity<FieldNamingStrategyEntity> entity = new SimpleElasticsearchPersistentEntity<>(
ClassTypeInformation.from(FieldNamingStrategyEntity.class), contextConfiguration);
ClassTypeInformation<FieldNamingStrategyEntity> type = ClassTypeInformation.from(FieldNamingStrategyEntity.class);
TypeInformation.of(FieldNamingStrategyEntity.class), contextConfiguration);
TypeInformation<FieldNamingStrategyEntity> type = TypeInformation.of(FieldNamingStrategyEntity.class);
java.lang.reflect.Field field = ReflectionUtils.findField(FieldNamingStrategyEntity.class,
"withoutCustomFieldName");
@ -232,8 +232,8 @@ public class SimpleElasticsearchPersistentPropertyUnitTests {
fieldNamingStrategy, true);
ElasticsearchPersistentEntity<FieldNamingStrategyEntity> entity = new SimpleElasticsearchPersistentEntity<>(
ClassTypeInformation.from(FieldNamingStrategyEntity.class), contextConfiguration);
ClassTypeInformation<FieldNamingStrategyEntity> type = ClassTypeInformation.from(FieldNamingStrategyEntity.class);
TypeInformation.of(FieldNamingStrategyEntity.class), contextConfiguration);
TypeInformation<FieldNamingStrategyEntity> type = TypeInformation.of(FieldNamingStrategyEntity.class);
java.lang.reflect.Field field = ReflectionUtils.findField(FieldNamingStrategyEntity.class,
"withoutCustomFieldName");