use of com.google.cloud.firestore.Query.QueryOptions.Builder in project java-firestore by googleapis.
the class Query method select.
/**
* Creates and returns a new Query instance that applies a field mask to the result and returns
* the specified subset of fields. You can specify a list of field paths to return, or use an
* empty list to only return the references of matching documents.
*
* @param fieldPaths The field paths to include.
* @return The created Query.
*/
@Nonnull
public Query select(FieldPath... fieldPaths) {
ImmutableList.Builder<FieldReference> fieldProjections = ImmutableList.builder();
if (fieldPaths.length == 0) {
fieldPaths = new FieldPath[] { FieldPath.DOCUMENT_ID };
}
for (FieldPath path : fieldPaths) {
FieldReference fieldReference = FieldReference.newBuilder().setFieldPath(path.getEncodedPath()).build();
fieldProjections.add(fieldReference);
}
Builder newOptions = options.toBuilder().setFieldProjections(fieldProjections.build());
return new Query(rpcContext, newOptions.build());
}
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 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 before, in order of the query's order by.
* @return The created Query.
*/
@Nonnull
public Query endBefore(Object... fieldValues) {
ImmutableList<FieldOrder> fieldOrders = fieldValues.length == 1 && fieldValues[0] instanceof DocumentReference ? createImplicitOrderBy() : options.getFieldOrders();
Cursor cursor = createCursor(fieldOrders, fieldValues, true);
Builder newOptions = options.toBuilder();
newOptions.setFieldOrders(fieldOrders);
newOptions.setEndCursor(cursor);
return new Query(rpcContext, newOptions.build());
}
use of com.google.cloud.firestore.Query.QueryOptions.Builder in project java-firestore by googleapis.
the class Query method whereEqualTo.
/**
* Creates and returns a new Query with the additional filter that documents must contain the
* specified field and the value should be equal to the specified value.
*
* @param fieldPath The path of the field to compare.
* @param value The value for comparison.
* @return The created Query.
*/
@Nonnull
public Query whereEqualTo(@Nonnull FieldPath fieldPath, @Nullable Object value) {
Preconditions.checkState(options.getStartCursor() == null && options.getEndCursor() == null, "Cannot call whereEqualTo() after defining a boundary with startAt(), " + "startAfter(), endBefore() or endAt().");
if (isUnaryComparison(value)) {
Builder newOptions = options.toBuilder();
StructuredQuery.UnaryFilter.Operator op = value == null ? StructuredQuery.UnaryFilter.Operator.IS_NULL : StructuredQuery.UnaryFilter.Operator.IS_NAN;
UnaryFilter newFieldFilter = new UnaryFilter(fieldPath.toProto(), op);
newOptions.setFieldFilters(append(options.getFieldFilters(), newFieldFilter));
return new Query(rpcContext, newOptions.build());
} else {
return whereHelper(fieldPath, EQUAL, value);
}
}
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 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 start this query at, in order of the query's order by.
* @return The created Query.
*/
@Nonnull
public Query startAt(Object... fieldValues) {
ImmutableList<FieldOrder> fieldOrders = fieldValues.length == 1 && fieldValues[0] instanceof DocumentReference ? createImplicitOrderBy() : options.getFieldOrders();
Cursor cursor = createCursor(fieldOrders, fieldValues, true);
Builder newOptions = options.toBuilder();
newOptions.setFieldOrders(fieldOrders);
newOptions.setStartCursor(cursor);
return new Query(rpcContext, newOptions.build());
}
use of com.google.cloud.firestore.Query.QueryOptions.Builder in project java-firestore by googleapis.
the class Query method whereNotEqualTo.
/**
* Creates and returns a new Query with the additional filter that documents must contain the
* specified field and the value does not equal the specified value.
*
* @param fieldPath The path of the field to compare.
* @param value The value for comparison.
* @return The created Query.
*/
@Nonnull
public Query whereNotEqualTo(@Nonnull FieldPath fieldPath, @Nullable Object value) {
Preconditions.checkState(options.getStartCursor() == null && options.getEndCursor() == null, "Cannot call whereNotEqualTo() after defining a boundary with startAt(), " + "startAfter(), endBefore() or endAt().");
if (isUnaryComparison(value)) {
Builder newOptions = options.toBuilder();
StructuredQuery.UnaryFilter.Operator op = value == null ? StructuredQuery.UnaryFilter.Operator.IS_NOT_NULL : StructuredQuery.UnaryFilter.Operator.IS_NOT_NAN;
UnaryFilter newFieldFilter = new UnaryFilter(fieldPath.toProto(), op);
newOptions.setFieldFilters(append(options.getFieldFilters(), newFieldFilter));
return new Query(rpcContext, newOptions.build());
} else {
return whereHelper(fieldPath, NOT_EQUAL, value);
}
}
Aggregations