Skip to content

Commit 00ab16f

Browse files
christophstroblmp911de
authored andcommitted
Use data commons expression marker.
See: #5027 Original pull request: #5038
1 parent 72d9361 commit 00ab16f

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/aot/AggregationBlocks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ private CodeBlock aggregationStages(String stageListVariableName, Collection<Str
304304

305305
VariableSnippet stageSnippet = Snippet.declare(builder)
306306
.variable(Document.class, context.localVariable("stage_%s".formatted(stageCounter)))
307-
.of(MongoCodeBlocks.asDocument(stage, parameterNames));
307+
.of(MongoCodeBlocks.asDocument(context.getExpressionMarker(), stage, parameterNames));
308308
builder.addStatement("$L.add($L)", stageListVariableName, stageSnippet.getVariableName());
309309

310310
stageCounter++;

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/aot/MongoCodeBlocks.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.springframework.data.mongodb.repository.aot.UpdateBlocks.UpdateExecutionCodeBlockBuilder;
3333
import org.springframework.data.mongodb.repository.query.MongoQueryMethod;
3434
import org.springframework.data.repository.aot.generate.AotQueryMethodGenerationContext;
35+
import org.springframework.data.repository.aot.generate.ExpressionMarker;
3536
import org.springframework.javapoet.CodeBlock;
3637
import org.springframework.javapoet.CodeBlock.Builder;
3738
import org.springframework.util.NumberUtils;
@@ -162,20 +163,20 @@ static GeoNearExecutionCodeBlockBuilder geoNearExecutionBlockBuilder(AotQueryMet
162163
return new GeoNearExecutionCodeBlockBuilder(context);
163164
}
164165

165-
static CodeBlock asDocument(String source, String argNames) {
166-
return asDocument(source, CodeBlock.of("$L", argNames));
166+
static CodeBlock asDocument(ExpressionMarker expressionMarker, String source, String argNames) {
167+
return asDocument(expressionMarker, source, CodeBlock.of("$L", argNames));
167168
}
168169

169-
static CodeBlock asDocument(String source, CodeBlock arguments) {
170+
static CodeBlock asDocument(ExpressionMarker expressionMarker, String source, CodeBlock arguments) {
170171

171172
Builder builder = CodeBlock.builder();
172173
if (!StringUtils.hasText(source)) {
173174
builder.add("new $T()", Document.class);
174175
} else if (containsPlaceholder(source)) {
175176
if (arguments.isEmpty()) {
176-
builder.add("bindParameters(ExpressionMarker.class.getEnclosingMethod(), $S)", source);
177+
builder.add("bindParameters($L, $S)", expressionMarker.enclosingMethod(), source);
177178
} else {
178-
builder.add("bindParameters(ExpressionMarker.class.getEnclosingMethod(), $S, $L)", source, arguments);
179+
builder.add("bindParameters($L, $S, $L)", expressionMarker.enclosingMethod(), source, arguments);
179180
}
180181
} else {
181182
builder.add("parse($S)", source);
@@ -213,7 +214,7 @@ static CodeBlock evaluateNumberPotentially(String value, Class<? extends Number>
213214
}
214215

215216
Builder builder = CodeBlock.builder();
216-
builder.add("($T) evaluate(ExpressionMarker.class.getEnclosingMethod(), $S$L)", targetType, value,
217+
builder.add("($T) evaluate($L, $S$L)", targetType, context.getExpressionMarker().enclosingMethod(), value,
217218
parameterNames);
218219
return builder.build();
219220
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/aot/MongoRepositoryContributor.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ protected void customizeConstructor(AotRepositoryConstructorBuilder constructorB
216216

217217
CodeBlock.Builder builder = CodeBlock.builder();
218218

219-
builder.addStatement("class ExpressionMarker{}");
219+
// builder.addStatement("class ExpressionMarker{}");
220220
builder.add(finalContribution.contribute(context));
221221

222222
return builder.build();
@@ -241,9 +241,6 @@ private QueryInteraction createStringQuery(RepositoryInformation repositoryInfor
241241
AotStringQuery aotStringQuery = queryCreator.createQuery(partTree, queryMethod, source);
242242
query = new QueryInteraction(aotStringQuery,
243243
partTree.isCountProjection(), partTree.isDelete(), partTree.isExistsProjection());
244-
// if(partTree.isLimiting()) {
245-
// query.s
246-
// }
247244
}
248245

249246
if (queryAnnotation != null && StringUtils.hasText(queryAnnotation.sort())) {

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/aot/QueryBlocks.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,14 @@ CodeBlock build() {
238238
if (StringUtils.hasText(source.getQuery().getFieldsString())) {
239239

240240
VariableSnippet fields = Snippet.declare(builder).variable(Document.class, context.localVariable("fields"))
241-
.of(MongoCodeBlocks.asDocument(source.getQuery().getFieldsString(), queryParameters.get()));
241+
.of(MongoCodeBlocks.asDocument(context.getExpressionMarker(), source.getQuery().getFieldsString(), queryParameters.get()));
242242
builder.addStatement("$L.setFieldsObject($L)", queryVariableName, fields.getVariableName());
243243
}
244244

245245
if (StringUtils.hasText(source.getQuery().getSortString())) {
246246

247247
VariableSnippet sort = Snippet.declare(builder).variable(Document.class, context.localVariable("sort"))
248-
.of(MongoCodeBlocks.asDocument(source.getQuery().getSortString(), getQueryParameters()));
248+
.of(MongoCodeBlocks.asDocument(context.getExpressionMarker(), source.getQuery().getSortString(), getQueryParameters()));
249249
builder.addStatement("$L.setSortObject($L)", queryVariableName, sort.getVariableName());
250250
}
251251

@@ -306,12 +306,12 @@ CodeBlock build() {
306306

307307
if (getQueryParameters().isEmpty()) {
308308
builder.addStatement(
309-
"$L.collation(collationOf(evaluate(ExpressionMarker.class.getEnclosingMethod(), $S)))",
310-
queryVariableName, collationString);
309+
"$L.collation(collationOf(evaluate($L, $S)))",
310+
queryVariableName, context.getExpressionMarker().enclosingMethod(), collationString);
311311
} else {
312312
builder.addStatement(
313-
"$L.collation(collationOf(evaluate(ExpressionMarker.class.getEnclosingMethod(), $S, $L)))",
314-
queryVariableName, collationString, getQueryParameters());
313+
"$L.collation(collationOf(evaluate($L, $S, $L)))",
314+
queryVariableName, context.getExpressionMarker().enclosingMethod(), collationString, getQueryParameters());
315315
}
316316
}
317317
}
@@ -337,9 +337,9 @@ private CodeBlock renderExpressionToQuery() {
337337
} else if (MongoCodeBlocks.containsPlaceholder(source)) {
338338
Builder builder = CodeBlock.builder();
339339
if (getQueryParameters().isEmpty()) {
340-
builder.add("createQuery(ExpressionMarker.class.getEnclosingMethod(), $S)", source);
340+
builder.add("createQuery($L, $S)", context.getExpressionMarker().enclosingMethod(), source);
341341
} else {
342-
builder.add("createQuery(ExpressionMarker.class.getEnclosingMethod(), $S, $L)", source, getQueryParameters());
342+
builder.add("createQuery($L, $S, $L)", context.getExpressionMarker().enclosingMethod(), source, getQueryParameters());
343343
}
344344
return builder.build();
345345
} else {

0 commit comments

Comments
 (0)