Skip to content

Commit 75412fa

Browse files
code changes per code review comments
1 parent ea0da76 commit 75412fa

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/integrationTest/java/com/mongodb/hibernate/query/select/SortingSelectQueryIntegrationTests.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.junit.jupiter.api.Test;
3737
import org.junit.jupiter.params.ParameterizedTest;
3838
import org.junit.jupiter.params.provider.EnumSource;
39+
import org.junit.jupiter.params.provider.ValueSource;
3940

4041
@DomainModel(annotatedClasses = Book.class)
4142
class SortingSelectQueryIntegrationTests extends AbstractSelectionQueryIntegrationTests {
@@ -164,8 +165,8 @@ void testSortFieldNotFieldPathExpressionNotSupported() {
164165
"from Book ORDER BY length(title)",
165166
Book.class,
166167
FeatureNotSupportedException.class,
167-
"%s does not support sort key not of field path type",
168-
MONGO_DBMS_NAME);
168+
"TODO-HIBERNATE-%1$d https://jira.mongodb.org/browse/HIBERNATE-%1$d",
169+
79);
169170
}
170171

171172
@ParameterizedTest
@@ -188,7 +189,8 @@ void testCaseInsensitiveSortSpecNotSupported() {
188189
criteria.select(root);
189190
criteria.orderBy(cb.sort(root.get("title"), SortDirection.ASCENDING, NullPrecedence.NONE, true));
190191
assertThatThrownBy(() -> session.createSelectionQuery(criteria).getResultList())
191-
.isInstanceOf(FeatureNotSupportedException.class);
192+
.isInstanceOf(FeatureNotSupportedException.class)
193+
.hasMessage("TODO-HIBERNATE-%1$d https://jira.mongodb.org/browse/HIBERNATE-%1$d", 79);
192194
});
193195
}
194196
}

src/main/java/com/mongodb/hibernate/internal/translate/AbstractMqlTranslator.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,8 @@ public void visitQuerySpec(QuerySpec querySpec) {
371371
var stages = new ArrayList<AstStage>(3);
372372

373373
createMatchStage(querySpec).ifPresent(stages::add);
374-
375374
createSortStage(querySpec).ifPresent(stages::add);
376-
377-
var projectStageSpecifications = acceptAndYield(querySpec.getSelectClause(), PROJECT_STAGE_SPECIFICATIONS);
378-
stages.add(new AstProjectStage(projectStageSpecifications));
375+
stages.add(createProjectStage(querySpec.getSelectClause()));
379376

380377
astVisitorValueHolder.yield(COLLECTION_AGGREGATE, new AstAggregateCommand(collection, stages));
381378
}
@@ -402,6 +399,11 @@ private Optional<AstSortStage> createSortStage(QuerySpec querySpec) {
402399
return Optional.empty();
403400
}
404401

402+
private AstProjectStage createProjectStage(SelectClause selectClause) {
403+
var projectStageSpecifications = acceptAndYield(selectClause, PROJECT_STAGE_SPECIFICATIONS);
404+
return new AstProjectStage(projectStageSpecifications);
405+
}
406+
405407
@Override
406408
public void visitFromClause(FromClause fromClause) {
407409
if (fromClause.getRoots().size() != 1) {
@@ -549,7 +551,7 @@ public void visitSortSpecification(SortSpecification sortSpecification) {
549551
format("%s does not support null precedence: NULLS %s", MONGO_DBMS_NAME, nullPrecedence));
550552
}
551553
if (sortSpecification.isIgnoreCase()) {
552-
throw new FeatureNotSupportedException("Case-insensitive sorting not supported");
554+
throw new FeatureNotSupportedException("TODO-HIBERNATE-79 https://jira.mongodb.org/browse/HIBERNATE-79");
553555
}
554556

555557
var astSortOrder =
@@ -574,8 +576,7 @@ public void visitSortSpecification(SortSpecification sortSpecification) {
574576

575577
private AstSortField createAstSortField(Expression sortExpression, AstSortOrder astSortOrder) {
576578
if (!isFieldPathExpression(sortExpression)) {
577-
throw new FeatureNotSupportedException(
578-
format("%s does not support sort key not of field path type", MONGO_DBMS_NAME));
579+
throw new FeatureNotSupportedException("TODO-HIBERNATE-79 https://jira.mongodb.org/browse/HIBERNATE-79");
579580
}
580581
var fieldPath = acceptAndYield(sortExpression, FIELD_PATH);
581582
return new AstSortField(fieldPath, astSortOrder);

0 commit comments

Comments
 (0)