DATAREDIS-523 - Polishing.
Allow reading of the TTL into primitive properties. Allow general numeric types for TTL properties. Extend date range in license headers. Extend JavaDoc. Original pull request: #208.
This commit is contained in:
@@ -605,9 +605,9 @@ public class RedisKeyValueAdapter extends AbstractKeyValueAdapter
|
||||
}
|
||||
});
|
||||
|
||||
if (timeout != null || (timeout == null && !ttlProperty.getType().isPrimitive())) {
|
||||
if (timeout != null || !ttlProperty.getType().isPrimitive()) {
|
||||
entity.getPropertyAccessor(target).setProperty(ttlProperty,
|
||||
NumberUtils.convertNumberToTargetClass(timeout, (Class) ttlProperty.getType()));
|
||||
converter.getConversionService().convert(timeout, ttlProperty.getType()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -282,9 +282,9 @@ public class RedisMappingContext extends KeyValueMappingContext {
|
||||
} else if (ttlProperty != null) {
|
||||
|
||||
RedisPersistentEntity entity = mappingContext.getPersistentEntity(type);
|
||||
Long timeout = (Long) entity.getPropertyAccessor(source).getProperty(ttlProperty);
|
||||
Number timeout = (Number) entity.getPropertyAccessor(source).getProperty(ttlProperty);
|
||||
if (timeout != null) {
|
||||
return TimeUnit.SECONDS.convert(timeout, unit);
|
||||
return TimeUnit.SECONDS.convert(timeout.longValue(), unit);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,7 +43,7 @@ public interface RedisPersistentEntity<T> extends KeyValuePersistentEntity<T> {
|
||||
boolean hasExplictTimeToLiveProperty();
|
||||
|
||||
/**
|
||||
* Get the {@link PersistentProperty}
|
||||
* Get the {@link PersistentProperty} that is annotated with {@link org.springframework.data.redis.core.TimeToLive}.
|
||||
*
|
||||
* @return can be {@null}.
|
||||
* @since 1.8
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -48,7 +48,10 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link RedisKeyValueTemplate}.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class RedisKeyValueTemplateTests {
|
||||
@@ -887,6 +890,25 @@ public class RedisKeyValueTemplateTests {
|
||||
assertThat(target.ttl.doubleValue(), is(closeTo(3D, 1D)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-523
|
||||
*/
|
||||
@Test
|
||||
public void shouldReadBackExplicitTimeToLiveToPrimitiveField() throws InterruptedException {
|
||||
|
||||
WithPrimitiveTtl source = new WithPrimitiveTtl();
|
||||
source.id = "ttl-1";
|
||||
source.ttl = 5;
|
||||
source.value = "5 seconds";
|
||||
|
||||
template.insert(source);
|
||||
|
||||
Thread.sleep(1100);
|
||||
|
||||
WithPrimitiveTtl target = template.findById(source.id, WithPrimitiveTtl.class);
|
||||
assertThat((double) target.ttl, is(closeTo(3D, 1D)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-523
|
||||
*/
|
||||
@@ -1049,4 +1071,12 @@ public class RedisKeyValueTemplateTests {
|
||||
String value;
|
||||
@TimeToLive Long ttl;
|
||||
}
|
||||
|
||||
@Data
|
||||
static class WithPrimitiveTtl {
|
||||
|
||||
@Id String id;
|
||||
String value;
|
||||
@TimeToLive int ttl;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user