Switch default to Predicate-based QueryEngine.

See: #565
This commit is contained in:
Christoph Strobl
2024-03-08 09:38:19 +01:00
parent 805849254d
commit 8cb65ec099
5 changed files with 15 additions and 10 deletions

View File

@@ -46,7 +46,7 @@ public abstract class AbstractKeyValueAdapter implements KeyValueAdapter {
* @since 3.1.10
*/
protected AbstractKeyValueAdapter(SortAccessor<Comparator<?>> sortAccessor) {
this(new SpelQueryEngine(sortAccessor));
this(new PredicateQueryEngine(sortAccessor));
}
/**
@@ -56,7 +56,7 @@ public abstract class AbstractKeyValueAdapter implements KeyValueAdapter {
*/
protected AbstractKeyValueAdapter(@Nullable QueryEngine<? extends KeyValueAdapter, ?, ?> engine) {
this.engine = engine != null ? engine : new SpelQueryEngine();
this.engine = engine != null ? engine : new PredicateQueryEngine();
this.engine.registerAdapter(this);
}

View File

@@ -26,7 +26,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.keyvalue.core.KeyValueOperations;
import org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery;
import org.springframework.data.keyvalue.repository.query.SpelQueryCreator;
import org.springframework.data.keyvalue.repository.query.PredicateQueryCreator;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.projection.ProjectionFactory;
@@ -58,7 +58,7 @@ import org.springframework.util.ClassUtils;
*/
public class KeyValueRepositoryFactory extends RepositoryFactorySupport {
private static final Class<SpelQueryCreator> DEFAULT_QUERY_CREATOR = SpelQueryCreator.class;
private static final Class<PredicateQueryCreator> DEFAULT_QUERY_CREATOR = PredicateQueryCreator.class;
private final KeyValueOperations keyValueOperations;
private final MappingContext<?, ?> context;

View File

@@ -32,8 +32,8 @@ import org.springframework.data.keyvalue.core.KeyValueOperations;
import org.springframework.data.keyvalue.core.KeyValueTemplate;
import org.springframework.data.keyvalue.core.SortAccessor;
import org.springframework.data.keyvalue.repository.config.QueryCreatorType;
import org.springframework.data.keyvalue.repository.query.CachingKeyValuePartTreeQuery;
import org.springframework.data.keyvalue.repository.query.SpelQueryCreator;
import org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery;
import org.springframework.data.keyvalue.repository.query.PredicateQueryCreator;
import org.springframework.data.keyvalue.repository.support.KeyValueRepositoryFactoryBean;
import org.springframework.data.repository.config.DefaultRepositoryBaseClass;
import org.springframework.data.repository.query.QueryLookupStrategy;
@@ -51,7 +51,7 @@ import org.springframework.data.repository.query.QueryLookupStrategy.Key;
@Documented
@Inherited
@Import(MapRepositoriesRegistrar.class)
@QueryCreatorType(value = SpelQueryCreator.class, repositoryQueryType = CachingKeyValuePartTreeQuery.class)
@QueryCreatorType(value = PredicateQueryCreator.class, repositoryQueryType = KeyValuePartTreeQuery.class)
public @interface EnableMapRepositories {
/**

View File

@@ -23,6 +23,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.List;
import java.util.function.Predicate;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -48,7 +49,8 @@ class KeyValueTemplateTests {
private static final Bar BAR_ONE = new Bar("one");
private static final ClassWithTypeAlias ALIASED = new ClassWithTypeAlias("super");
private static final SubclassOfAliasedType SUBCLASS_OF_ALIASED = new SubclassOfAliasedType("sub");
private static final KeyValueQuery<String> STRING_QUERY = new KeyValueQuery<>("foo == 'two'");
private static final KeyValueQuery<Predicate<Foo>> STRING_QUERY = new KeyValueQuery<>((Predicate<Foo>) foo -> foo.getFoo().equals("two"));
private KeyValueTemplate operations;

View File

@@ -15,23 +15,26 @@
*/
package org.springframework.data.map;
import org.junit.jupiter.api.Disabled;
import org.springframework.data.keyvalue.core.KeyValueOperations;
import org.springframework.data.keyvalue.repository.query.CachingKeyValuePartTreeQuery;
import org.springframework.data.keyvalue.repository.query.PredicateQueryCreator;
import org.springframework.data.keyvalue.repository.query.SpelQueryCreator;
import org.springframework.data.keyvalue.repository.support.KeyValueRepositoryFactory;
import org.springframework.data.keyvalue.repository.support.SimpleKeyValueRepository;
/**
* Unit tests for {@link SimpleKeyValueRepository} using {@link CachingKeyValuePartTreeQuery} and
* {@link SpelQueryCreator}.
* {@link PredicateQueryCreator}.
*
* @author Mark Paluch
* @author Christoph Strobl
*/
@Disabled
public class CachingQuerySimpleKeyValueRepositoryUnitTests extends SimpleKeyValueRepositoryUnitTests {
@Override
protected KeyValueRepositoryFactory createKeyValueRepositoryFactory(KeyValueOperations operations) {
return new KeyValueRepositoryFactory(operations, SpelQueryCreator.class, CachingKeyValuePartTreeQuery.class);
return new KeyValueRepositoryFactory(operations, PredicateQueryCreator.class, CachingKeyValuePartTreeQuery.class);
}
}