Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7be39ba
Implement boolean expressions (#1025)
katcharov Nov 2, 2022
2f33777
Implement filter, map, reduce (#1031)
katcharov Nov 9, 2022
6acb798
Implement eq, ne, gt, gte, lt, lte (#1033)
katcharov Nov 10, 2022
2d7c03c
Implement string expressions (#1036)
katcharov Nov 15, 2022
6768db0
Implement arithmetic expressions (#1037)
katcharov Nov 29, 2022
7ac3ccd
Implement array expressions (#1043)
katcharov Nov 29, 2022
8b69f18
Implement date expressions (#1045)
katcharov Nov 29, 2022
47efc90
Implement conversion/type expressions (#1050)
katcharov Dec 13, 2022
3dcd2ff
Implement document expressions (#1052)
katcharov Dec 13, 2022
1ce4912
Replace reduce with individual reductions (#1053)
katcharov Jan 18, 2023
0bfce8e
Implement map expressions (#1054)
katcharov Jan 19, 2023
a5245b0
Implement switch expression (#1055)
katcharov Jan 19, 2023
6436f96
Test expressions in context (#1057)
katcharov Jan 19, 2023
25553d1
Add javadoc for boolean, date, number, integer, and expression (#1059)
katcharov Nov 30, 2022
1d9964b
Update and add documentation (#1059)
katcharov Dec 5, 2022
347ab45
Add `@MqlUnchecked` and a few usage examples (#1059)
stIncMale Jan 18, 2023
7ce9cb5
Add has to document, add tests (#1070)
katcharov Jan 20, 2023
75cb0b7
Add javadocs for remaining classes (#1070)
katcharov Jan 20, 2023
8de3396
5.2 annotations (#1070)
katcharov Jan 23, 2023
5680102
5.0 annotations (#1070)
katcharov Jan 23, 2023
b80bfcd
4.4 annotations (#1070)
katcharov Jan 23, 2023
6f24bea
4.2 annotations (#1070)
katcharov Jan 23, 2023
b1ae65d
4.0 annotations (#1070)
katcharov Jan 23, 2023
678cef8
Update and add documentation, add tests, fix minor issues (#1070)
katcharov Jan 23, 2023
441bc53
Rename to Mql (automated) (#1073)
katcharov Jan 27, 2023
6bbb231
Rename methods (automated) (#1073)
katcharov Jan 27, 2023
6588406
Update naming, terms, and missing checks and annotations (#1073)
katcharov Jan 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add @MqlUnchecked and a few usage examples (#1059)
  • Loading branch information
stIncMale authored and katcharov committed Jan 31, 2023
commit 347ab45dfbc6aff862fbdcf2e1549a47e776ad3c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.function.Function;

import static com.mongodb.client.model.expressions.Expressions.of;
import static com.mongodb.client.model.expressions.MqlUnchecked.Unchecked.PRESENT;
import static com.mongodb.client.model.expressions.MqlUnchecked.Unchecked.NON_EMPTY;

/**
* An array {@link Expression value} in the context of the MongoDB Query
Expand Down Expand Up @@ -85,6 +87,7 @@ public interface ArrayExpression<T extends Expression> extends Expression {
* @param i
* @return
*/
@MqlUnchecked(PRESENT)
T elementAt(IntegerExpression i);

default T elementAt(final int i) {
Expand All @@ -95,6 +98,7 @@ default T elementAt(final int i) {
* user asserts that array is not empty
* @return
*/
@MqlUnchecked(NON_EMPTY)
T first();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.List;
import java.util.function.Function;

import static com.mongodb.client.model.expressions.MqlUnchecked.Unchecked.TYPE_ARGUMENT;

public final class Branches<T extends Expression> {

Branches() {
Expand Down Expand Up @@ -78,7 +80,7 @@ public <R extends Expression> BranchesIntermediary<T, R> isDate(final Function<?
}

@SuppressWarnings("unchecked")
public <R extends Expression, Q extends Expression> BranchesIntermediary<T, R> isArray(final Function<? super ArrayExpression<Q>, ? extends R> r) {
public <R extends Expression, Q extends Expression> BranchesIntermediary<T, R> isArray(final Function<? super ArrayExpression<@MqlUnchecked(TYPE_ARGUMENT) Q>, ? extends R> r) {
return is(v -> mqlEx(v).isArray(), v -> r.apply((ArrayExpression<Q>) v));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import static com.mongodb.client.model.expressions.Expressions.of;
import static com.mongodb.client.model.expressions.Expressions.ofMap;
import static com.mongodb.client.model.expressions.MqlUnchecked.Unchecked.PRESENT;
import static com.mongodb.client.model.expressions.MqlUnchecked.Unchecked.TYPE;

/**
* Expresses a document value. A document is an ordered set of fields, where the
Expand All @@ -34,8 +36,10 @@ public interface DocumentExpression extends Expression {

DocumentExpression unsetField(String fieldName);

@MqlUnchecked(PRESENT)
Expression getField(String fieldName);

@MqlUnchecked({PRESENT, TYPE})
BooleanExpression getBoolean(String fieldName);

BooleanExpression getBoolean(String fieldName, BooleanExpression other);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import java.util.function.Function;

import static com.mongodb.client.model.expressions.MqlUnchecked.Unchecked.TYPE_ARGUMENT;

/**
* A value in the context of the MongoDB Query Language (MQL).
*
Expand Down Expand Up @@ -215,7 +217,7 @@ public interface Expression {
* @return the resulting value.
* @param <T> the type of the elements of the resulting array.
*/
<T extends Expression> ArrayExpression<T> isArrayOr(ArrayExpression<? extends T> other);
<T extends Expression> ArrayExpression<@MqlUnchecked(TYPE_ARGUMENT) T> isArrayOr(ArrayExpression<? extends T> other);

/**
* {@code this} value as a {@linkplain DocumentExpression document} if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.function.Function;

import static com.mongodb.client.model.expressions.Expressions.of;
import static com.mongodb.client.model.expressions.MqlUnchecked.Unchecked.PRESENT;

public interface MapExpression<T extends Expression> extends Expression {

Expand All @@ -29,6 +30,7 @@ default BooleanExpression has(String key) {
}

// TODO-END doc "user asserts"
@MqlUnchecked(PRESENT)
T get(StringExpression key);

// TODO-END doc "user asserts"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 2008-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mongodb.client.model.expressions;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Documents places where the API relies on a user asserting
* something that is not checked at run-time.
* If the assertion turns out to be false, the API behavior is unspecified.
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
@Documented
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.METHOD, ElementType.TYPE_USE})
public @interface MqlUnchecked {
/**
* @return A hint on the user assertion the API relies on.
*/
Unchecked[] value();

/**
* @see MqlUnchecked#value()
*/
enum Unchecked {
/**
* The API relies on the values it encounters being of the type
* implied/specified by or inferred from the user code.
* For example, {@link com.mongodb.client.model.expressions.DocumentExpression#getBoolean(String)}
* relies on the values of the document field being of the
* {@linkplain com.mongodb.client.model.expressions.BooleanExpression boolean} type.
*/
TYPE,
/**
* The API checks the raw type, but relies on the type argument
* implied/specified by or inferred from the user code being correct.
* For example, {@link com.mongodb.client.model.expressions.Expression#isArrayOr(ArrayExpression)}
* checks that the value is of the
* {@linkplain com.mongodb.client.model.expressions.ArrayExpression array} raw type,
* but relies on the elements of the array being of the type derived from the user code.
*
* <p>One may think of it as a more specific version of {@link #TYPE}.</p>
*/
TYPE_ARGUMENT,
/**
* The API relies on the array being non-empty.
* For example, {@link com.mongodb.client.model.expressions.ArrayExpression#first()}.
*/
NON_EMPTY,
/**
* The API relies on the element identified by index, name, etc., being present in the
* {@linkplain com.mongodb.client.model.expressions.DocumentExpression document} involved.
* For example, {@link com.mongodb.client.model.expressions.DocumentExpression#getField(String)}.
*/
PRESENT,
}
}