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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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}. * Resolves the criteria object from given {@link KeyValueQuery}.
* *
* @author Christoph Strobl * @author Christoph Strobl
* @param <T> * @param <T>
*/ */
public interface CriteriaAccessor<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. * transformation to match the desired type.
* *
* @param query can be {@literal null}. * @param query can be {@literal null}.
* @return the criteria extracted from the query. * @return the criteria extracted from the query.
* @throws IllegalArgumentException in case the criteria is not valid for usage with specific {@link CriteriaAccessor} * @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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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. * {@link CriteriaAccessor} implementation capable of {@link SpelExpression}s.
* *
* @author Christoph Strobl * @author Christoph Strobl
* @author Oliver Gierke * @author Oliver Gierke
*/ */
@@ -32,7 +32,7 @@ class SpelCriteriaAccessor implements CriteriaAccessor<SpelCriteria> {
/** /**
* Creates a new {@link SpelCriteriaAccessor} using the given {@link SpelExpressionParser}. * Creates a new {@link SpelCriteriaAccessor} using the given {@link SpelExpressionParser}.
* *
* @param parser must not be {@literal null}. * @param parser must not be {@literal null}.
*/ */
public SpelCriteriaAccessor(SpelExpressionParser parser) { public SpelCriteriaAccessor(SpelExpressionParser parser) {
@@ -49,22 +49,22 @@ class SpelCriteriaAccessor implements CriteriaAccessor<SpelCriteria> {
@Override @Override
public SpelCriteria resolve(KeyValueQuery<?> query) { public SpelCriteria resolve(KeyValueQuery<?> query) {
if (query.getCritieria() == null) { if (query.getCriteria() == null) {
return null; return null;
} }
if (query.getCritieria() instanceof SpelExpression) { if (query.getCriteria() instanceof SpelExpression) {
return new SpelCriteria((SpelExpression) query.getCritieria()); return new SpelCriteria((SpelExpression) query.getCriteria());
} }
if (query.getCritieria() instanceof String) { if (query.getCriteria() instanceof String) {
return new SpelCriteria(parser.parseRaw((String) query.getCritieria())); return new SpelCriteria(parser.parseRaw((String) query.getCriteria()));
} }
if (query.getCritieria() instanceof SpelCriteria) { if (query.getCriteria() instanceof SpelCriteria) {
return (SpelCriteria) query.getCritieria(); 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. * Creates new instance of {@link KeyValueQuery} with given criteria.
* *
* @param criteria can be {@literal null}. * @param criteria can be {@literal null}.
*/ */
public KeyValueQuery(T criteria) { public KeyValueQuery(T criteria) {
@@ -44,7 +44,7 @@ public class KeyValueQuery<T> {
/** /**
* Creates new instance of {@link KeyValueQuery} with given {@link Sort}. * Creates new instance of {@link KeyValueQuery} with given {@link Sort}.
* *
* @param sort can be {@literal null}. * @param sort can be {@literal null}.
*/ */
public KeyValueQuery(Sort sort) { public KeyValueQuery(Sort sort) {
@@ -53,16 +53,28 @@ public class KeyValueQuery<T> {
/** /**
* Get the criteria object. * Get the criteria object.
* *
* @return * @return
* @deprecated will be removed in favor of {@link #getCriteria()}.
*/ */
@Deprecated
public T getCritieria() { public T getCritieria() {
return criteria; return criteria;
} }
/**
* Get the criteria object.
*
* @return
* @since 1.2.4
*/
public T getCriteria() {
return criteria;
}
/** /**
* Get {@link Sort}. * Get {@link Sort}.
* *
* @return * @return
*/ */
public Sort getSort() { public Sort getSort() {
@@ -71,7 +83,7 @@ public class KeyValueQuery<T> {
/** /**
* Number of elements to skip. * Number of elements to skip.
* *
* @return negative value if not set. * @return negative value if not set.
*/ */
public int getOffset() { public int getOffset() {
@@ -80,7 +92,7 @@ public class KeyValueQuery<T> {
/** /**
* Number of elements to read. * Number of elements to read.
* *
* @return negative value if not set. * @return negative value if not set.
*/ */
public int getRows() { public int getRows() {
@@ -89,7 +101,7 @@ public class KeyValueQuery<T> {
/** /**
* Set the number of elements to skip. * Set the number of elements to skip.
* *
* @param offset use negative value for none. * @param offset use negative value for none.
*/ */
public void setOffset(int offset) { public void setOffset(int offset) {
@@ -98,8 +110,8 @@ public class KeyValueQuery<T> {
/** /**
* Set the number of elements to read. * 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) { public void setRows(int rows) {
this.rows = rows; this.rows = rows;
@@ -107,7 +119,7 @@ public class KeyValueQuery<T> {
/** /**
* Set {@link Sort} to be applied. * Set {@link Sort} to be applied.
* *
* @param sort * @param sort
*/ */
public void setSort(Sort sort) { public void setSort(Sort sort) {
@@ -116,7 +128,7 @@ public class KeyValueQuery<T> {
/** /**
* Add given {@link Sort}. * Add given {@link Sort}.
* *
* @param sort {@literal null} {@link Sort} will be ignored. * @param sort {@literal null} {@link Sort} will be ignored.
* @return * @return
*/ */

View File

@@ -135,7 +135,7 @@ public class KeyValuePartTreeQuery implements RepositoryQuery {
ParametersParameterAccessor accessor = new ParametersParameterAccessor(getQueryMethod().getParameters(), ParametersParameterAccessor accessor = new ParametersParameterAccessor(getQueryMethod().getParameters(),
parameters); parameters);
Object criteria = instance.getCritieria(); Object criteria = instance.getCriteria();
if (criteria instanceof SpelCriteria || criteria instanceof SpelExpression) { 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)); verify(adapterMock, times(1)).find(captor.capture(), eq(Foo.class.getName()), eq(Foo.class));
assertThat(captor.getValue().getOffset(), is(1)); assertThat(captor.getValue().getOffset(), is(1));
assertThat(captor.getValue().getRows(), is(5)); assertThat(captor.getValue().getRows(), is(5));
assertThat(captor.getValue().getCritieria(), nullValue()); assertThat(captor.getValue().getCriteria(), nullValue());
} }
@Test // DATACMNS-525 @Test // DATACMNS-525

View File

@@ -99,7 +99,7 @@ public class SpelQueryEngineUnitTests {
SpelQueryCreator creator = new SpelQueryCreator(partTree, new ParametersParameterAccessor(new QueryMethod(method, SpelQueryCreator creator = new SpelQueryCreator(partTree, new ParametersParameterAccessor(new QueryMethod(method,
metadata, new SpelAwareProxyProjectionFactory()).getParameters(), args)); 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 { static interface PersonRepository {

View File

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

View File

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

View File

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