DATAREDIS-425 - Adapted to changes in Spring Data KeyValue APIs.
Default query initialization changed to new, so we can delete some code here. Original Pull Request: #156
This commit is contained in:
@@ -16,26 +16,17 @@
|
||||
package org.springframework.data.redis.repository.support;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.data.keyvalue.core.KeyValueOperations;
|
||||
import org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery;
|
||||
import org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.QueryInitialization;
|
||||
import org.springframework.data.keyvalue.repository.support.KeyValueRepositoryFactory;
|
||||
import org.springframework.data.projection.ProjectionFactory;
|
||||
import org.springframework.data.redis.core.mapping.RedisPersistentEntity;
|
||||
import org.springframework.data.redis.repository.core.MappingRedisEntityInformation;
|
||||
import org.springframework.data.redis.repository.query.RedisQueryCreator;
|
||||
import org.springframework.data.repository.core.EntityInformation;
|
||||
import org.springframework.data.repository.core.NamedQueries;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
|
||||
import org.springframework.data.repository.query.EvaluationContextProvider;
|
||||
import org.springframework.data.repository.query.QueryLookupStrategy;
|
||||
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
|
||||
import org.springframework.data.repository.query.QueryMethod;
|
||||
import org.springframework.data.repository.query.RepositoryQuery;
|
||||
import org.springframework.data.repository.query.parser.AbstractQueryCreator;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link RepositoryFactorySupport} specific of handing Redis
|
||||
@@ -48,14 +39,13 @@ import org.springframework.util.Assert;
|
||||
public class RedisRepositoryFactory extends KeyValueRepositoryFactory {
|
||||
|
||||
private final KeyValueOperations operations;
|
||||
private final Class<? extends AbstractQueryCreator<?, ?>> queryCreator;
|
||||
|
||||
/**
|
||||
* @param keyValueOperations
|
||||
* @see KeyValueRepositoryFactory#KeyValueRepositoryFactory(KeyValueOperations)
|
||||
*/
|
||||
public RedisRepositoryFactory(KeyValueOperations keyValueOperations) {
|
||||
this(keyValueOperations, DEFAULT_QUERY_CREATOR);
|
||||
this(keyValueOperations, RedisQueryCreator.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,19 +55,20 @@ public class RedisRepositoryFactory extends KeyValueRepositoryFactory {
|
||||
*/
|
||||
public RedisRepositoryFactory(KeyValueOperations keyValueOperations,
|
||||
Class<? extends AbstractQueryCreator<?, ?>> queryCreator) {
|
||||
super(keyValueOperations, queryCreator);
|
||||
|
||||
this.operations = keyValueOperations;
|
||||
this.queryCreator = queryCreator;
|
||||
this(keyValueOperations, queryCreator, KeyValuePartTreeQuery.class);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.repository.support.KeyValueRepositoryFactory#getQueryLookupStrategy(org.springframework.data.repository.query.QueryLookupStrategy.Key, org.springframework.data.repository.query.EvaluationContextProvider)
|
||||
/**
|
||||
* @param keyValueOperations
|
||||
* @param queryCreator
|
||||
* @param repositoryQueryType
|
||||
* @see KeyValueRepositoryFactory#KeyValueRepositoryFactory(KeyValueOperations, Class, Class)
|
||||
*/
|
||||
@Override
|
||||
protected QueryLookupStrategy getQueryLookupStrategy(Key key, EvaluationContextProvider evaluationContextProvider) {
|
||||
return new RedisQueryLookupStrategy(key, evaluationContextProvider, operations, queryCreator);
|
||||
public RedisRepositoryFactory(KeyValueOperations keyValueOperations,
|
||||
Class<? extends AbstractQueryCreator<?, ?>> queryCreator, Class<? extends RepositoryQuery> repositoryQueryType) {
|
||||
super(keyValueOperations, queryCreator, repositoryQueryType);
|
||||
|
||||
this.operations = keyValueOperations;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -95,53 +86,4 @@ public class RedisRepositoryFactory extends KeyValueRepositoryFactory {
|
||||
|
||||
return entityInformation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @since 1.7
|
||||
*/
|
||||
private static class RedisQueryLookupStrategy implements QueryLookupStrategy {
|
||||
|
||||
private EvaluationContextProvider evaluationContextProvider;
|
||||
private KeyValueOperations keyValueOperations;
|
||||
|
||||
private Class<? extends AbstractQueryCreator<?, ?>> queryCreator;
|
||||
|
||||
/**
|
||||
* Creates a new {@link RedisQueryLookupStrategy} for the given {@link Key}, {@link EvaluationContextProvider},
|
||||
* {@link KeyValueOperations} and query creator type.
|
||||
* <p>
|
||||
*
|
||||
* @param key
|
||||
* @param evaluationContextProvider must not be {@literal null}.
|
||||
* @param keyValueOperations must not be {@literal null}.
|
||||
* @param queryCreator must not be {@literal null}.
|
||||
*/
|
||||
public RedisQueryLookupStrategy(Key key, EvaluationContextProvider evaluationContextProvider,
|
||||
KeyValueOperations keyValueOperations, Class<? extends AbstractQueryCreator<?, ?>> queryCreator) {
|
||||
|
||||
Assert.notNull(evaluationContextProvider, "EvaluationContextProvider must not be null!");
|
||||
Assert.notNull(keyValueOperations, "KeyValueOperations must not be null!");
|
||||
Assert.notNull(queryCreator, "Query creator type must not be null!");
|
||||
|
||||
this.evaluationContextProvider = evaluationContextProvider;
|
||||
this.keyValueOperations = keyValueOperations;
|
||||
this.queryCreator = queryCreator;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.QueryLookupStrategy#resolveQuery(java.lang.reflect.Method, org.springframework.data.repository.core.RepositoryMetadata, org.springframework.data.repository.core.NamedQueries)
|
||||
*/
|
||||
@Override
|
||||
public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory,
|
||||
NamedQueries namedQueries) {
|
||||
|
||||
QueryMethod queryMethod = new QueryMethod(method, metadata, factory);
|
||||
KeyValuePartTreeQuery partTreeQuery = new KeyValuePartTreeQuery(queryMethod, evaluationContextProvider,
|
||||
this.keyValueOperations, this.queryCreator);
|
||||
partTreeQuery.setQueryIntialization(QueryInitialization.NEW);
|
||||
return partTreeQuery;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.data.keyvalue.core.KeyValueOperations;
|
||||
import org.springframework.data.keyvalue.repository.support.KeyValueRepositoryFactoryBean;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.query.RepositoryQuery;
|
||||
import org.springframework.data.repository.query.parser.AbstractQueryCreator;
|
||||
|
||||
/**
|
||||
@@ -33,16 +34,16 @@ import org.springframework.data.repository.query.parser.AbstractQueryCreator;
|
||||
* @param <ID> The repository id type.
|
||||
* @since 1.7
|
||||
*/
|
||||
public class RedisRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable> extends
|
||||
KeyValueRepositoryFactoryBean<T, S, ID> {
|
||||
public class RedisRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable>
|
||||
extends KeyValueRepositoryFactoryBean<T, S, ID> {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.repository.support.KeyValueRepositoryFactoryBean#createRepositoryFactory(org.springframework.data.keyvalue.core.KeyValueOperations, java.lang.Class)
|
||||
* @see org.springframework.data.keyvalue.repository.support.KeyValueRepositoryFactoryBean#createRepositoryFactory(org.springframework.data.keyvalue.core.KeyValueOperations, java.lang.Class, java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
protected RedisRepositoryFactory createRepositoryFactory(KeyValueOperations operations,
|
||||
Class<? extends AbstractQueryCreator<?, ?>> queryCreator) {
|
||||
return new RedisRepositoryFactory(operations, queryCreator);
|
||||
Class<? extends AbstractQueryCreator<?, ?>> queryCreator, Class<? extends RepositoryQuery> repositoryQueryType) {
|
||||
return new RedisRepositoryFactory(operations, queryCreator, repositoryQueryType);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user