DATAKV-170 - Fix KeyValue.getCriteria() method name.

Introduce KeyValue.getCriteria() method and deprecate KeyValue.getCritieria() for later removal. Use fixed method in affected classes.
This commit is contained in:
Mark Paluch
2017-04-20 13:03:53 +02:00
parent bb56ff7d40
commit 0fe1083da4
9 changed files with 50 additions and 38 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,16 +19,16 @@ import org.springframework.data.keyvalue.core.query.KeyValueQuery;
/**
* Resolves the criteria object from given {@link KeyValueQuery}.
*
*
* @author Christoph Strobl
* @param <T>
*/
public interface CriteriaAccessor<T> {
/**
* Checks and reads {@link KeyValueQuery#getCritieria()} of given {@link KeyValueQuery}. Might also apply additional
* Checks and reads {@link KeyValueQuery#getCriteria()} of given {@link KeyValueQuery}. Might also apply additional
* transformation to match the desired type.
*
*
* @param query can be {@literal null}.
* @return the criteria extracted from the query.
* @throws IllegalArgumentException in case the criteria is not valid for usage with specific {@link CriteriaAccessor}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@ import org.springframework.util.Assert;
/**
* {@link CriteriaAccessor} implementation capable of {@link SpelExpression}s.
*
*
* @author Christoph Strobl
* @author Oliver Gierke
*/
@@ -32,7 +32,7 @@ class SpelCriteriaAccessor implements CriteriaAccessor<SpelCriteria> {
/**
* Creates a new {@link SpelCriteriaAccessor} using the given {@link SpelExpressionParser}.
*
*
* @param parser must not be {@literal null}.
*/
public SpelCriteriaAccessor(SpelExpressionParser parser) {
@@ -49,22 +49,22 @@ class SpelCriteriaAccessor implements CriteriaAccessor<SpelCriteria> {
@Override
public SpelCriteria resolve(KeyValueQuery<?> query) {
if (query.getCritieria() == null) {
if (query.getCriteria() == null) {
return null;
}
if (query.getCritieria() instanceof SpelExpression) {
return new SpelCriteria((SpelExpression) query.getCritieria());
if (query.getCriteria() instanceof SpelExpression) {
return new SpelCriteria((SpelExpression) query.getCriteria());
}
if (query.getCritieria() instanceof String) {
return new SpelCriteria(parser.parseRaw((String) query.getCritieria()));
if (query.getCriteria() instanceof String) {
return new SpelCriteria(parser.parseRaw((String) query.getCriteria()));
}
if (query.getCritieria() instanceof SpelCriteria) {
return (SpelCriteria) query.getCritieria();
if (query.getCriteria() instanceof SpelCriteria) {
return (SpelCriteria) query.getCriteria();
}
throw new IllegalArgumentException("Cannot create SpelCriteria for " + query.getCritieria());
throw new IllegalArgumentException("Cannot create SpelCriteria for " + query.getCriteria());
}
}

View File

@@ -35,7 +35,7 @@ public class KeyValueQuery<T> {
/**
* Creates new instance of {@link KeyValueQuery} with given criteria.
*
*
* @param criteria can be {@literal null}.
*/
public KeyValueQuery(T criteria) {
@@ -44,7 +44,7 @@ public class KeyValueQuery<T> {
/**
* Creates new instance of {@link KeyValueQuery} with given {@link Sort}.
*
*
* @param sort can be {@literal null}.
*/
public KeyValueQuery(Sort sort) {
@@ -53,16 +53,28 @@ public class KeyValueQuery<T> {
/**
* Get the criteria object.
*
*
* @return
* @deprecated will be removed in favor of {@link #getCriteria()}.
*/
@Deprecated
public T getCritieria() {
return criteria;
}
/**
* Get the criteria object.
*
* @return
* @since 1.2.4
*/
public T getCriteria() {
return criteria;
}
/**
* Get {@link Sort}.
*
*
* @return
*/
public Sort getSort() {
@@ -71,7 +83,7 @@ public class KeyValueQuery<T> {
/**
* Number of elements to skip.
*
*
* @return negative value if not set.
*/
public int getOffset() {
@@ -80,7 +92,7 @@ public class KeyValueQuery<T> {
/**
* Number of elements to read.
*
*
* @return negative value if not set.
*/
public int getRows() {
@@ -89,7 +101,7 @@ public class KeyValueQuery<T> {
/**
* Set the number of elements to skip.
*
*
* @param offset use negative value for none.
*/
public void setOffset(int offset) {
@@ -98,8 +110,8 @@ public class KeyValueQuery<T> {
/**
* Set the number of elements to read.
*
* @param offset use negative value for all.
*
* @param rows use negative value for all.
*/
public void setRows(int rows) {
this.rows = rows;
@@ -107,7 +119,7 @@ public class KeyValueQuery<T> {
/**
* Set {@link Sort} to be applied.
*
*
* @param sort
*/
public void setSort(Sort sort) {
@@ -116,7 +128,7 @@ public class KeyValueQuery<T> {
/**
* Add given {@link Sort}.
*
*
* @param sort {@literal null} {@link Sort} will be ignored.
* @return
*/

View File

@@ -135,7 +135,7 @@ public class KeyValuePartTreeQuery implements RepositoryQuery {
ParametersParameterAccessor accessor = new ParametersParameterAccessor(getQueryMethod().getParameters(),
parameters);
Object criteria = instance.getCritieria();
Object criteria = instance.getCriteria();
if (criteria instanceof SpelCriteria || criteria instanceof SpelExpression) {

View File

@@ -216,7 +216,7 @@ public class KeyValueTemplateUnitTests {
verify(adapterMock, times(1)).find(captor.capture(), eq(Foo.class.getName()), eq(Foo.class));
assertThat(captor.getValue().getOffset(), is(1));
assertThat(captor.getValue().getRows(), is(5));
assertThat(captor.getValue().getCritieria(), nullValue());
assertThat(captor.getValue().getCriteria(), nullValue());
}
@Test // DATACMNS-525

View File

@@ -99,7 +99,7 @@ public class SpelQueryEngineUnitTests {
SpelQueryCreator creator = new SpelQueryCreator(partTree, new ParametersParameterAccessor(new QueryMethod(method,
metadata, new SpelAwareProxyProjectionFactory()).getParameters(), args));
return new SpelCriteria(creator.createQuery().getCritieria(), new StandardEvaluationContext(args));
return new SpelCriteria(creator.createQuery().getCriteria(), new StandardEvaluationContext(args));
}
static interface PersonRepository {

View File

@@ -68,8 +68,8 @@ public class CachingKeyValuePartTreeQueryUnitTests {
Object[] args = new Object[] { "foo" };
SpelCriteria first = (SpelCriteria) query.prepareQuery(args).getCritieria();
SpelCriteria second = (SpelCriteria) query.prepareQuery(args).getCritieria();
SpelCriteria first = (SpelCriteria) query.prepareQuery(args).getCriteria();
SpelCriteria second = (SpelCriteria) query.prepareQuery(args).getCriteria();
assertThat(first.getExpression(), sameInstance(second.getExpression()));
assertThat(first.getContext(), not(sameInstance(second.getContext())));

View File

@@ -67,8 +67,8 @@ public class KeyValuePartTreeQueryUnitTests {
Object[] args = new Object[] { "foo" };
Object first = query.prepareQuery(args).getCritieria();
Object second = query.prepareQuery(args).getCritieria();
Object first = query.prepareQuery(args).getCriteria();
Object second = query.prepareQuery(args).getCriteria();
assertThat(first, not(sameInstance(second)));
}
@@ -124,9 +124,9 @@ public class KeyValuePartTreeQueryUnitTests {
KeyValueQuery<?> query = partTreeQuery.prepareQuery(new Object[] { "firstname" });
assertThat(query.getCritieria(), is(notNullValue()));
assertThat(query.getCritieria(), IsInstanceOf.instanceOf(SpelCriteria.class));
assertThat(((SpelCriteria) query.getCritieria()).getExpression().getExpressionString(),
assertThat(query.getCriteria(), is(notNullValue()));
assertThat(query.getCriteria(), IsInstanceOf.instanceOf(SpelCriteria.class));
assertThat(((SpelCriteria) query.getCriteria()).getExpression().getExpressionString(),
is("#it?.firstname?.equals([0])"));
assertThat(query.getRows(), is(3));
}

View File

@@ -307,7 +307,7 @@ public class SpelQueryCreatorUnitTests {
}
private Evaluation evaluate(String methodName, Object... args) throws Exception {
return new Evaluation((SpelExpression) createQueryForMethodWithArgs(methodName, args).getCritieria());
return new Evaluation((SpelExpression) createQueryForMethodWithArgs(methodName, args).getCriteria());
}
private KeyValueQuery<SpelExpression> createQueryForMethodWithArgs(String methodName, Object... args)
@@ -329,7 +329,7 @@ public class SpelQueryCreatorUnitTests {
new QueryMethod(method, metadataMock, new SpelAwareProxyProjectionFactory()).getParameters(), args));
KeyValueQuery<SpelExpression> q = creator.createQuery();
q.getCritieria().setEvaluationContext(new StandardEvaluationContext(args));
q.getCriteria().setEvaluationContext(new StandardEvaluationContext(args));
return q;
}