diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/EvaluationOperators.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/EvaluationOperators.java index e2eb49c827..184dcb03dc 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/EvaluationOperators.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/EvaluationOperators.java @@ -92,72 +92,73 @@ public Expr expr() { * @return new instance of {@link Expr}. */ public LastObservationCarriedForward locf() { - return usesFieldRef() ? LastObservationCarriedForward.locfValueOf(fieldReference) : LastObservationCarriedForward.locfValueOf(expression); + return usesFieldRef() ? LastObservationCarriedForward.locfValueOf(fieldReference) + : LastObservationCarriedForward.locfValueOf(expression); + } + + private boolean usesFieldRef() { + return fieldReference != null; + } + } + + /** + * Allows the use of aggregation expressions within the query language. + */ + public static class Expr extends AbstractAggregationExpression { + + private Expr(Object value) { + super(value); + } + + @Override + protected String getMongoMethod() { + return "$expr"; } /** - * Allows the use of aggregation expressions within the query language. + * Creates new {@link Expr}. + * + * @param fieldReference must not be {@literal null}. + * @return new instance of {@link Expr}. */ - public static class Expr extends AbstractAggregationExpression { - - private Expr(Object value) { - super(value); - } - - @Override - protected String getMongoMethod() { - return "$expr"; - } - - /** - * Creates new {@link Expr}. - * - * @param fieldReference must not be {@literal null}. - * @return new instance of {@link Expr}. - */ - public static Expr valueOf(String fieldReference) { - - Assert.notNull(fieldReference, "FieldReference must not be null"); - return new Expr(Fields.field(fieldReference)); - } - - /** - * Creates new {@link Expr}. - * - * @param expression must not be {@literal null}. - * @return new instance of {@link Expr}. - */ - public static Expr valueOf(AggregationExpression expression) { - - Assert.notNull(expression, "Expression must not be null"); - return new Expr(expression); - } - - /** - * Creates {@code $expr} as {@link CriteriaDefinition}. - * - * @return the {@link CriteriaDefinition} from this expression. - */ - public CriteriaDefinition toCriteriaDefinition(AggregationOperationContext context) { - - Document criteriaObject = toDocument(context); - - return new CriteriaDefinition() { - @Override - public Document getCriteriaObject() { - return criteriaObject; - } - - @Override - public String getKey() { - return getMongoMethod(); - } - }; - } + public static Expr valueOf(String fieldReference) { + + Assert.notNull(fieldReference, "FieldReference must not be null"); + return new Expr(Fields.field(fieldReference)); } - private boolean usesFieldRef() { - return fieldReference != null; + /** + * Creates new {@link Expr}. + * + * @param expression must not be {@literal null}. + * @return new instance of {@link Expr}. + */ + public static Expr valueOf(AggregationExpression expression) { + + Assert.notNull(expression, "Expression must not be null"); + return new Expr(expression); + } + + /** + * Creates {@code $expr} as {@link CriteriaDefinition}. + * + * @return the {@link CriteriaDefinition} from this expression. + */ + public CriteriaDefinition toCriteriaDefinition(AggregationOperationContext context) { + + Document criteriaObject = toDocument(context); + + return new CriteriaDefinition() { + @Override + public Document getCriteriaObject() { + return criteriaObject; + } + + @Override + public String getKey() { + return getMongoMethod(); + } + }; } } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/QueryMapperUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/QueryMapperUnitTests.java index 06f6aec93b..c604dd9e18 100755 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/QueryMapperUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/QueryMapperUnitTests.java @@ -1416,7 +1416,7 @@ void allowsUsingFieldPathsForPropertiesHavingCustomConversionRegistered() { @Test // GH-3790 void shouldAcceptExprAsCriteriaDefinition() { - EvaluationOperators.EvaluationOperatorFactory.Expr expr = EvaluationOperators + EvaluationOperators.Expr expr = EvaluationOperators .valueOf(ConditionalOperators.ifNull("customizedField").then(true)).expr(); Query query = query(