Skip to content

Commit 8034cce

Browse files
committed
Move off deprecated API.
Closes #2409
1 parent 1801ae8 commit 8034cce

File tree

7 files changed

+51
-59
lines changed

7 files changed

+51
-59
lines changed

src/main/java/org/springframework/data/redis/core/convert/MappingRedisConverter.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
import org.springframework.core.convert.support.GenericConversionService;
3939
import org.springframework.data.convert.CustomConversions;
4040
import org.springframework.data.mapping.AssociationHandler;
41+
import org.springframework.data.mapping.InstanceCreatorMetadata;
4142
import org.springframework.data.mapping.MappingException;
4243
import org.springframework.data.mapping.PersistentPropertyAccessor;
4344
import org.springframework.data.mapping.PersistentPropertyPath;
44-
import org.springframework.data.mapping.PreferredConstructor;
4545
import org.springframework.data.mapping.PropertyHandler;
4646
import org.springframework.data.mapping.model.EntityInstantiator;
4747
import org.springframework.data.mapping.model.EntityInstantiators;
@@ -55,7 +55,6 @@
5555
import org.springframework.data.redis.core.mapping.RedisPersistentEntity;
5656
import org.springframework.data.redis.core.mapping.RedisPersistentProperty;
5757
import org.springframework.data.redis.util.ByteUtils;
58-
import org.springframework.data.util.ClassTypeInformation;
5958
import org.springframework.data.util.ProxyUtils;
6059
import org.springframework.data.util.TypeInformation;
6160
import org.springframework.lang.Nullable;
@@ -177,7 +176,7 @@ public MappingRedisConverter(@Nullable RedisMappingContext mappingContext, @Null
177176
@SuppressWarnings("unchecked")
178177
public <R> R read(Class<R> type, RedisData source) {
179178

180-
TypeInformation<?> readType = typeMapper.readType(source.getBucket().getPath(), ClassTypeInformation.from(type));
179+
TypeInformation<?> readType = typeMapper.readType(source.getBucket().getPath(), TypeInformation.of(type));
181180

182181
return readType.isCollectionLike()
183182
? (R) readCollectionOrArray("", ArrayList.class, Object.class, source.getBucket())
@@ -193,7 +192,7 @@ private <R> R readInternal(String path, Class<R> type, RedisData source) {
193192
@SuppressWarnings("unchecked")
194193
private <R> R doReadInternal(String path, Class<R> type, RedisData source) {
195194

196-
TypeInformation<?> readType = typeMapper.readType(source.getBucket().getPath(), ClassTypeInformation.from(type));
195+
TypeInformation<?> readType = typeMapper.readType(source.getBucket().getPath(), TypeInformation.of(type));
197196

198197
if (customConversions.hasCustomReadTarget(Map.class, readType.getType())) {
199198

@@ -237,9 +236,9 @@ private <R> R doReadInternal(String path, Class<R> type, RedisData source) {
237236

238237
entity.doWithProperties((PropertyHandler<RedisPersistentProperty>) persistentProperty -> {
239238

240-
PreferredConstructor<?, RedisPersistentProperty> constructor = entity.getPersistenceConstructor();
239+
InstanceCreatorMetadata<RedisPersistentProperty> creator = entity.getInstanceCreatorMetadata();
241240

242-
if (constructor != null && constructor.isConstructorParameter(persistentProperty)) {
241+
if (creator != null && creator.isCreatorParameter(persistentProperty)) {
243242
return;
244243
}
245244

@@ -490,10 +489,10 @@ private void writePartialPropertyUpdate(PartialUpdate<?> update, PropertyUpdate
490489

491490
targetProperty = getTargetPropertyOrNullForPath(path.replaceAll("\\.\\[.*\\]", ""), update.getTarget());
492491

493-
TypeInformation<?> ti = targetProperty == null ? ClassTypeInformation.OBJECT
492+
TypeInformation<?> ti = targetProperty == null ? TypeInformation.OBJECT
494493
: (targetProperty.isMap() ? (targetProperty.getTypeInformation().getMapValueType() != null
495494
? targetProperty.getTypeInformation().getRequiredMapValueType()
496-
: ClassTypeInformation.OBJECT) : targetProperty.getTypeInformation().getActualType());
495+
: TypeInformation.OBJECT) : targetProperty.getTypeInformation().getActualType());
497496

498497
writeInternal(entity.getKeySpace(), pUpdate.getPropertyPath(), pUpdate.getValue(), ti, sink);
499498
return;
@@ -820,7 +819,7 @@ private Object readCollectionOrArray(String path, Class<?> collectionType, Class
820819
Bucket elementData = bucket.extract(key);
821820

822821
TypeInformation<?> typeInformation = typeMapper.readType(elementData.getPropertyPath(key),
823-
ClassTypeInformation.from(valueType));
822+
TypeInformation.of(valueType));
824823

825824
Class<?> typeToUse = typeInformation.getType();
826825
if (conversionService.canConvert(byte[].class, typeToUse)) {
@@ -863,7 +862,7 @@ private void writeMap(@Nullable String keyspace, String path, Class<?> mapValueT
863862
if (customConversions.hasCustomWriteTarget(entry.getValue().getClass())) {
864863
writeToBucket(currentPath, entry.getValue(), sink, mapValueType);
865864
} else {
866-
writeInternal(keyspace, currentPath, entry.getValue(), ClassTypeInformation.from(mapValueType), sink);
865+
writeInternal(keyspace, currentPath, entry.getValue(), TypeInformation.of(mapValueType), sink);
867866
}
868867
}
869868
}
@@ -930,7 +929,7 @@ private String mapMapKey(Object key) {
930929
Object mapKey = extractMapKeyForPath(path, key, keyType);
931930

932931
TypeInformation<?> typeInformation = typeMapper.readType(source.getBucket().getPropertyPath(key),
933-
ClassTypeInformation.from(valueType));
932+
TypeInformation.of(valueType));
934933

935934
Object o = readInternal(key, typeInformation.getType(), new RedisData(partial));
936935
target.put(mapKey, o);
@@ -963,7 +962,7 @@ private Object extractMapKeyForPath(String path, String key, Class<?> targetType
963962
private Class<?> getTypeHint(String path, Bucket bucket, Class<?> fallback) {
964963

965964
TypeInformation<?> typeInformation = typeMapper.readType(bucket.getPropertyPath(path),
966-
ClassTypeInformation.from(fallback));
965+
TypeInformation.of(fallback));
967966
return typeInformation.getType();
968967
}
969968

src/main/java/org/springframework/data/redis/core/convert/PathIndexResolver.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.springframework.data.redis.core.mapping.RedisMappingContext;
4040
import org.springframework.data.redis.core.mapping.RedisPersistentEntity;
4141
import org.springframework.data.redis.core.mapping.RedisPersistentProperty;
42-
import org.springframework.data.util.ClassTypeInformation;
4342
import org.springframework.data.util.TypeInformation;
4443
import org.springframework.lang.Nullable;
4544
import org.springframework.util.Assert;
@@ -162,7 +161,7 @@ public void doWithPersistentProperty(RedisPersistentProperty persistentProperty)
162161
}
163162

164163
else if (persistentProperty.isEntity()
165-
|| persistentProperty.getTypeInformation().getActualType().equals(ClassTypeInformation.OBJECT)) {
164+
|| persistentProperty.getTypeInformation().getActualType().equals(TypeInformation.OBJECT)) {
166165

167166
typeHint = updateTypeHintForActualValue(typeHint, propertyValue);
168167
indexes.addAll(
@@ -175,7 +174,7 @@ else if (persistentProperty.isEntity()
175174

176175
private TypeInformation<?> updateTypeHintForActualValue(TypeInformation<?> typeHint, Object propertyValue) {
177176

178-
if (typeHint.equals(ClassTypeInformation.OBJECT) || typeHint.getClass().isInterface()) {
177+
if (typeHint.equals(TypeInformation.OBJECT) || typeHint.getClass().isInterface()) {
179178
try {
180179
typeHint = mappingContext.getRequiredPersistentEntity(propertyValue.getClass()).getTypeInformation();
181180
} catch (Exception e) {
@@ -201,7 +200,7 @@ protected Set<IndexedData> resolveIndex(String keyspace, String propertyPath,
201200
if (indexConfiguration.hasIndexFor(keyspace, path)) {
202201

203202
IndexingContext context = new IndexingContext(keyspace, path,
204-
property != null ? property.getTypeInformation() : ClassTypeInformation.OBJECT);
203+
property != null ? property.getTypeInformation() : TypeInformation.OBJECT);
205204

206205
for (IndexDefinition indexDefinition : indexConfiguration.getIndexDefinitionsFor(keyspace, path)) {
207206

src/main/java/org/springframework/data/redis/core/mapping/RedisMappingContext.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,7 @@ public Long getTimeToLive(Object source) {
215215
unit = ttlProperty.getRequiredAnnotation(TimeToLive.class).unit();
216216
}
217217

218-
if (source instanceof PartialUpdate) {
219-
220-
PartialUpdate<?> update = (PartialUpdate<?>) source;
218+
if (source instanceof PartialUpdate<?> update) {
221219

222220
if (ttlProperty != null && !update.getPropertyUpdates().isEmpty()) {
223221
for (PropertyUpdate pUpdate : update.getPropertyUpdates()) {
@@ -232,7 +230,7 @@ public Long getTimeToLive(Object source) {
232230

233231
} else if (ttlProperty != null) {
234232

235-
RedisPersistentEntity entity = mappingContext.getRequiredPersistentEntity(type);
233+
RedisPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(type);
236234

237235
Object ttlPropertyValue = entity.getPropertyAccessor(source).getProperty(ttlProperty);
238236
if (ttlPropertyValue != null) {
@@ -245,9 +243,7 @@ public Long getTimeToLive(Object source) {
245243

246244
if (timeoutMethod != null) {
247245

248-
if (!timeoutMethod.isAccessible()) {
249-
ReflectionUtils.makeAccessible(timeoutMethod);
250-
}
246+
ReflectionUtils.makeAccessible(timeoutMethod);
251247

252248
TimeToLive ttl = AnnotationUtils.findAnnotation(timeoutMethod, TimeToLive.class);
253249
try {
@@ -309,15 +305,14 @@ private Long resolveDefaultTimeOut(Class<?> type) {
309305
return defaultTimeout;
310306
}
311307

312-
@SuppressWarnings({ "rawtypes" })
313308
@Nullable
314309
private PersistentProperty<?> resolveTtlProperty(Class<?> type) {
315310

316311
if (timeoutProperties.containsKey(type)) {
317312
return timeoutProperties.get(type);
318313
}
319314

320-
RedisPersistentEntity entity = mappingContext.getRequiredPersistentEntity(type);
315+
RedisPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(type);
321316
PersistentProperty<?> ttlProperty = entity.getPersistentProperty(TimeToLive.class);
322317

323318
if (ttlProperty != null) {

src/main/java/org/springframework/data/redis/repository/support/RedisRepositoryFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata
8787
MappingRedisEntityInformation<?, ?> entityInformation = new MappingRedisEntityInformation<>(persistentEntity);
8888

8989
fragments = fragments.append(RepositoryFragment.implemented(QueryByExampleExecutor.class,
90-
getTargetRepositoryViaReflection(QueryByExampleRedisExecutor.class, entityInformation, operations)));
90+
instantiateClass(QueryByExampleRedisExecutor.class, entityInformation, operations)));
9191
}
9292

9393
return fragments;

src/test/java/org/springframework/data/redis/core/convert/MappingRedisConverterUnitTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ void writeAppendsListOfComplexObjectsCorrectly() {
198198
}
199199

200200
@Test // DATAREDIS-425
201-
void writeDoesNotAddClassTypeInformationCorrectlyForMatchingTypes() {
201+
void writeDoesNotAddTypeInformationCorrectlyForMatchingTypes() {
202202

203203
Address address = new Address();
204204
address.city = "two rivers";
@@ -211,7 +211,7 @@ void writeDoesNotAddClassTypeInformationCorrectlyForMatchingTypes() {
211211
}
212212

213213
@Test // DATAREDIS-425, DATAREDIS-543
214-
void writeAddsClassTypeInformationCorrectlyForNonMatchingTypes() {
214+
void writeAddsTypeInformationCorrectlyForNonMatchingTypes() {
215215

216216
AddressWithPostcode address = new AddressWithPostcode();
217217
address.city = "two rivers";
@@ -225,7 +225,7 @@ void writeAddsClassTypeInformationCorrectlyForNonMatchingTypes() {
225225
}
226226

227227
@Test // DATAREDIS-425
228-
void readConsidersClassTypeInformationCorrectlyForNonMatchingTypes() {
228+
void readConsidersTypeInformationCorrectlyForNonMatchingTypes() {
229229

230230
Map<String, String> map = new HashMap<>();
231231
map.put("address._class", AddressWithPostcode.class.getName());
@@ -262,7 +262,7 @@ void readEntityViaConstructor() {
262262
}
263263

264264
@Test // DATAREDIS-425
265-
void writeAddsClassTypeInformationCorrectlyForNonMatchingTypesInCollections() {
265+
void writeAddsTypeInformationCorrectlyForNonMatchingTypesInCollections() {
266266

267267
Person mat = new TaVeren();
268268
mat.firstname = "mat";
@@ -381,7 +381,7 @@ void readUnorderedListOfComplexPropertyCorrectly() {
381381
}
382382

383383
@Test // DATAREDIS-425
384-
void readListComplexPropertyCorrectlyAndConsidersClassTypeInformation() {
384+
void readListComplexPropertyCorrectlyAndConsidersTypeInformation() {
385385

386386
Map<String, String> map = new LinkedHashMap<>();
387387
map.put("coworkers.[0]._class", TaVeren.class.getName());
@@ -569,7 +569,7 @@ void readMapWithIntegerKeysAndComplexObjectsCorrectly() {
569569
}
570570

571571
@Test // DATAREDIS-425
572-
void writeAppendsClassTypeInformationCorrectlyForMapWithComplexObjects() {
572+
void writeAppendsTypeInformationCorrectlyForMapWithComplexObjects() {
573573

574574
Map<String, Person> map = new LinkedHashMap<>();
575575
Person lews = new TaVeren();
@@ -584,7 +584,7 @@ void writeAppendsClassTypeInformationCorrectlyForMapWithComplexObjects() {
584584
}
585585

586586
@Test // DATAREDIS-425
587-
void readConsidersClassTypeInformationCorrectlyForMapWithComplexObjects() {
587+
void readConsidersTypeInformationCorrectlyForMapWithComplexObjects() {
588588

589589
Map<String, String> map = new LinkedHashMap<>();
590590
map.put("relatives.[previous-incarnation]._class", TaVeren.class.getName());

0 commit comments

Comments
 (0)