Skip to content

Commit 11829bb

Browse files
committed
DATAMONGO-2138 - GenericQuery wraps Query with type parameter
TypedQuery needs to carry the entity type in a generic type parameter. Giving Query a type parameter would break backwards compatibility. Solution: Both Query and TypedQuery will implement GenericQuery.
1 parent 9a0dad1 commit 11829bb

File tree

2 files changed

+33
-1
lines changed
  • spring-data-mongodb/src/main

2 files changed

+33
-1
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Query.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
* @author Christoph Strobl
4747
* @author Mark Paluch
4848
*/
49-
public class Query {
49+
public class Query implements GenericQuery {
5050

5151
private static final String RESTRICTED_TYPES_KEY = "_$RESTRICTED_TYPES";
5252

@@ -475,6 +475,11 @@ protected List<CriteriaDefinition> getCriteria() {
475475
return new ArrayList<>(this.criteria.values());
476476
}
477477

478+
@Override
479+
public Query getQuery() {
480+
return this;
481+
}
482+
478483
/*
479484
* (non-Javadoc)
480485
* @see java.lang.Object#toString()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2010-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.mongodb.core.query
17+
18+
/**
19+
* Wraps [Query] with type parameter.
20+
*
21+
* @param T Type of Entity that is queried, used for type-safe queries.
22+
*
23+
* @author Tjeu Kayim
24+
*/
25+
interface GenericQuery<in T : Any> {
26+
val query: Query
27+
}

0 commit comments

Comments
 (0)