Skip to content

Commit b9fa290

Browse files
committed
Polishing.
Use consistently domain type instead of introducing a new terminology to repository infrastructure. Rename Kotlin variant of ParameterUnitTests to KParameterUnitTests to avoid duplicate classes. See #2770 Original pull request: #2771
1 parent b775b6d commit b9fa290

File tree

6 files changed

+31
-38
lines changed

6 files changed

+31
-38
lines changed

src/main/java/org/springframework/data/repository/query/DefaultParameters.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ public final class DefaultParameters extends Parameters<DefaultParameters, Param
3131
* Creates a new {@link DefaultParameters} instance from the given {@link Method}.
3232
*
3333
* @param method must not be {@literal null}.
34-
* @deprecated since 3.1, use {@link #DefaultParameters(Method, TypeInformation)} instead.
3534
*/
36-
@Deprecated(since = "3.1", forRemoval = true)
3735
public DefaultParameters(Method method) {
3836
super(method);
3937
}

src/main/java/org/springframework/data/repository/query/Parameter.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,27 +71,26 @@ public class Parameter {
7171
* Creates a new {@link Parameter} for the given {@link MethodParameter}.
7272
*
7373
* @param parameter must not be {@literal null}.
74-
* @deprecated since 3.1, use {@link #Parameter(MethodParameter, TypeInformation)} instead.
7574
*/
76-
@Deprecated(since = "3.1", forRemoval = true)
7775
protected Parameter(MethodParameter parameter) {
7876
this(parameter, TypeInformation.of(Parameter.class));
7977
}
8078

8179
/**
82-
* Creates a new {@link Parameter} for the given {@link MethodParameter} and aggregate {@link TypeInformation}.
80+
* Creates a new {@link Parameter} for the given {@link MethodParameter} and domain {@link TypeInformation}.
8381
*
8482
* @param parameter must not be {@literal null}.
85-
* @param aggregateType must not be {@literal null}.
83+
* @param domainType must not be {@literal null}.
84+
* @since 3.0.2
8685
*/
87-
protected Parameter(MethodParameter parameter, TypeInformation<?> aggregateType) {
86+
protected Parameter(MethodParameter parameter, TypeInformation<?> domainType) {
8887

8988
Assert.notNull(parameter, "MethodParameter must not be null");
90-
Assert.notNull(aggregateType, "TypeInformation must not be null!");
89+
Assert.notNull(domainType, "TypeInformation must not be null!");
9190

9291
this.parameter = parameter;
9392
this.parameterType = potentiallyUnwrapParameterType(parameter);
94-
this.isDynamicProjectionParameter = isDynamicProjectionParameter(parameter, aggregateType);
93+
this.isDynamicProjectionParameter = isDynamicProjectionParameter(parameter, domainType);
9594
this.name = isSpecialParameterType(parameter.getParameterType()) ? Lazy.of(Optional.empty()) : Lazy.of(() -> {
9695
Param annotation = parameter.getParameterAnnotation(Param.class);
9796
return Optional.ofNullable(annotation == null ? parameter.getParameterName() : annotation.value());
@@ -218,10 +217,10 @@ boolean isSort() {
218217
* </code>
219218
*
220219
* @param parameter must not be {@literal null}.
221-
* @param aggregateType the reference aggregate type, must not be {@literal null}.
220+
* @param domainType the reference domain type, must not be {@literal null}.
222221
* @return
223222
*/
224-
private static boolean isDynamicProjectionParameter(MethodParameter parameter, TypeInformation<?> aggregateType) {
223+
private static boolean isDynamicProjectionParameter(MethodParameter parameter, TypeInformation<?> domainType) {
225224

226225
if (!parameter.getParameterType().equals(Class.class)) {
227226
return false;
@@ -241,7 +240,7 @@ private static boolean isDynamicProjectionParameter(MethodParameter parameter, T
241240
var unwrapped = QueryExecutionConverters.unwrapWrapperTypes(returnType);
242241
var reactiveUnwrapped = ReactiveWrapperConverters.unwrapWrapperTypes(unwrapped);
243242

244-
if (aggregateType.isAssignableFrom(reactiveUnwrapped)) {
243+
if (domainType.isAssignableFrom(reactiveUnwrapped)) {
245244
return false;
246245
}
247246

src/main/java/org/springframework/data/repository/query/Parameters.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,8 @@ public abstract class Parameters<S extends Parameters<S, T>, T extends Parameter
6363
* Creates a new instance of {@link Parameters}.
6464
*
6565
* @param method must not be {@literal null}.
66-
* @deprecated since 3.1, use {@link #Parameters(Method, Function)} instead.
6766
*/
6867
@SuppressWarnings("null")
69-
@Deprecated(since = "3.1", forRemoval = true)
7068
public Parameters(Method method) {
7169
this(method, null);
7270
}
@@ -77,6 +75,7 @@ public Parameters(Method method) {
7775
*
7876
* @param method must not be {@literal null}.
7977
* @param parameterFactory must not be {@literal null}.
78+
* @since 3.0.2
8079
*/
8180
protected Parameters(Method method, Function<MethodParameter, T> parameterFactory) {
8281

@@ -176,10 +175,8 @@ private S getBindable() {
176175
*
177176
* @param parameter will never be {@literal null}.
178177
* @return
179-
* @deprecated since 3.1, in your extension, call {@link #Parameters(Method, ParameterFactory)} instead.
180178
*/
181179
@SuppressWarnings("unchecked")
182-
@Deprecated(since = "3.1", forRemoval = true)
183180
protected T createParameter(MethodParameter parameter) {
184181
return (T) new Parameter(parameter);
185182
}

src/main/java/org/springframework/data/repository/query/QueryMethod.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,10 @@ public QueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory
6969
Assert.notNull(metadata, "Repository metadata must not be null");
7070
Assert.notNull(factory, "ProjectionFactory must not be null");
7171

72-
Parameters.TYPES.stream()
73-
.filter(type -> getNumberOfOccurrences(method, type) > 1)
74-
.findFirst().ifPresent(type -> {
75-
throw new IllegalStateException(
76-
String.format("Method must have only one argument of type %s; Offending method: %s",
77-
type.getSimpleName(), method));
72+
Parameters.TYPES.stream() //
73+
.filter(type -> getNumberOfOccurrences(method, type) > 1).findFirst().ifPresent(type -> {
74+
throw new IllegalStateException(String.format(
75+
"Method must have only one argument of type %s; Offending method: %s", type.getSimpleName(), method));
7876
});
7977

8078
this.method = method;
@@ -121,9 +119,7 @@ public QueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory
121119
*
122120
* @param method must not be {@literal null}.
123121
* @return must not return {@literal null}.
124-
* @deprecated since 3.1, call or override {@link #createParameters(Method, TypeInformation)} instead.
125122
*/
126-
@Deprecated(since = "3.1", forRemoval = true)
127123
protected Parameters<?, ?> createParameters(Method method) {
128124
return createParameters(method, metadata.getDomainTypeInformation());
129125
}
@@ -132,11 +128,12 @@ public QueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory
132128
* Creates a {@link Parameters} instance.
133129
*
134130
* @param method must not be {@literal null}.
135-
* @param aggregateType must not be {@literal null}.
131+
* @param domainType must not be {@literal null}.
136132
* @return must not return {@literal null}.
133+
* @since 3.0.2
137134
*/
138-
protected Parameters<?, ?> createParameters(Method method, TypeInformation<?> aggregateType) {
139-
return new DefaultParameters(method, aggregateType);
135+
protected Parameters<?, ?> createParameters(Method method, TypeInformation<?> domainType) {
136+
return new DefaultParameters(method, domainType);
140137
}
141138

142139
/**

src/test/java/org/springframework/data/repository/query/ParameterUnitTests.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Collections;
2121
import java.util.List;
2222
import java.util.Optional;
23+
import java.util.function.Function;
2324
import java.util.stream.Stream;
2425

2526
import org.jetbrains.annotations.NotNull;
@@ -34,6 +35,7 @@
3435
* Unit tests for {@link Parameter}.
3536
*
3637
* @author Jens Schauder
38+
* @author Oliver Drotbohm
3739
*/
3840
class ParameterUnitTests {
3941

@@ -69,9 +71,9 @@ Stream<DynamicTest> doesNotConsiderClassParametersDynamicProjectionOnes() {
6971
"staticReturnNonDynamicBindWildcard", //
7072
"staticReturnNonDynamicBindWildcardExtends");
7173

72-
return DynamicTest.stream(methods, it -> it, it -> {
73-
assertThat(new Parameter(getMethodParameter(it), TypeInformation.of(User.class))
74-
.isDynamicProjectionParameter()).isFalse();
74+
return DynamicTest.stream(methods, Function.identity(), it -> {
75+
Parameter parameter = new Parameter(getMethodParameter(it), TypeInformation.of(User.class));
76+
assertThat(parameter.isDynamicProjectionParameter()).isFalse();
7577
});
7678
}
7779

src/test/kotlin/org/springframework/data/repository/query/ParameterUnitTests.kt renamed to src/test/kotlin/org/springframework/data/repository/query/KParameterUnitTests.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ import kotlin.reflect.jvm.javaMethod
2626
*
2727
* @author Mark Paluch
2828
*/
29-
class ParameterUnitTests {
29+
class KParameterUnitTests {
3030

31-
@Test // DATACMNS-1508
32-
fun `should consider Continuation a special parameter`() {
31+
@Test // DATACMNS-1508
32+
fun `should consider Continuation a special parameter`() {
3333

34-
val methodParameter =
35-
MethodParameter(MyCoroutineRepository::hello.javaMethod!!, 0)
36-
methodParameter.initParameterNameDiscovery(DefaultParameterNameDiscoverer())
37-
val parameter = Parameter(methodParameter)
34+
val methodParameter =
35+
MethodParameter(MyCoroutineRepository::hello.javaMethod!!, 0)
36+
methodParameter.initParameterNameDiscovery(DefaultParameterNameDiscoverer())
37+
val parameter = Parameter(methodParameter)
3838

39-
assertThat(parameter.name).isEmpty()
39+
assertThat(parameter.name).isEmpty()
4040
assertThat(parameter.isBindable).isFalse()
4141
}
4242

0 commit comments

Comments
 (0)