diff --git a/src/main/java/org/springframework/data/elasticsearch/core/convert/DefaultElasticsearchTypeMapper.java b/src/main/java/org/springframework/data/elasticsearch/core/convert/DefaultElasticsearchTypeMapper.java index 4974c96ef..e9946e282 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/convert/DefaultElasticsearchTypeMapper.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/convert/DefaultElasticsearchTypeMapper.java @@ -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_TYPE_INFO = ClassTypeInformation.from(Map.class); + private static final TypeInformation MAP_TYPE_INFO = TypeInformation.of(Map.class); private final @Nullable String typeKey; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java b/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java index 96539c2fc..9613ed04f 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java @@ -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 read(Class type, Document source) { - TypeInformation typeHint = ClassTypeInformation.from((Class) ClassUtils.getUserClass(type)); + TypeInformation typeHint = TypeInformation.of((Class) 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) value)); } else if (value instanceof List) { map.put(key, - readCollectionOrArray(valueType != null ? valueType : ClassTypeInformation.LIST, (List) value)); + readCollectionOrArray(valueType != null ? valueType : TypeInformation.LIST, (List) 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 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 potentiallyConvertSpelValue(Object object, Parameter parameter) { + protected T potentiallyConvertSpelValue(Object object, + Parameter 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) source, sink, ClassTypeInformation.MAP); + writeMapInternal((Map) 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 sink, @@ -813,7 +822,7 @@ public class MappingElasticsearchConverter } else { Map 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 document = existingValue instanceof Map ? (Map) 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); } diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchQueryMethod.java b/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchQueryMethod.java index 00acc78ae..4e6259d99 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchQueryMethod.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchQueryMethod.java @@ -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"); diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/query/ReactiveElasticsearchQueryMethod.java b/src/main/java/org/springframework/data/elasticsearch/repository/query/ReactiveElasticsearchQueryMethod.java index 4c1bad124..af9696202 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/query/ReactiveElasticsearchQueryMethod.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/query/ReactiveElasticsearchQueryMethod.java @@ -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_TYPE = ClassTypeInformation.from(Page.class); - private static final ClassTypeInformation SLICE_TYPE = ClassTypeInformation.from(Slice.class); + private static final TypeInformation PAGE_TYPE = TypeInformation.of(Page.class); + private static final TypeInformation SLICE_TYPE = TypeInformation.of(Slice.class); private final Lazy 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> typeArguments = returnType.getTypeArguments(); if (!Mono.class.isAssignableFrom(returnType.getType()) || typeArguments.size() != 1 diff --git a/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntityTests.java b/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntityTests.java index 197d0bb03..0bf52d98d 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntityTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntityTests.java @@ -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 typeInformation = ClassTypeInformation - .from(EntityWithWrongVersionType.class); + TypeInformation typeInformation = TypeInformation + .of(EntityWithWrongVersionType.class); SimpleElasticsearchPersistentEntity entity = new SimpleElasticsearchPersistentEntity<>( typeInformation, contextConfiguration); @@ -73,8 +72,8 @@ public class SimpleElasticsearchPersistentEntityTests extends MappingContextBase @Test public void shouldThrowExceptionGivenMultipleVersionPropertiesArePresent() { - TypeInformation typeInformation = ClassTypeInformation - .from(EntityWithMultipleVersionField.class); + TypeInformation typeInformation = TypeInformation + .of(EntityWithMultipleVersionField.class); SimpleElasticsearchPersistentEntity 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 typeInformation = ClassTypeInformation - .from(EntityWithoutSeqNoPrimaryTerm.class); + TypeInformation typeInformation = TypeInformation + .of(EntityWithoutSeqNoPrimaryTerm.class); SimpleElasticsearchPersistentEntity entity = new SimpleElasticsearchPersistentEntity<>( typeInformation, contextConfiguration); @@ -113,8 +112,8 @@ public class SimpleElasticsearchPersistentEntityTests extends MappingContextBase @Test // DATAES-799 void shouldReportThatThereIsSeqNoPrimaryTermPropertyWhenThereIsSuchProperty() { - TypeInformation typeInformation = ClassTypeInformation - .from(EntityWithSeqNoPrimaryTerm.class); + TypeInformation typeInformation = TypeInformation + .of(EntityWithSeqNoPrimaryTerm.class); SimpleElasticsearchPersistentEntity entity = new SimpleElasticsearchPersistentEntity<>( typeInformation, contextConfiguration); @@ -127,8 +126,8 @@ public class SimpleElasticsearchPersistentEntityTests extends MappingContextBase // DATAES-799 void shouldReturnSeqNoPrimaryTermPropertyWhenThereIsSuchProperty() { - TypeInformation typeInformation = ClassTypeInformation - .from(EntityWithSeqNoPrimaryTerm.class); + TypeInformation typeInformation = TypeInformation + .of(EntityWithSeqNoPrimaryTerm.class); SimpleElasticsearchPersistentEntity 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 typeInformation = ClassTypeInformation - .from(EntityWithSeqNoPrimaryTerm.class); + TypeInformation typeInformation = TypeInformation + .of(EntityWithSeqNoPrimaryTerm.class); SimpleElasticsearchPersistentEntity entity = new SimpleElasticsearchPersistentEntity<>( typeInformation, contextConfiguration); entity.addPersistentProperty(createProperty(entity, "seqNoPrimaryTerm")); @@ -199,7 +198,7 @@ public class SimpleElasticsearchPersistentEntityTests extends MappingContextBase ] } } - } """; + }"""; ElasticsearchPersistentEntity entity = elasticsearchConverter.get().getMappingContext() .getRequiredPersistentEntity(SettingsValidSortParameterSizes.class); diff --git a/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentPropertyUnitTests.java b/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentPropertyUnitTests.java index 77497c3c8..54a1757b4 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentPropertyUnitTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentPropertyUnitTests.java @@ -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 entity = new SimpleElasticsearchPersistentEntity<>( - ClassTypeInformation.from(FieldNamingStrategyEntity.class), contextConfiguration); - ClassTypeInformation type = ClassTypeInformation.from(FieldNamingStrategyEntity.class); + TypeInformation.of(FieldNamingStrategyEntity.class), contextConfiguration); + TypeInformation 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 entity = new SimpleElasticsearchPersistentEntity<>( - ClassTypeInformation.from(FieldNamingStrategyEntity.class), contextConfiguration); - ClassTypeInformation type = ClassTypeInformation.from(FieldNamingStrategyEntity.class); + TypeInformation.of(FieldNamingStrategyEntity.class), contextConfiguration); + TypeInformation type = TypeInformation.of(FieldNamingStrategyEntity.class); java.lang.reflect.Field field = ReflectionUtils.findField(FieldNamingStrategyEntity.class, "withoutCustomFieldName");