ClassTypeInformation is now deprecated. (#1735)

Closes #1456.
This commit is contained in:
Michael Reiche
2023-05-10 10:59:44 -07:00
committed by mikereiche
parent 140c169799
commit e4e2f466c0
8 changed files with 29 additions and 35 deletions

View File

@@ -29,7 +29,6 @@ import org.springframework.data.couchbase.core.mapping.CouchbaseList;
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty;
import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
import org.springframework.data.mapping.model.EntityInstantiators;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
/**
@@ -163,12 +162,12 @@ public abstract class AbstractCouchbaseConverter implements CouchbaseConverter,
// superseded by EnumCvtrs value = Enum.class.isAssignableFrom(value.getClass()) ? ((Enum<?>) value).name() :
// value;
} else if (value instanceof Collection || elementType.isArray()) {
TypeInformation<?> type = ClassTypeInformation.from(value.getClass());
TypeInformation<?> type = TypeInformation.of(value.getClass());
value = ((MappingCouchbaseConverter) this).writeCollectionInternal(MappingCouchbaseConverter.asCollection(value),
new CouchbaseList(conversions.getSimpleTypeHolder()), type, null, null);
} else {
CouchbaseDocument embeddedDoc = new CouchbaseDocument();
TypeInformation<?> type = ClassTypeInformation.from(value.getClass());
TypeInformation<?> type = TypeInformation.of(value.getClass());
((MappingCouchbaseConverter) this).writeInternalRoot(value, embeddedDoc, type, false, null, true);
value = embeddedDoc;
}

View File

@@ -70,7 +70,6 @@ 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.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@@ -206,7 +205,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem
@Override
public <R> R read(final Class<R> clazz, final CouchbaseDocument source) {
return read(ClassTypeInformation.from(clazz), source, null);
return read(TypeInformation.of(clazz), source, null);
}
/**
@@ -438,7 +437,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem
}
boolean isCustom = conversions.getCustomWriteTarget(source.getClass(), CouchbaseDocument.class).isPresent();
TypeInformation<?> type = ClassTypeInformation.from(source.getClass());
TypeInformation<?> type = TypeInformation.of(source.getClass());
if (!isCustom) {
typeMapper.writeType(type, target);
@@ -472,7 +471,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem
}
if (Map.class.isAssignableFrom(source.getClass())) {
writeMapInternal((Map<Object, Object>) source, target, ClassTypeInformation.MAP, property);
writeMapInternal((Map<Object, Object>) source, target, TypeInformation.MAP, property);
return;
}
@@ -639,7 +638,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem
}
String name = prop.getFieldName();
TypeInformation<?> valueType = ClassTypeInformation.from(source.getClass());
TypeInformation<?> valueType = TypeInformation.of(source.getClass());
TypeInformation<?> type = prop.getTypeInformation();
if (valueType.isCollectionLike()) {
CouchbaseList collectionDoc = createCollection(asCollection(source), valueType, prop, accessor);
@@ -968,7 +967,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem
}
}
if (conversions.hasCustomReadTarget(value.getClass(), rawType)) {
TypeInformation ti = ClassTypeInformation.from(value.getClass());
TypeInformation ti = TypeInformation.of(value.getClass());
return (R) conversionService.convert(value, ti.toTypeDescriptor(), new TypeDescriptor(prop.getField()));
}
if (value instanceof CouchbaseDocument) {

View File

@@ -20,7 +20,6 @@ import org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext;
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity;
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.util.Assert;
@@ -66,7 +65,7 @@ public interface QueryIndexResolver {
* @see 2.2
*/
default Iterable<? extends IndexDefinition> resolveIndexFor(Class<?> entityType) {
return resolveIndexFor(ClassTypeInformation.from(entityType));
return resolveIndexFor(TypeInformation.of(entityType));
}
}

View File

