Skip to content

Commit ca643c9

Browse files
committed
Polishing.
Introduce refined names: EntityQuery, TemplatedQuery, ParametrizedQuery, QueryProvider. Return QueryProvider where possible. Introduce rewrite as concept on DeclaredQuery to retain its nature and track the origin of the query rewriting. Move methods solely used in tests to TestEntityQuery.
1 parent a2988e9 commit ca643c9

File tree

11 files changed

+149
-149
lines changed

11 files changed

+149
-149
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/AbstractStringBasedJpaQuery.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ public AbstractStringBasedJpaQuery(JpaQueryMethod method, EntityManager em, Stri
7878
this.valueExpressionDelegate = queryConfiguration.getValueExpressionDelegate();
7979
this.valueExpressionContextProvider = valueExpressionDelegate.createValueContextProvider(method.getParameters());
8080

81-
this.query = ExpressionQuery.create(queryString, method, queryConfiguration);
81+
this.query = TemplatedQuery.create(queryString, method, queryConfiguration);
8282

8383
this.countQuery = Lazy.of(() -> {
8484

8585
if (StringUtils.hasText(countQueryString)) {
86-
return ExpressionQuery.create(countQueryString, method, queryConfiguration);
86+
return TemplatedQuery.create(countQueryString, method, queryConfiguration);
8787
}
8888

8989
return this.query.deriveCountQuery(method.getCountQueryProjection());

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/StructuredQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* @since 4.0
2929
* @see EntityQuery
3030
* @see EntityQuery#create(DeclaredQuery, QueryEnhancerSelector)
31-
* @see ExpressionQuery#create(String, JpaQueryMethod, JpaQueryConfiguration)
31+
* @see TemplatedQuery#create(String, JpaQueryMethod, JpaQueryConfiguration)
3232
*/
3333
interface StructuredQuery extends QueryProvider {
3434

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/ExpressionQuery.java renamed to spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/TemplatedQuery.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.springframework.util.Assert;
2828

2929
/**
30-
* Extension of {@link DefaultEntityQuery} that evaluates the given query string as a SpEL template-expression.
30+
* Factory methods to obtain {@link EntityQuery} from a declared query using SpEL template-expressions.
3131
* <p>
3232
* Currently, the following template variables are available:
3333
* <ol>
@@ -41,7 +41,7 @@
4141
* @author Diego Krupitza
4242
* @author Greg Turnquist
4343
*/
44-
class ExpressionQuery {
44+
class TemplatedQuery {
4545

4646
private static final String EXPRESSION_PARAMETER = "$1#{";
4747
private static final String QUOTED_EXPRESSION_PARAMETER = "$1__HASH__{";

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/DefaultEntityQueryUnitTests.java

Lines changed: 58 additions & 58 deletions
Large diffs are not rendered by default.

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/JSqlParserQueryEnhancerUnitTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void setOperationListWorks() {
8282
+ "except \n" //
8383
+ "select SOME_COLUMN from SOME_OTHER_TABLE where REPORTING_DATE = :REPORTING_DATE";
8484

85-
DefaultEntityQuery query = new TestDefaultEntityQuery(setQuery, true);
85+
DefaultEntityQuery query = new TestEntityQuery(setQuery, true);
8686
QueryEnhancer queryEnhancer = QueryEnhancer.create(query);
8787

8888
assertThat(query.getAlias()).isNullOrEmpty();
@@ -105,7 +105,7 @@ void complexSetOperationListWorks() {
105105
+ "select SOME_COLUMN from SOME_OTHER_TABLE where REPORTING_DATE = :REPORTING_DATE \n" //
106106
+ "union select SOME_COLUMN from SOME_OTHER_OTHER_TABLE";
107107

108-
DefaultEntityQuery query = new TestDefaultEntityQuery(setQuery, true);
108+
DefaultEntityQuery query = new TestEntityQuery(setQuery, true);
109109
QueryEnhancer queryEnhancer = QueryEnhancerFactory.forQuery(query).create(query);
110110

111111
assertThat(query.getAlias()).isNullOrEmpty();
@@ -132,7 +132,7 @@ void deeplyNestedcomplexSetOperationListWorks() {
132132
+ "\tselect CustomerID from customers where country = 'Germany'\n"//
133133
+ "\t;";
134134

135-
DefaultEntityQuery query = new TestDefaultEntityQuery(setQuery, true);
135+
DefaultEntityQuery query = new TestEntityQuery(setQuery, true);
136136
QueryEnhancer queryEnhancer = QueryEnhancerFactory.forQuery(query).create(query);
137137

138138
assertThat(query.getAlias()).isNullOrEmpty();
@@ -152,7 +152,7 @@ void valuesStatementsWorks() {
152152

153153
String setQuery = "VALUES (1, 2, 'test')";
154154

155-
DefaultEntityQuery query = new TestDefaultEntityQuery(setQuery, true);
155+
DefaultEntityQuery query = new TestEntityQuery(setQuery, true);
156156
QueryEnhancer queryEnhancer = QueryEnhancerFactory.forQuery(query).create(query);
157157

158158
assertThat(query.getAlias()).isNullOrEmpty();
@@ -173,7 +173,7 @@ void withStatementsWorks() {
173173
String setQuery = "with sample_data(day, value) as (values ((0, 13), (1, 12), (2, 15), (3, 4), (4, 8), (5, 16))) \n"
174174
+ "select day, value from sample_data as a";
175175

176-
DefaultEntityQuery query = new TestDefaultEntityQuery(setQuery, true);
176+
DefaultEntityQuery query = new TestEntityQuery(setQuery, true);
177177
QueryEnhancer queryEnhancer = QueryEnhancerFactory.forQuery(query).create(query);
178178

179179
assertThat(query.getAlias()).isEqualToIgnoringCase("a");
@@ -196,7 +196,7 @@ void multipleWithStatementsWorks() {
196196
String setQuery = "with sample_data(day, value) as (values ((0, 13), (1, 12), (2, 15), (3, 4), (4, 8), (5, 16))), test2 as (values (1,2,3)) \n"
197197
+ "select day, value from sample_data as a";
198198

199-
DefaultEntityQuery query = new TestDefaultEntityQuery(setQuery, true);
199+
DefaultEntityQuery query = new TestEntityQuery(setQuery, true);
200200
QueryEnhancer queryEnhancer = QueryEnhancerFactory.forQuery(query).create(query);
201201

202202
assertThat(query.getAlias()).isEqualToIgnoringCase("a");
@@ -216,7 +216,7 @@ void multipleWithStatementsWorks() {
216216
@Test // GH-3038
217217
void truncateStatementShouldWork() {
218218

219-
DefaultEntityQuery query = new TestDefaultEntityQuery("TRUNCATE TABLE foo", true);
219+
DefaultEntityQuery query = new TestEntityQuery("TRUNCATE TABLE foo", true);
220220
QueryEnhancer queryEnhancer = QueryEnhancerFactory.forQuery(query).create(query);
221221

222222
assertThat(query.getAlias()).isNull();
@@ -234,7 +234,7 @@ void truncateStatementShouldWork() {
234234
@MethodSource("mergeStatementWorksSource")
235235
void mergeStatementWorksWithJSqlParser(String queryString, String alias) {
236236

237-
DefaultEntityQuery query = new TestDefaultEntityQuery(queryString, true);
237+
DefaultEntityQuery query = new TestEntityQuery(queryString, true);
238238
QueryEnhancer queryEnhancer = QueryEnhancerFactory.forQuery(query).create(query);
239239

240240
assertThat(queryEnhancer.detectAlias()).isEqualTo(alias);

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/ParameterBindingParserUnitTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void identificationOfParameters() {
6767

6868
private void checkHasParameter(SoftAssertions softly, String query, boolean containsParameter, String label) {
6969

70-
DefaultEntityQuery stringQuery = new TestDefaultEntityQuery(query, false);
70+
DefaultEntityQuery stringQuery = new TestEntityQuery(query, false);
7171

7272
softly.assertThat(stringQuery.getParameterBindings().size()) //
7373
.describedAs(String.format("<%s> (%s)", query, label)) //

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/QueryEnhancerFactoryUnitTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class QueryEnhancerFactoryUnitTests {
3232
@Test
3333
void createsParsingImplementationForNonNativeQuery() {
3434

35-
DefaultEntityQuery query = new TestDefaultEntityQuery("select new com.example.User(u.firstname) from User u",
35+
DefaultEntityQuery query = new TestEntityQuery("select new com.example.User(u.firstname) from User u",
3636
false);
3737

3838
QueryEnhancer queryEnhancer = QueryEnhancer.create(query);
@@ -48,7 +48,7 @@ void createsParsingImplementationForNonNativeQuery() {
4848
@Test
4949
void createsJSqlImplementationForNativeQuery() {
5050

51-
DefaultEntityQuery query = new TestDefaultEntityQuery("select * from User", true);
51+
DefaultEntityQuery query = new TestEntityQuery("select * from User", true);
5252

5353
QueryEnhancer queryEnhancer = QueryEnhancerFactory.forQuery(query).create(query);
5454

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/QueryEnhancerTckTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static Stream<Arguments> nativeQueriesWithVariables() {
203203
// DATAJPA-1696
204204
void findProjectionClauseWithIncludedFrom() {
205205

206-
DefaultEntityQuery query = new TestDefaultEntityQuery("select x, frommage, y from t", true);
206+
DefaultEntityQuery query = new TestEntityQuery("select x, frommage, y from t", true);
207207

208208
assertThat(createQueryEnhancer(query).getProjection()).isEqualTo("x, frommage, y");
209209
}

0 commit comments

Comments
 (0)