Skip to content

Commit d9d5cb4

Browse files
committed
Polishing.
Simplify AotQuery design, introduce isDerived() flag and NamedQuery (including isManaged flag) to improve encapsulation and simplify the flow. See #4102
1 parent ae98285 commit d9d5cb4

File tree

7 files changed

+142
-225
lines changed

7 files changed

+142
-225
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/aot/AotQueries.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,35 +110,23 @@ public Map<String, Object> serialize() {
110110

111111
Map<String, Object> serialized = new LinkedHashMap<>();
112112

113-
if (result() instanceof NamedAotQuery nq) {
114-
115-
serialized.put("name", nq.getName());
116-
serialized.put("query", nq.getQueryString());
113+
if (result() instanceof AotQuery.NamedQuery nq) {
114+
serialized.put("name", nq.getQueryName());
117115
}
118116

119117
if (result() instanceof StringAotQuery sq) {
120118
serialized.put("query", sq.getQueryString());
121119
}
122120

123-
if (result() instanceof StringAotQuery.NamedStringAotQuery nsq) {
124-
serialized.put("name", nsq.getQueryName());
125-
}
126-
127121
if (paging) {
128122

129-
if (count() instanceof NamedAotQuery nq) {
130-
131-
serialized.put("count-name", nq.getName());
132-
serialized.put("count-query", nq.getQueryString());
123+
if (count() instanceof AotQuery.NamedQuery nq) {
124+
serialized.put("count-name", nq.getQueryName());
133125
}
134126

135127
if (count() instanceof StringAotQuery sq) {
136128
serialized.put("count-query", sq.getQueryString());
137129
}
138-
139-
if (count() instanceof StringAotQuery.NamedStringAotQuery nsq) {
140-
serialized.put("count-name", nsq.getQueryName());
141-
}
142130
}
143131

144132
return serialized;

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/aot/AotQuery.java

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,30 +67,24 @@ public boolean isLimited() {
6767
}
6868

6969
/**
70-
* @return whether the query a delete query.
70+
* @return whether the query is derived.
71+
* @since 4.0.1
7172
*/
72-
public boolean isDelete() {
73+
public boolean isDerived() {
7374
return false;
7475
}
7576

7677
/**
77-
* @return whether the query is an exists query.
78+
* @return whether the query a delete query.
7879
*/
79-
public boolean isExists() {
80+
public boolean isDelete() {
8081
return false;
8182
}
8283

8384
/**
84-
* @return {@literal true} if the query uses value expressions.
85+
* @return whether the query is an exists query.
8586
*/
86-
public boolean hasExpression() {
87-
88-
for (ParameterBinding parameterBinding : parameterBindings) {
89-
if (parameterBinding.getOrigin().isExpression()) {
90-
return true;
91-
}
92-
}
93-
87+
public boolean isExists() {
9488
return false;
9589
}
9690

@@ -100,4 +94,24 @@ public boolean hasExpression() {
10094
*/
10195
public abstract boolean hasConstructorExpressionOrDefaultProjection();
10296

97+
/**
98+
* Extension to describe a named query.
99+
*
100+
* @since 4.0.1
101+
*/
102+
interface NamedQuery {
103+
104+
/**
105+
* @return the query name.
106+
*/
107+
String getQueryName();
108+
109+
/**
110+
* @return {@literal true} if the query is managed (e.g. defined in an {@code orm.xml} or via {@code @NamedQuery});
111+
* {@literal false} otherwise
112+
*/
113+
boolean isManaged();
114+
115+
}
116+
103117
}

0 commit comments

Comments
 (0)