Move off deprecated API.

Closes #2409
This commit is contained in:
Mark Paluch
2022-09-15 14:43:02 +02:00
parent 1801ae8562
commit 8034cce7cb
7 changed files with 51 additions and 59 deletions

View File

@@ -38,10 +38,10 @@ import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.data.convert.CustomConversions;
import org.springframework.data.mapping.AssociationHandler;
import org.springframework.data.mapping.InstanceCreatorMetadata;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.mapping.PreferredConstructor;
import org.springframework.data.mapping.PropertyHandler;
import org.springframework.data.mapping.model.EntityInstantiator;
import org.springframework.data.mapping.model.EntityInstantiators;
@@ -55,7 +55,6 @@ import org.springframework.data.redis.core.mapping.RedisMappingContext;
import org.springframework.data.redis.core.mapping.RedisPersistentEntity;
import org.springframework.data.redis.core.mapping.RedisPersistentProperty;
import org.springframework.data.redis.util.ByteUtils;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.ProxyUtils;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
@@ -177,7 +176,7 @@ public class MappingRedisConverter implements RedisConverter, InitializingBean {
@SuppressWarnings("unchecked")
public <R> R read(Class<R> type, RedisData source) {
TypeInformation<?> readType = typeMapper.readType(source.getBucket().getPath(), ClassTypeInformation.from(type));
TypeInformation<?> readType = typeMapper.readType(source.getBucket().getPath(), TypeInformation.of(type));
return readType.isCollectionLike()
? (R) readCollectionOrArray("", ArrayList.class, Object.class, source.getBucket())
@@ -193,7 +192,7 @@ public class MappingRedisConverter implements RedisConverter, InitializingBean {
@SuppressWarnings("unchecked")
private <R> R doReadInternal(String path, Class<R> type, RedisData source) {
TypeInformation<?> readType = typeMapper.readType(source.getBucket().getPath(), ClassTypeInformation.from(type));
TypeInformation<?> readType = typeMapper.readType(source.getBucket().getPath(), TypeInformation.of(type));
if (customConversions.hasCustomReadTarget(Map.class, readType.getType())) {
@@ -237,9 +236,9 @@ public class MappingRedisConverter implements RedisConverter, InitializingBean {
entity.doWithProperties((PropertyHandler<RedisPersistentProperty>) persistentProperty -> {
PreferredConstructor<?, RedisPersistentProperty> constructor = entity.getPersistenceConstructor();
InstanceCreatorMetadata<RedisPersistentProperty> creator = entity.getInstanceCreatorMetadata();
if (constructor != null && constructor.isConstructorParameter(persistentProperty)) {
if (creator != null && creator.isCreatorParameter(persistentProperty)) {
return;
}
@@ -490,10 +489,10 @@ public class MappingRedisConverter implements RedisConverter, InitializingBean {
targetProperty = getTargetPropertyOrNullForPath(path.replaceAll("\\.\\[.*\\]", ""), update.getTarget());
TypeInformation<?> ti = targetProperty == null ? ClassTypeInformation.OBJECT
TypeInformation<?> ti = targetProperty == null ? TypeInformation.OBJECT
: (targetProperty.isMap() ? (targetProperty.getTypeInformation().getMapValueType() != null
? targetProperty.getTypeInformation().getRequiredMapValueType()
: ClassTypeInformation.OBJECT) : targetProperty.getTypeInformation().getActualType());
: TypeInformation.OBJECT) : targetProperty.getTypeInformation().getActualType());
writeInternal(entity.getKeySpace(), pUpdate.getPropertyPath(), pUpdate.getValue(), ti, sink);
return;
@@ -820,7 +819,7 @@ public class MappingRedisConverter implements RedisConverter, InitializingBean {
Bucket elementData = bucket.extract(key);
TypeInformation<?> typeInformation = typeMapper.readType(elementData.getPropertyPath(key),
ClassTypeInformation.from(valueType));
TypeInformation.of(valueType));
Class<?> typeToUse = typeInformation.getType();
if (conversionService.canConvert(byte[].class, typeToUse)) {
@@ -863,7 +862,7 @@ public class MappingRedisConverter implements RedisConverter, InitializingBean {
if (customConversions.hasCustomWriteTarget(entry.getValue().getClass())) {
writeToBucket(currentPath, entry.getValue(), sink, mapValueType);
} else {
writeInternal(keyspace, currentPath, entry.getValue(), ClassTypeInformation.from(mapValueType), sink);
writeInternal(keyspace, currentPath, entry.getValue(), TypeInformation.of(mapValueType), sink);
}
}
}
@@ -930,7 +929,7 @@ public class MappingRedisConverter implements RedisConverter, InitializingBean {
Object mapKey = extractMapKeyForPath(path, key, keyType);
TypeInformation<?> typeInformation = typeMapper.readType(source.getBucket().getPropertyPath(key),
ClassTypeInformation.from(valueType));
TypeInformation.of(valueType));
Object o = readInternal(key, typeInformation.getType(), new RedisData(partial));
target.put(mapKey, o);
@@ -963,7 +962,7 @@ public class MappingRedisConverter implements RedisConverter, InitializingBean {
private Class<?> getTypeHint(String path, Bucket bucket, Class<?> fallback) {
TypeInformation<?> typeInformation = typeMapper.readType(bucket.getPropertyPath(path),
ClassTypeInformation.from(fallback));
TypeInformation.of(fallback));
return typeInformation.getType();
}

View File

@@ -39,7 +39,6 @@ import org.springframework.data.redis.core.index.SimpleIndexDefinition;
import org.springframework.data.redis.core.mapping.RedisMappingContext;
import org.springframework.data.redis.core.mapping.RedisPersistentEntity;
import org.springframework.data.redis.core.mapping.RedisPersistentProperty;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@@ -162,7 +161,7 @@ public class PathIndexResolver implements IndexResolver {
}
else if (persistentProperty.isEntity()
|| persistentProperty.getTypeInformation().getActualType().equals(ClassTypeInformation.OBJECT)) {
|| persistentProperty.getTypeInformation().getActualType().equals(TypeInformation.OBJECT)) {
typeHint = updateTypeHintForActualValue(typeHint, propertyValue);
indexes.addAll(
@@ -175,7 +174,7 @@ public class PathIndexResolver implements IndexResolver {
private TypeInformation<?> updateTypeHintForActualValue(TypeInformation<?> typeHint, Object propertyValue) {
if (typeHint.equals(ClassTypeInformation.OBJECT) || typeHint.getClass().isInterface()) {
if (typeHint.equals(TypeInformation.OBJECT) || typeHint.getClass().isInterface()) {
try {
typeHint = mappingContext.getRequiredPersistentEntity(propertyValue.getClass()).getTypeInformation();
} catch (Exception e) {
@@ -201,7 +200,7 @@ public class PathIndexResolver implements IndexResolver {
if (indexConfiguration.hasIndexFor(keyspace, path)) {
IndexingContext context = new IndexingContext(keyspace, path,
property != null ? property.getTypeInformation() : ClassTypeInformation.OBJECT);
property != null ? property.getTypeInformation() : TypeInformation.OBJECT);
for (IndexDefinition indexDefinition : indexConfiguration.getIndexDefinitionsFor(keyspace, path)) {

View File

@@ -215,9 +215,7 @@ public class RedisMappingContext extends KeyValueMappingContext<RedisPersistentE
unit = ttlProperty.getRequiredAnnotation(TimeToLive.class).unit();
}
if (source instanceof PartialUpdate) {
PartialUpdate<?> update = (PartialUpdate<?>) source;
if (source instanceof PartialUpdate<?> update) {
if (ttlProperty != null && !update.getPropertyUpdates().isEmpty()) {
for (PropertyUpdate pUpdate : update.getPropertyUpdates()) {
@@ -232,7 +230,7 @@ public class RedisMappingContext extends KeyValueMappingContext<RedisPersistentE
} else if (ttlProperty != null) {
RedisPersistentEntity entity = mappingContext.getRequiredPersistentEntity(type);
RedisPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(type);
Object ttlPropertyValue = entity.getPropertyAccessor(source).getProperty(ttlProperty);
if (ttlPropertyValue != null) {
@@ -245,9 +243,7 @@ public class RedisMappingContext extends KeyValueMappingContext<RedisPersistentE
if (timeoutMethod != null) {
if (!timeoutMethod.isAccessible()) {
ReflectionUtils.makeAccessible(timeoutMethod);
}
ReflectionUtils.makeAccessible(timeoutMethod);
TimeToLive ttl = AnnotationUtils.findAnnotation(timeoutMethod, TimeToLive.class);
try {
@@ -309,7 +305,6 @@ public class RedisMappingContext extends KeyValueMappingContext<RedisPersistentE
return defaultTimeout;
}
@SuppressWarnings({ "rawtypes" })
@Nullable
private PersistentProperty<?> resolveTtlProperty(Class<?> type) {
@@ -317,7 +312,7 @@ public class RedisMappingContext extends KeyValueMappingContext<RedisPersistentE
return timeoutProperties.get(type);
}
RedisPersistentEntity entity = mappingContext.getRequiredPersistentEntity(type);
RedisPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(type);
PersistentProperty<?> ttlProperty = entity.getPersistentProperty(TimeToLive.class);
if (ttlProperty != null) {

View File

@@ -87,7 +87,7 @@ public class RedisRepositoryFactory extends KeyValueRepositoryFactory {
MappingRedisEntityInformation<?, ?> entityInformation = new MappingRedisEntityInformation<>(persistentEntity);
fragments = fragments.append(RepositoryFragment.implemented(QueryByExampleExecutor.class,
getTargetRepositoryViaReflection(QueryByExampleRedisExecutor.class, entityInformation, operations)));
instantiateClass(QueryByExampleRedisExecutor.class, entityInformation, operations)));
}
return fragments;