Search in sources :

Example 16 with FieldPath

use of com.google.firebase.firestore.model.FieldPath in project firebase-android-sdk by firebase.

the class BundleSerializer method decodeFieldFilter.

private void decodeFieldFilter(List<Filter> result, JSONObject fieldFilter) throws JSONException {
    FieldPath fieldPath = decodeFieldReference(fieldFilter.getJSONObject("field"));
    FieldFilter.Operator filterOperator = decodeFieldFilterOperator(fieldFilter.getString("op"));
    result.add(FieldFilter.create(fieldPath, filterOperator, decodeValue(fieldFilter.getJSONObject("value"))));
}
Also used : FieldFilter(com.google.firebase.firestore.core.FieldFilter) FieldPath(com.google.firebase.firestore.model.FieldPath)

Example 17 with FieldPath

use of com.google.firebase.firestore.model.FieldPath in project firebase-android-sdk by firebase.

the class UserDataReader method parseUpdateData.

/**
 * Parses the update data from the update(field, value, field, value...) varargs call, accepting
 * both strings and FieldPaths.
 */
public ParsedUpdateData parseUpdateData(List<Object> fieldsAndValues) {
    // fieldsAndValues.length and alternating types should already be validated by
    // Util.collectUpdateArguments().
    hardAssert(fieldsAndValues.size() % 2 == 0, "Expected fieldAndValues to contain an even number of elements");
    ParseAccumulator accumulator = new ParseAccumulator(UserData.Source.Update);
    ParseContext context = accumulator.rootContext();
    ObjectValue updateData = new ObjectValue();
    Iterator<Object> iterator = fieldsAndValues.iterator();
    while (iterator.hasNext()) {
        Object fieldPath = iterator.next();
        Object fieldValue = iterator.next();
        hardAssert(fieldPath instanceof String || fieldPath instanceof com.google.firebase.firestore.FieldPath, "Expected argument to be String or FieldPath.");
        FieldPath parsedField;
        if (fieldPath instanceof String) {
            parsedField = com.google.firebase.firestore.FieldPath.fromDotSeparatedPath((String) fieldPath).getInternalPath();
        } else {
            parsedField = ((com.google.firebase.firestore.FieldPath) fieldPath).getInternalPath();
        }
        if (fieldValue instanceof DeleteFieldValue) {
            // Add it to the field mask, but don't add anything to updateData.
            context.addToFieldMask(parsedField);
        } else {
            Value parsedValue = convertAndParseFieldData(fieldValue, context.childContext(parsedField));
            if (parsedValue != null) {
                context.addToFieldMask(parsedField);
                updateData.set(parsedField, parsedValue);
            }
        }
    }
    return accumulator.toUpdateData(updateData);
}
Also used : ParseAccumulator(com.google.firebase.firestore.core.UserData.ParseAccumulator) FieldPath(com.google.firebase.firestore.model.FieldPath) ObjectValue(com.google.firebase.firestore.model.ObjectValue) ParseContext(com.google.firebase.firestore.core.UserData.ParseContext) ObjectValue(com.google.firebase.firestore.model.ObjectValue) Value(com.google.firestore.v1.Value) NullValue(com.google.protobuf.NullValue) DeleteFieldValue(com.google.firebase.firestore.FieldValue.DeleteFieldValue) MapValue(com.google.firestore.v1.MapValue) ServerTimestampFieldValue(com.google.firebase.firestore.FieldValue.ServerTimestampFieldValue) ArrayUnionFieldValue(com.google.firebase.firestore.FieldValue.ArrayUnionFieldValue) ArrayRemoveFieldValue(com.google.firebase.firestore.FieldValue.ArrayRemoveFieldValue) ArrayValue(com.google.firestore.v1.ArrayValue) DeleteFieldValue(com.google.firebase.firestore.FieldValue.DeleteFieldValue)

Example 18 with FieldPath

use of com.google.firebase.firestore.model.FieldPath in project firebase-android-sdk by firebase.

the class Query method filter.

/**
 * Creates a new Query with an additional filter.
 *
 * @param filter The predicate to filter by.
 * @return the new Query.
 */
