Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support redis specific repository. #2817

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.springframework.data.redis.repository;

import org.springframework.data.keyvalue.repository.KeyValueRepository;

/**
* Redis specific {@link org.springframework.data.repository.Repository} interface.
*
* @author Junghoon Ban
* @param <T>
* @param <ID>
*/
public interface RedisRepository<T, ID> extends KeyValueRepository<T, ID> {}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import java.util.Collection;
import java.util.Collections;

import java.util.List;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.data.keyvalue.repository.KeyValueRepository;
import org.springframework.data.keyvalue.repository.config.KeyValueRepositoryConfigurationExtension;
import org.springframework.data.redis.core.RedisHash;
import org.springframework.data.redis.core.RedisKeyValueAdapter;
Expand All @@ -35,6 +37,7 @@
import org.springframework.data.redis.core.convert.MappingRedisConverter;
import org.springframework.data.redis.core.convert.RedisCustomConversions;
import org.springframework.data.redis.core.mapping.RedisMappingContext;
import org.springframework.data.redis.repository.RedisRepository;
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
import org.springframework.data.repository.config.RepositoryConfigurationSource;
import org.springframework.util.StringUtils;
Expand All @@ -44,6 +47,7 @@
*
* @author Christoph Strobl
* @author Mark Paluch
* @author Junghoon Ban
* @since 1.7
*/
public class RedisRepositoryConfigurationExtension extends KeyValueRepositoryConfigurationExtension {
Expand All @@ -69,6 +73,11 @@ protected String getDefaultKeyValueTemplateRef() {
return "redisKeyValueTemplate";
}

@Override
protected Collection<Class<?>> getIdentifyingTypes() {
return List.of(RedisRepository.class, KeyValueRepository.class);
}

@Override
public void registerBeansForRoot(BeanDefinitionRegistry registry, RepositoryConfigurationSource configuration) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* @author Christoph Strobl
* @author Oliver Gierke
* @author Mark Paluch
* @author Junghoon Ban
* @since 1.7
*/
public class RedisRepositoryFactory extends KeyValueRepositoryFactory {
Expand Down Expand Up @@ -75,6 +76,11 @@ public RedisRepositoryFactory(KeyValueOperations keyValueOperations,
this.operations = keyValueOperations;
}

@Override
protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
return SimpleRedisRepository.class;
}

@Override
protected RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata) {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.springframework.data.redis.repository.support;

import org.springframework.data.keyvalue.core.KeyValueOperations;
import org.springframework.data.keyvalue.repository.support.SimpleKeyValueRepository;
import org.springframework.data.redis.repository.RedisRepository;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.core.EntityInformation;

/**
* Redis specific repository implementation.
*
* @author Junghoon Ban
* @param <T>
* @param <ID>
*/
@NoRepositoryBean
public class SimpleRedisRepository<T, ID> extends SimpleKeyValueRepository<T, ID> implements RedisRepository<T, ID> {

public SimpleRedisRepository(EntityInformation<T, ID> metadata, KeyValueOperations operations) {
super(metadata, operations);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.Collection;

import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry;
Expand All @@ -33,6 +32,7 @@
import org.springframework.data.keyvalue.repository.KeyValueRepository;
import org.springframework.data.redis.core.RedisHash;
import org.springframework.data.redis.core.RedisKeyValueAdapter.EnableKeyspaceEvents;
import org.springframework.data.redis.repository.RedisRepository;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource;
import org.springframework.data.repository.config.RepositoryConfiguration;
Expand Down Expand Up @@ -65,6 +65,12 @@ void isStrictMatchIfRepositoryExtendsStoreSpecificBase() {
assertHasRepo(StoreRepository.class, extension.getRepositoryConfigurations(configurationSource, loader, true));
}

@Test // GH-2816
void isStrictMatchIfRepositoryExtendsKeyValueSpecificBase() {
assertHasRepo(KeyValueSpecificRepository.class,
extension.getRepositoryConfigurations(configurationSource, loader, true));
}

@Test // DATAREDIS-425
void isNotStrictMatchIfDomainTypeIsNotAnnotatedWithDocument() {

Expand Down Expand Up @@ -197,5 +203,8 @@ interface SampleRepository extends Repository<Sample, Long> {}

interface UnannotatedRepository extends Repository<Object, Long> {}

interface StoreRepository extends KeyValueRepository<Object, Long> {}
interface StoreRepository extends RedisRepository<Object, Long> {}

interface KeyValueSpecificRepository extends KeyValueRepository<Object, Long> {}

}