Skip to content

Commit 42ea333

Browse files
committed
Support module specific repository.
1 parent 2e29a99 commit 42ea333

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.springframework.data.redis.repository;
2+
3+
import org.springframework.data.keyvalue.repository.KeyValueRepository;
4+
5+
/**
6+
* Redis specific {@link org.springframework.data.repository.Repository} interface.
7+
*
8+
* @author Junghoon Ban
9+
* @param <T>
10+
* @param <ID>
11+
*/
12+
public interface RedisRepository<T, ID> extends KeyValueRepository<T, ID> {}

src/main/java/org/springframework/data/redis/repository/configuration/RedisRepositoryConfigurationExtension.java

+9
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
import java.util.Collection;
2020
import java.util.Collections;
2121

22+
import java.util.List;
2223
import org.springframework.beans.factory.config.BeanDefinition;
2324
import org.springframework.beans.factory.support.AbstractBeanDefinition;
2425
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
2526
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
2627
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
2728
import org.springframework.beans.factory.support.RootBeanDefinition;
29+
import org.springframework.data.keyvalue.repository.KeyValueRepository;
2830
import org.springframework.data.keyvalue.repository.config.KeyValueRepositoryConfigurationExtension;
2931
import org.springframework.data.redis.core.RedisHash;
3032
import org.springframework.data.redis.core.RedisKeyValueAdapter;
@@ -35,6 +37,7 @@
3537
import org.springframework.data.redis.core.convert.MappingRedisConverter;
3638
import org.springframework.data.redis.core.convert.RedisCustomConversions;
3739
import org.springframework.data.redis.core.mapping.RedisMappingContext;
40+
import org.springframework.data.redis.repository.RedisRepository;
3841
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
3942
import org.springframework.data.repository.config.RepositoryConfigurationSource;
4043
import org.springframework.util.StringUtils;
@@ -44,6 +47,7 @@
4447
*
4548
* @author Christoph Strobl
4649
* @author Mark Paluch
50+
* @author Junghoon Ban
4751
* @since 1.7
4852
*/
4953
public class RedisRepositoryConfigurationExtension extends KeyValueRepositoryConfigurationExtension {
@@ -69,6 +73,11 @@ protected String getDefaultKeyValueTemplateRef() {
6973
return "redisKeyValueTemplate";
7074
}
7175

76+
@Override
77+
protected Collection<Class<?>> getIdentifyingTypes() {
78+
return List.of(RedisRepository.class, KeyValueRepository.class);
79+
}
80+
7281
@Override
7382
public void registerBeansForRoot(BeanDefinitionRegistry registry, RepositoryConfigurationSource configuration) {
7483

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

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* @author Christoph Strobl
3939
* @author Oliver Gierke
4040
* @author Mark Paluch
41+
* @author Junghoon Ban
4142
* @since 1.7
4243
*/
4344
public class RedisRepositoryFactory extends KeyValueRepositoryFactory {
@@ -75,6 +76,11 @@ public RedisRepositoryFactory(KeyValueOperations keyValueOperations,
7576
this.operations = keyValueOperations;
7677
}
7778

79+
@Override
80+
protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
81+
return SimpleRedisRepository.class;
82+
}
83+
7884
@Override
7985
protected RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata) {
8086

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.springframework.data.redis.repository.support;
2+
3+
import org.springframework.data.keyvalue.core.KeyValueOperations;
4+
import org.springframework.data.keyvalue.repository.support.SimpleKeyValueRepository;
5+
import org.springframework.data.redis.repository.RedisRepository;
6+
import org.springframework.data.repository.NoRepositoryBean;
7+
import org.springframework.data.repository.core.EntityInformation;
8+
9+
/**
10+
* Redis specific repository implementation.
11+
*
12+
* @author Junghoon Ban
13+
* @param <T>
14+
* @param <ID>
15+
*/
16+
@NoRepositoryBean
17+
public class SimpleRedisRepository<T, ID> extends SimpleKeyValueRepository<T, ID> implements RedisRepository<T, ID> {
18+
19+
public SimpleRedisRepository(EntityInformation<T, ID> metadata, KeyValueOperations operations) {
20+
super(metadata, operations);
21+
}
22+
}

src/test/java/org/springframework/data/redis/repository/configuration/RedisRepositoryConfigurationExtensionUnitTests.java

+8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.springframework.data.keyvalue.repository.KeyValueRepository;
3434
import org.springframework.data.redis.core.RedisHash;
3535
import org.springframework.data.redis.core.RedisKeyValueAdapter.EnableKeyspaceEvents;
36+
import org.springframework.data.redis.repository.RedisRepository;
3637
import org.springframework.data.repository.Repository;
3738
import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource;
3839
import org.springframework.data.repository.config.RepositoryConfiguration;
@@ -117,6 +118,11 @@ void explicitlyEmptyKeyspaceNotificationsConfigParameterShouldBeCapturedCorrectl
117118
assertThat(getKeyspaceNotificationsConfigParameter(beanDefintionRegistry)).isEqualTo("");
118119
}
119120

121+
@Test // GH-2816
122+
void shouldConsiderModuleSpecificRepository() {
123+
assertHasRepo(ModuleSpecificRepository.class, extension.getRepositoryConfigurations(configurationSource, loader, true));
124+
}
125+
120126
private static void assertDoesNotHaveRepo(Class<?> repositoryInterface,
121127
Collection<RepositoryConfiguration<RepositoryConfigurationSource>> configs) {
122128

@@ -198,4 +204,6 @@ interface SampleRepository extends Repository<Sample, Long> {}
198204
interface UnannotatedRepository extends Repository<Object, Long> {}
199205

200206
interface StoreRepository extends KeyValueRepository<Object, Long> {}
207+
208+
interface ModuleSpecificRepository extends RedisRepository<Object, Long> {}
201209
}

0 commit comments

Comments
 (0)