Skip to content

Commit

Permalink
Move Expr operator one level up.
Browse files Browse the repository at this point in the history
The Expr operator should be held within ExpressionOperators not its factory.

See #4139
Original pull request: #4182.
  • Loading branch information
christophstrobl authored and mp911de committed Oct 12, 2022
1 parent 9217821 commit 79f05c3
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 61 deletions.
Expand Up @@ -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();
}
};
}
}

Expand Down
Expand Up @@ -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(
Expand Down

0 comments on commit 79f05c3

Please sign in to comment.