From 0fe1083da4ca7e75db2dccaf76e44c2f52ec2b1e Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Thu, 20 Apr 2017 13:03:53 +0200 Subject: [PATCH] DATAKV-170 - Fix KeyValue.getCriteria() method name. Introduce KeyValue.getCriteria() method and deprecate KeyValue.getCritieria() for later removal. Use fixed method in affected classes. --- .../data/keyvalue/core/CriteriaAccessor.java | 8 ++--- .../keyvalue/core/SpelCriteriaAccessor.java | 22 ++++++------ .../keyvalue/core/query/KeyValueQuery.java | 34 +++++++++++++------ .../query/KeyValuePartTreeQuery.java | 2 +- .../core/KeyValueTemplateUnitTests.java | 2 +- .../core/SpelQueryEngineUnitTests.java | 2 +- ...CachingKeyValuePartTreeQueryUnitTests.java | 4 +-- .../query/KeyValuePartTreeQueryUnitTests.java | 10 +++--- .../query/SpelQueryCreatorUnitTests.java | 4 +-- 9 files changed, 50 insertions(+), 38 deletions(-) diff --git a/src/main/java/org/springframework/data/keyvalue/core/CriteriaAccessor.java b/src/main/java/org/springframework/data/keyvalue/core/CriteriaAccessor.java index 389d65b..dd61ca8 100644 --- a/src/main/java/org/springframework/data/keyvalue/core/CriteriaAccessor.java +++ b/src/main/java/org/springframework/data/keyvalue/core/CriteriaAccessor.java @@ -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 */ public interface CriteriaAccessor { /** - * 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} diff --git a/src/main/java/org/springframework/data/keyvalue/core/SpelCriteriaAccessor.java b/src/main/java/org/springframework/data/keyvalue/core/SpelCriteriaAccessor.java index 710a6b2..66c9da6 100644 --- a/src/main/java/org/springframework/data/keyvalue/core/SpelCriteriaAccessor.java +++ b/src/main/java/org/springframework/data/keyvalue/core/SpelCriteriaAccessor.java @@ -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 { /** * 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 { @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()); } } diff --git a/src/main/java/org/springframework/data/keyvalue/core/query/KeyValueQuery.java b/src/main/java/org/springframework/data/keyvalue/core/query/KeyValueQuery.java index b032a62..f36679e 100644 --- a/src/main/java/org/springframework/data/keyvalue/core/query/KeyValueQuery.java +++ b/src/main/java/org/springframework/data/keyvalue/core/query/KeyValueQuery.java @@ -35,7 +35,7 @@ public class KeyValueQuery { /** * 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 { /** * 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 { /** * 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 { /** * Number of elements to skip. - * + * * @return negative value if not set. */ public int getOffset() { @@ -80,7 +92,7 @@ public class KeyValueQuery { /** * Number of elements to read. - * + * * @return negative value if not set. */ public int getRows() { @@ -89,7 +101,7 @@ public class KeyValueQuery { /** * 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 { /** * 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 { /** * Set {@link Sort} to be applied. - * + * * @param sort */ public void setSort(Sort sort) { @@ -116,7 +128,7 @@ public class KeyValueQuery { /** * Add given {@link Sort}. - * + * * @param sort {@literal null} {@link Sort} will be ignored. * @return */ diff --git a/src/main/java/org/springframework/data/keyvalue/repository/query/KeyValuePartTreeQuery.java b/src/main/java/org/springframework/data/keyvalue/repository/query/KeyValuePartTreeQuery.java index a28cdd6..bb2e752 100644 --- a/src/main/java/org/springframework/data/keyvalue/repository/query/KeyValuePartTreeQuery.java +++ b/src/main/java/org/springframework/data/keyvalue/repository/query/KeyValuePartTreeQuery.java @@ -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) { diff --git a/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateUnitTests.java b/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateUnitTests.java index bc7939a..7ed0906 100644 --- a/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateUnitTests.java +++ b/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateUnitTests.java @@ -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 diff --git a/src/test/java/org/springframework/data/keyvalue/core/SpelQueryEngineUnitTests.java b/src/test/java/org/springframework/data/keyvalue/core/SpelQueryEngineUnitTests.java index 9c0a873..4c394ce 100644 --- a/src/test/java/org/springframework/data/keyvalue/core/SpelQueryEngineUnitTests.java +++ b/src/test/java/org/springframework/data/keyvalue/core/SpelQueryEngineUnitTests.java @@ -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 { diff --git a/src/test/java/org/springframework/data/keyvalue/repository/query/CachingKeyValuePartTreeQueryUnitTests.java b/src/test/java/org/springframework/data/keyvalue/repository/query/CachingKeyValuePartTreeQueryUnitTests.java index 825f781..3aaf665 100644 --- a/src/test/java/org/springframework/data/keyvalue/repository/query/CachingKeyValuePartTreeQueryUnitTests.java +++ b/src/test/java/org/springframework/data/keyvalue/repository/query/CachingKeyValuePartTreeQueryUnitTests.java @@ -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()))); diff --git a/src/test/java/org/springframework/data/keyvalue/repository/query/KeyValuePartTreeQueryUnitTests.java b/src/test/java/org/springframework/data/keyvalue/repository/query/KeyValuePartTreeQueryUnitTests.java index 4c6c258..2ef480f 100644 --- a/src/test/java/org/springframework/data/keyvalue/repository/query/KeyValuePartTreeQueryUnitTests.java +++ b/src/test/java/org/springframework/data/keyvalue/repository/query/KeyValuePartTreeQueryUnitTests.java @@ -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)); } diff --git a/src/test/java/org/springframework/data/keyvalue/repository/query/SpelQueryCreatorUnitTests.java b/src/test/java/org/springframework/data/keyvalue/repository/query/SpelQueryCreatorUnitTests.java index 0154579..57aa308 100644 --- a/src/test/java/org/springframework/data/keyvalue/repository/query/SpelQueryCreatorUnitTests.java +++ b/src/test/java/org/springframework/data/keyvalue/repository/query/SpelQueryCreatorUnitTests.java @@ -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 createQueryForMethodWithArgs(String methodName, Object... args) @@ -329,7 +329,7 @@ public class SpelQueryCreatorUnitTests { new QueryMethod(method, metadataMock, new SpelAwareProxyProjectionFactory()).getParameters(), args)); KeyValueQuery q = creator.createQuery(); - q.getCritieria().setEvaluationContext(new StandardEvaluationContext(args)); + q.getCriteria().setEvaluationContext(new StandardEvaluationContext(args)); return q; }