Skip to content

Commit 772d412

Browse files
committed
DATAREDIS-660 - Adapt to API changes in mapping subsystem.
1 parent a06162d commit 772d412

14 files changed

+226
-243
lines changed

src/main/java/org/springframework/data/redis/core/RedisKeyValueAdapter.java

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.List;
2424
import java.util.Map;
2525
import java.util.Map.Entry;
26-
import java.util.Optional;
2726
import java.util.Set;
2827
import java.util.concurrent.TimeUnit;
2928
import java.util.concurrent.atomic.AtomicReference;
@@ -219,10 +218,10 @@ public Object put(final Serializable id, final Object item, final Serializable k
219218
rdo.setId(converter.getConversionService().convert(id, String.class));
220219

221220
if (!(item instanceof RedisData)) {
222-
KeyValuePersistentProperty idProperty = converter.getMappingContext().getPersistentEntity(item.getClass()).get()
223-
.getIdProperty().get();
224-
converter.getMappingContext().getPersistentEntity(item.getClass()).get().getPropertyAccessor(item)
225-
.setProperty(idProperty, Optional.ofNullable(id));
221+
KeyValuePersistentProperty idProperty = converter.getMappingContext()
222+
.getRequiredPersistentEntity(item.getClass()).getRequiredIdProperty();
223+
converter.getMappingContext().getRequiredPersistentEntity(item.getClass()).getPropertyAccessor(item)
224+
.setProperty(idProperty, id);
226225
}
227226
}
228227

@@ -441,8 +440,8 @@ public Long doInRedis(RedisConnection connection) throws DataAccessException {
441440

442441
public void update(final PartialUpdate<?> update) {
443442

444-
final RedisPersistentEntity<?> entity = this.converter.getMappingContext().getPersistentEntity(update.getTarget())
445-
.get();
443+
final RedisPersistentEntity<?> entity = this.converter.getMappingContext()
444+
.getRequiredPersistentEntity(update.getTarget());
446445

447446
final String keyspace = entity.getKeySpace();
448447
final Object id = update.getId();
@@ -632,32 +631,28 @@ private <T> T readBackTimeToLiveIfSet(final byte[] key, T target) {
632631
return target;
633632
}
634633

635-
RedisPersistentEntity<?> entity = this.converter.getMappingContext().getPersistentEntity(target.getClass()).get();
634+
RedisPersistentEntity<?> entity = this.converter.getMappingContext().getRequiredPersistentEntity(target.getClass());
636635
if (entity.hasExplictTimeToLiveProperty()) {
637636

638-
Optional<RedisPersistentProperty> ttlProperty = entity.getExplicitTimeToLiveProperty();
639-
if (!ttlProperty.isPresent()) {
637+
RedisPersistentProperty ttlProperty = entity.getExplicitTimeToLiveProperty();
638+
if (ttlProperty == null) {
640639
return target;
641640
}
642641

643-
final Optional<TimeToLive> ttl = ttlProperty.get().findAnnotation(TimeToLive.class);
642+
TimeToLive ttl = ttlProperty.findAnnotation(TimeToLive.class);
644643

645-
Long timeout = redisOps.execute(new RedisCallback<Long>() {
644+
Long timeout = redisOps.execute((RedisCallback<Long>) connection -> {
646645

647-
@Override
648-
public Long doInRedis(RedisConnection connection) throws DataAccessException {
649-
650-
if (ObjectUtils.nullSafeEquals(TimeUnit.SECONDS, ttl.get().unit())) {
651-
return connection.ttl(key);
652-
}
653-
654-
return connection.pTtl(key, ttl.get().unit());
646+
if (ObjectUtils.nullSafeEquals(TimeUnit.SECONDS, ttl.unit())) {
647+
return connection.ttl(key);
655648
}
649+
650+
return connection.pTtl(key, ttl.unit());
656651
});
657652

658-
if (timeout != null || !ttlProperty.get().getType().isPrimitive()) {
659-
entity.getPropertyAccessor(target).setProperty(ttlProperty.get(),
660-
Optional.ofNullable(converter.getConversionService().convert(timeout, ttlProperty.get().getType())));
653+
if (timeout != null || !ttlProperty.getType().isPrimitive()) {
654+
entity.getPropertyAccessor(target).setProperty(ttlProperty,
655+
converter.getConversionService().convert(timeout, ttlProperty.getType()));
661656
}
662657
}
663658

@@ -757,7 +752,7 @@ private void initKeyExpirationListener() {
757752
}
758753

759754
/**
760-
* {@link MessageListener} implementation used to capture Redis keypspace notifications. Tries to read a previously
755+
* {@link MessageListener} implementation used to capture Redis keyspace notifications. Tries to read a previously
761756
* created phantom key {@code keyspace:id:phantom} to provide the expired object as part of the published
762757
* {@link RedisKeyExpiredEvent}.
763758
*

0 commit comments

Comments
 (0)