Search in sources :

Example 1 with Builder

use of com.google.cloud.firestore.Query.QueryOptions.Builder in project java-firestore by googleapis.

the class Query method startAt.

/**
 * Creates and returns a new Query that starts at the provided document (inclusive). The starting
 * position is relative to the order of the query. The document must contain all of the fields
 * provided in the orderBy of this query.
 *
 * @param snapshot The snapshot of the document to start at.
 * @return The created Query.
 */
@Nonnull
public Query startAt(@Nonnull DocumentSnapshot snapshot) {
    ImmutableList<FieldOrder> fieldOrders = createImplicitOrderBy();
    Cursor cursor = createCursor(fieldOrders, snapshot, true);
    Builder newOptions = options.toBuilder();
    newOptions.setFieldOrders(fieldOrders);
    newOptions.setStartCursor(cursor);
    return new Query(rpcContext, newOptions.build());
}
Also used : StructuredQuery(com.google.firestore.v1.StructuredQuery) BundledQuery(com.google.firestore.bundle.BundledQuery) Builder(com.google.cloud.firestore.Query.QueryOptions.Builder) Cursor(com.google.firestore.v1.Cursor) Nonnull(javax.annotation.Nonnull)

Example 2 with Builder

use of com.google.cloud.firestore.Query.QueryOptions.Builder in project java-firestore by googleapis.

the class Query method startAfter.

/**
 * Creates and returns a new Query that starts after the provided document (exclusive). The
 * starting position is relative to the order of the query. The document must contain all of the
 * fields provided in the orderBy of this query.
 *
 * @param snapshot The snapshot of the document to start after.
 * @return The created Query.
 */
@Nonnull
public Query startAfter(@Nonnull DocumentSnapshot snapshot) {
    ImmutableList<FieldOrder> fieldOrders = createImplicitOrderBy();
    Cursor cursor = createCursor(fieldOrders, snapshot, false);
    Builder newOptions = options.toBuilder();
    newOptions.setFieldOrders(fieldOrders);
    newOptions.setStartCursor(cursor);
    return new Query(rpcContext, newOptions.build());
}
Also used : StructuredQuery(com.google.firestore.v1.StructuredQuery) BundledQuery(com.google.firestore.bundle.BundledQuery) Builder(com.google.cloud.firestore.Query.QueryOptions.Builder) Cursor(com.google.firestore.v1.Cursor) Nonnull(javax.annotation.Nonnull)

Example 3 with Builder

use of com.google.cloud.firestore.Query.QueryOptions.Builder in project java-firestore by googleapis.

the class Query method endBefore.

/**
 * Creates and returns a new Query that ends before the provided document (exclusive). The end
 * position is relative to the order of the query. The document must contain all of the fields
 * provided in the orderBy of this query.
 *
 * @param snapshot The snapshot of the document to end before.
 * @return The created Query.
 */
@Nonnull
public Query endBefore(@Nonnull DocumentSnapshot snapshot) {
    ImmutableList<FieldOrder> fieldOrders = createImplicitOrderBy();
    Cursor cursor = createCursor(fieldOrders, snapshot, true);
    Builder newOptions = options.toBuilder();
    newOptions.setFieldOrders(fieldOrders);
    newOptions.setEndCursor(cursor);
    return new Query(rpcContext, newOptions.build());
}
Also used : StructuredQuery(com.google.firestore.v1.StructuredQuery) BundledQuery(com.google.firestore.bundle.BundledQuery) Builder(com.google.cloud.firestore.Query.QueryOptions.Builder) Cursor(com.google.firestore.v1.Cursor) Nonnull(javax.annotation.Nonnull)

Example 4 with Builder

use of com.google.cloud.firestore.Query.QueryOptions.Builder in project java-firestore by googleapis.

the class Query method endAt.

/**
 * Creates and returns a new Query that ends at the provided fields relative to the order of the
 * query. The order of the field values must match the order of the order by clauses of the query.
 *
 * @param fieldValues The field values to end this query at, in order of the query's order by.
 * @return The created Query.
 */
@Nonnull
public Query endAt(Object... fieldValues) {
    ImmutableList<FieldOrder> fieldOrders = fieldValues.length == 1 && fieldValues[0] instanceof DocumentReference ? createImplicitOrderBy() : options.getFieldOrders();
    Cursor cursor = createCursor(fieldOrders, fieldValues, false);
    Builder newOptions = options.toBuilder();
    newOptions.setFieldOrders(fieldOrders);
    newOptions.setEndCursor(cursor);
    return new Query(rpcContext, newOptions.build());
}
Also used : StructuredQuery(com.google.firestore.v1.StructuredQuery) BundledQuery(com.google.firestore.bundle.BundledQuery) Builder(com.google.cloud.firestore.Query.QueryOptions.Builder) Cursor(com.google.firestore.v1.Cursor) Nonnull(javax.annotation.Nonnull)

Example 5 with Builder

use of com.google.cloud.firestore.Query.QueryOptions.Builder in project java-firestore by googleapis.

the class Query method endAt.

/**
 * Creates and returns a new Query that ends at the provided document (inclusive). The end
 * position is relative to the order of the query. The document must contain all of the fields
 * provided in the orderBy of this query.
 *
 * @param snapshot The snapshot of the document to end at.
 * @return The created Query.
 */
@Nonnull
public Query endAt(@Nonnull DocumentSnapshot snapshot) {
    ImmutableList<FieldOrder> fieldOrders = createImplicitOrderBy();
    Cursor cursor = createCursor(fieldOrders, snapshot, false);
    Builder newOptions = options.toBuilder();
    newOptions.setFieldOrders(fieldOrders);
    newOptions.setEndCursor(cursor);
    return new Query(rpcContext, newOptions.build());
}
Also used : StructuredQuery(com.google.firestore.v1.StructuredQuery) BundledQuery(com.google.firestore.bundle.BundledQuery) Builder(com.google.cloud.firestore.Query.QueryOptions.Builder) Cursor(com.google.firestore.v1.Cursor) Nonnull(javax.annotation.Nonnull)

Aggregations

Builder (com.google.cloud.firestore.Query.QueryOptions.Builder)13 BundledQuery (com.google.firestore.bundle.BundledQuery)13 StructuredQuery (com.google.firestore.v1.StructuredQuery)13 Nonnull (javax.annotation.Nonnull)11 Cursor (com.google.firestore.v1.Cursor)8 ImmutableList (com.google.common.collect.ImmutableList)2 FieldReference (com.google.firestore.v1.StructuredQuery.FieldReference)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1