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"))));
}
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);
}
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);
}
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);
}
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);
}
Aggregations