@@ -34,7 +34,6 @@ import org.springframework.data.couchbase.repository.support.MappingCouchbaseEnt
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mapping.Alias;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.util.Assert;
@@ -383,7 +382,7 @@ public class Query {
.getRequiredPersistentEntity(domainClass);
MappingCouchbaseEntityInformation<?, Object> info = new MappingCouchbaseEntityInformation<>(persistentEntity);
String typeValue = info.getJavaType().getName();
TypeInformation<?> typeInfo = ClassTypeInformation.from(info.getJavaType());
TypeInformation<?> typeInfo = TypeInformation.of(info.getJavaType());
Alias alias = converter.getTypeAlias(typeInfo);
if (alias != null && alias.isPresent()) {
typeValue = alias.toString();

View File

@@ -26,7 +26,6 @@ import org.springframework.data.couchbase.repository.support.MappingCouchbaseEnt
import org.springframework.data.mapping.Alias;
import org.springframework.data.repository.query.ParameterAccessor;
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.expression.spel.standard.SpelExpressionParser;
@@ -118,7 +117,7 @@ public class StringQuery extends Query {
.getRequiredPersistentEntity(domainClass);
MappingCouchbaseEntityInformation<?, Object> info = new MappingCouchbaseEntityInformation<>(persistentEntity);
String typeValue = info.getJavaType().getName();
TypeInformation<?> typeInfo = ClassTypeInformation.from(info.getJavaType());
TypeInformation<?> typeInfo = TypeInformation.of(info.getJavaType());
Alias alias = converter.getTypeAlias(typeInfo);
if (alias != null && alias.isPresent()) {
typeValue = alias.toString();

View File

@@ -29,7 +29,6 @@ import org.springframework.data.repository.query.ParametersParameterAccessor;
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.RepositoryQuery;
import org.springframework.data.repository.query.ResultProcessor;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.lang.Nullable;
@@ -122,8 +121,8 @@ public abstract class AbstractCouchbaseQueryBase<CouchbaseOperationsType> implem
}
private Object execute(ParametersParameterAccessor parameterAccessor) {
TypeInformation<?> returnType = ClassTypeInformation
.from(method.getResultProcessor().getReturnedType().getReturnedType());
TypeInformation<?> returnType = TypeInformation
.of(method.getResultProcessor().getReturnedType().getReturnedType());
ResultProcessor processor = method.getResultProcessor().withDynamicProjection(parameterAccessor);
Class<?> typeToRead = processor.getReturnedType().getTypeToRead();

View File

@@ -27,7 +27,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.mock.env.MockPropertySource;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
@@ -41,7 +41,7 @@ public class BasicCouchbasePersistentEntityTests {
@Test
void testNoExpiryByDefault() {
CouchbasePersistentEntity<DefaultExpiry> entity = new BasicCouchbasePersistentEntity<>(
ClassTypeInformation.from(DefaultExpiry.class));
TypeInformation.of(DefaultExpiry.class));
assertThat(entity.getExpiryDuration().getSeconds()).isEqualTo(0);
}
@@ -49,7 +49,7 @@ public class BasicCouchbasePersistentEntityTests {
@Test
void testDefaultExpiryUnitIsSeconds() {
CouchbasePersistentEntity<DefaultExpiryUnit> entity = new BasicCouchbasePersistentEntity<>(
ClassTypeInformation.from(DefaultExpiryUnit.class));
TypeInformation.of(DefaultExpiryUnit.class));
assertThat(entity.getExpiryDuration().getSeconds()).isEqualTo(78);
}
@@ -57,14 +57,14 @@ public class BasicCouchbasePersistentEntityTests {
@Test
void testLargeExpiry30DaysStillInSeconds() {
CouchbasePersistentEntity<LimitDaysExpiry> entityUnder = new BasicCouchbasePersistentEntity<>(
ClassTypeInformation.from(LimitDaysExpiry.class));
TypeInformation.of(LimitDaysExpiry.class));
assertThat(entityUnder.getExpiryDuration().getSeconds()).isEqualTo(30 * 24 * 60 * 60);
}
@Test
void testLargeExpiry31DaysIsConvertedToUnixUtcTime() {
CouchbasePersistentEntity<OverLimitDaysExpiry> entityOver = new BasicCouchbasePersistentEntity<>(
ClassTypeInformation.from(OverLimitDaysExpiry.class));
TypeInformation.of(OverLimitDaysExpiry.class));
int expiryOver = (int) entityOver.getExpiry();
Calendar expected = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
@@ -84,7 +84,7 @@ public class BasicCouchbasePersistentEntityTests {
@Test
void testLargeExpiryExpression31DaysIsConvertedToUnixUtcTime() {
BasicCouchbasePersistentEntity<OverLimitDaysExpiryExpression> entityOver = new BasicCouchbasePersistentEntity<>(
ClassTypeInformation.from(OverLimitDaysExpiryExpression.class));
TypeInformation.of(OverLimitDaysExpiryExpression.class));
entityOver.setEnvironment(environment);
int expiryOver = (int) entityOver.getExpiry();
@@ -105,7 +105,7 @@ public class BasicCouchbasePersistentEntityTests {
@Test
void testLargeExpiry31DaysInSecondsIsConvertedToUnixUtcTime() {
CouchbasePersistentEntity<OverLimitSecondsExpiry> entityOver = new BasicCouchbasePersistentEntity<>(
ClassTypeInformation.from(OverLimitSecondsExpiry.class));
TypeInformation.of(OverLimitSecondsExpiry.class));
int expiryOver = (int) entityOver.getExpiry();
Calendar expected = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
@@ -182,7 +182,7 @@ public class BasicCouchbasePersistentEntityTests {
private BasicCouchbasePersistentEntity getBasicCouchbasePersistentEntity(Class<?> clazz) {
BasicCouchbasePersistentEntity basicCouchbasePersistentEntity = new BasicCouchbasePersistentEntity(
ClassTypeInformation.from(clazz));
TypeInformation.of(clazz));
basicCouchbasePersistentEntity.setEnvironment(environment);
return basicCouchbasePersistentEntity;
}

View File

@@ -27,7 +27,7 @@ import org.springframework.data.mapping.MappingException;
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.util.ReflectionUtils;
/**
@@ -48,7 +48,7 @@ public class BasicCouchbasePersistentPropertyTests {
*/
@BeforeEach
void beforeEach() {
entity = new BasicCouchbasePersistentEntity<>(ClassTypeInformation.from(Beer.class));
entity = new BasicCouchbasePersistentEntity<>(TypeInformation.of(Beer.class));
}
/**
@@ -72,7 +72,7 @@ public class BasicCouchbasePersistentPropertyTests {
@Test
void testSdkIdAnnotationEvaluatedAfterSpringIdAnnotationIsIgnored() {
BasicCouchbasePersistentEntity<Beer> test = new BasicCouchbasePersistentEntity<>(
ClassTypeInformation.from(Beer.class));
TypeInformation.of(Beer.class));
Field springIdField = ReflectionUtils.findField(Beer.class, "springId");
CouchbasePersistentProperty springIdProperty = getPropertyFor(springIdField);
@@ -91,7 +91,7 @@ public class BasicCouchbasePersistentPropertyTests {
@Id private String springId;
}
BasicCouchbasePersistentEntity<TestIdField> test = new BasicCouchbasePersistentEntity<>(
ClassTypeInformation.from(TestIdField.class));
TypeInformation.of(TestIdField.class));
Field springIdField = ReflectionUtils.findField(TestIdField.class, "springId");
CouchbasePersistentProperty springIdProperty = getPropertyFor(springIdField);
test.addPersistentProperty(springIdProperty);
@@ -108,7 +108,7 @@ public class BasicCouchbasePersistentPropertyTests {
Field idField = ReflectionUtils.findField(TestIdField.class, "id");
CouchbasePersistentProperty idProperty = getPropertyFor(idField);
BasicCouchbasePersistentEntity<TestIdField> test = new BasicCouchbasePersistentEntity<>(
ClassTypeInformation.from(TestIdField.class));
TypeInformation.of(TestIdField.class));
test.addPersistentProperty(idProperty);
assertThat(test.getIdProperty()).isEqualTo(idProperty);
}
@@ -122,7 +122,7 @@ public class BasicCouchbasePersistentPropertyTests {
private String id;
}
BasicCouchbasePersistentEntity<TestIdField> test = new BasicCouchbasePersistentEntity<>(
ClassTypeInformation.from(TestIdField.class));
TypeInformation.of(TestIdField.class));
Field springIdField = ReflectionUtils.findField(TestIdField.class, "springId");
Field idField = ReflectionUtils.findField(TestIdField.class, "id");
CouchbasePersistentProperty idProperty = getPropertyFor(idField);
@@ -148,7 +148,7 @@ public class BasicCouchbasePersistentPropertyTests {
CouchbasePersistentProperty idProperty = getPropertyFor(idField);
CouchbasePersistentProperty springIdProperty = getPropertyFor(springIdField);
BasicCouchbasePersistentEntity<TestIdField> test = new BasicCouchbasePersistentEntity<>(
ClassTypeInformation.from(TestIdField.class));
TypeInformation.of(TestIdField.class));
test.addPersistentProperty(springIdProperty);
assertThatExceptionOfType(MappingException.class).isThrownBy(() -> {
test.addPersistentProperty(idProperty);
@@ -168,7 +168,7 @@ public class BasicCouchbasePersistentPropertyTests {
CouchbasePersistentProperty idProperty = getPropertyFor(idField);
CouchbasePersistentProperty springIdProperty = getPropertyFor(springIdField);
BasicCouchbasePersistentEntity<TestIdField> test = new BasicCouchbasePersistentEntity<>(
ClassTypeInformation.from(TestIdField.class));
TypeInformation.of(TestIdField.class));
test.addPersistentProperty(springIdProperty);
assertThatExceptionOfType(MappingException.class).isThrownBy(() -> {
test.addPersistentProperty(idProperty);
@@ -183,7 +183,7 @@ public class BasicCouchbasePersistentPropertyTests {
*/
private CouchbasePersistentProperty getPropertyFor(Field field) {
ClassTypeInformation<?> type = ClassTypeInformation.from(field.getDeclaringClass());
TypeInformation<?> type = TypeInformation.of(field.getDeclaringClass());
return new BasicCouchbasePersistentProperty(Property.of(type, field), entity, SimpleTypeHolder.DEFAULT,
PropertyNameFieldNamingStrategy.INSTANCE);