public Query filter(Filter filter) {
    hardAssert(!isDocumentQuery(), "No filter is allowed for document query");
    FieldPath newInequalityField = filter.getFirstInequalityField();
    FieldPath queryInequalityField = inequalityField();
    Assert.hardAssert(queryInequalityField == null || newInequalityField == null || queryInequalityField.equals(newInequalityField), "Query must only have one inequality field");
    Assert.hardAssert(explicitSortOrder.isEmpty() || newInequalityField == null || explicitSortOrder.get(0).field.equals(newInequalityField), "First orderBy must match inequality field");
    List<Filter> updatedFilter = new ArrayList<>(filters);
    updatedFilter.add(filter);
    return new Query(path, collectionGroup, updatedFilter, explicitSortOrder, limit, limitType, startAt, endAt);
}
Also used : FieldPath(com.google.firebase.firestore.model.FieldPath) ArrayList(java.util.ArrayList)

Example 19 with FieldPath

use of com.google.firebase.firestore.model.FieldPath in project firebase-android-sdk by firebase.

the class Query method orderBy.

/**
 * Creates a new Query with an additional ordering constraint.
 *
 * @param order The key and direction to order by.
 * @return the new Query.
 */
public Query orderBy(OrderBy order) {
    hardAssert(!isDocumentQuery(), "No ordering is allowed for document query");
    if (explicitSortOrder.isEmpty()) {
        FieldPath inequality = inequalityField();
        if (inequality != null && !inequality.equals(order.field)) {
            throw Assert.fail("First orderBy must match inequality field");
        }
    }
    List<OrderBy> updatedSortOrder = new ArrayList<>(explicitSortOrder);
    updatedSortOrder.add(order);
    return new Query(path, collectionGroup, filters, updatedSortOrder, limit, limitType, startAt, endAt);
}
Also used : FieldPath(com.google.firebase.firestore.model.FieldPath) ArrayList(java.util.ArrayList)

Example 20 with FieldPath

use of com.google.firebase.firestore.model.FieldPath in project firebase-android-sdk by firebase.

the class ConformanceTest method formatFieldPath.

private com.google.firebase.firestore.FieldPath formatFieldPath(String serverFormat) {
    FieldPath fieldPath = FieldPath.fromServerFormat(serverFormat);
    String[] segments = new String[fieldPath.length()];
    for (int i = 0; i < fieldPath.length(); ++i) {
        segments[i] = fieldPath.getSegment(i);
    }
    return com.google.firebase.firestore.FieldPath.of(segments);
}
Also used : FieldPath(com.google.firebase.firestore.model.FieldPath)

Aggregations

FieldPath (com.google.firebase.firestore.model.FieldPath)22 ObjectValue (com.google.firebase.firestore.model.ObjectValue)10 Value (com.google.firestore.v1.Value)9 ArrayList (java.util.ArrayList)7 Nullable (androidx.annotation.Nullable)3 ParseAccumulator (com.google.firebase.firestore.core.UserData.ParseAccumulator)3 ByteString (com.google.protobuf.ByteString)3 ArrayRemoveFieldValue (com.google.firebase.firestore.FieldValue.ArrayRemoveFieldValue)2 ArrayUnionFieldValue (com.google.firebase.firestore.FieldValue.ArrayUnionFieldValue)2 DeleteFieldValue (com.google.firebase.firestore.FieldValue.DeleteFieldValue)2 ServerTimestampFieldValue (com.google.firebase.firestore.FieldValue.ServerTimestampFieldValue)2 FieldFilter (com.google.firebase.firestore.core.FieldFilter)2 OrderBy (com.google.firebase.firestore.core.OrderBy)2 Direction (com.google.firebase.firestore.core.OrderBy.Direction)2 ParseContext (com.google.firebase.firestore.core.UserData.ParseContext)2 FieldIndex (com.google.firebase.firestore.model.FieldIndex)2 ArrayValue (com.google.firestore.v1.ArrayValue)2 MapValue (com.google.firestore.v1.MapValue)2 NullValue (com.google.protobuf.NullValue)2 HashMap (java.util.HashMap)2