DATAREDIS-538 - Allow @TimeToLive methods that are not accessible by default.
We allow now the use of non-public classes with a @TimeToLive method and @TimeToLive on non-public methods. Original Pull Request: #231
This commit is contained in:
committed by
Christoph Strobl
parent
54229d2388
commit
e62ecbb1a9
@@ -53,6 +53,7 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
* @since 1.7
|
||||
*/
|
||||
public class RedisMappingContext extends KeyValueMappingContext<RedisPersistentEntity<?>, RedisPersistentProperty> {
|
||||
@@ -256,6 +257,10 @@ public class RedisMappingContext extends KeyValueMappingContext<RedisPersistentE
|
||||
Method timeoutMethod = resolveTimeMethod(type);
|
||||
if (timeoutMethod != null) {
|
||||
|
||||
if (!timeoutMethod.isAccessible()) {
|
||||
ReflectionUtils.makeAccessible(timeoutMethod);
|
||||
}
|
||||
|
||||
TimeToLive ttl = AnnotationUtils.findAnnotation(timeoutMethod, TimeToLive.class);
|
||||
try {
|
||||
Number timeout = (Number) timeoutMethod.invoke(source);
|
||||
|
||||
@@ -28,7 +28,10 @@ import org.springframework.data.redis.core.convert.KeyspaceConfiguration.Keyspac
|
||||
import org.springframework.data.redis.core.mapping.RedisMappingContext.ConfigAwareTimeToLiveAccessor;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ConfigAwareTimeToLiveAccessor}.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class ConfigAwareTimeToLiveAccessorUnitTests {
|
||||
|
||||
@@ -137,6 +140,11 @@ public class ConfigAwareTimeToLiveAccessorUnitTests {
|
||||
assertThat(accessor.getTimeToLive(new TypeWithTtlOnMethod(100L))).isEqualTo(100L);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-538
|
||||
public void getTimeToLiveShouldReturnMethodLevelTimeToLiveOfNonPublicTypeIfPresent() {
|
||||
assertThat(accessor.getTimeToLive(new PrivateTypeWithTtlOnMethod(10L))).isEqualTo(10L);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-471
|
||||
public void getTimeToLiveShouldReturnDefaultValue() {
|
||||
|
||||
@@ -212,6 +220,22 @@ public class ConfigAwareTimeToLiveAccessorUnitTests {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@TimeToLive
|
||||
private Long getTimeToLive() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
// Type must be private so it does not fall in the
|
||||
// package-default scope like the types from above
|
||||
private static class PrivateTypeWithTtlOnMethod {
|
||||
|
||||
Long value;
|
||||
|
||||
public PrivateTypeWithTtlOnMethod(Long value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@TimeToLive
|
||||
Long getTimeToLive() {
|
||||
return value;
|
||||
|
||||
Reference in New Issue
Block a user