use of com.google.firebase.firestore.core.OrderBy in project firebase-android-sdk by firebase.
the class BundleSerializer method decodeBundledQuery.
private BundledQuery decodeBundledQuery(JSONObject bundledQuery) throws JSONException {
JSONObject structuredQuery = bundledQuery.getJSONObject("structuredQuery");
verifyNoSelect(structuredQuery);
ResourcePath parent = decodeName(bundledQuery.getString("parent"));
JSONArray from = structuredQuery.getJSONArray("from");
verifyCollectionSelector(from);
JSONObject collectionSelector = from.getJSONObject(0);
boolean allDescendants = collectionSelector.optBoolean("allDescendants", false);
@Nullable String collectionGroup = null;
if (allDescendants) {
collectionGroup = collectionSelector.getString("collectionId");
} else {
parent = parent.append(collectionSelector.getString("collectionId"));
}
List<Filter> filters = decodeWhere(structuredQuery.optJSONObject("where"));
List<OrderBy> orderBys = decodeOrderBy(structuredQuery.optJSONArray("orderBy"));
@Nullable Bound startAt = decodeStartAtBound(structuredQuery.optJSONObject("startAt"));
@Nullable Bound endAt = decodeEndAtBound(structuredQuery.optJSONObject("endAt"));
verifyNoOffset(structuredQuery);
int limit = decodeLimit(structuredQuery);
Query.LimitType limitType = decodeLimitType(bundledQuery);
return new BundledQuery(new Target(parent, collectionGroup, filters, orderBys, limit, startAt, endAt), limitType);
}
use of com.google.firebase.firestore.core.OrderBy in project firebase-android-sdk by firebase.
the class BundleSerializer method decodeOrderBy.
private List<OrderBy> decodeOrderBy(@Nullable JSONArray orderBys) throws JSONException {
List<OrderBy> result = new ArrayList<>();
if (orderBys != null) {
for (int i = 0; i < orderBys.length(); ++i) {
JSONObject orderBy = orderBys.getJSONObject(i);
FieldPath fieldPath = decodeFieldReference(orderBy.getJSONObject("field"));
String directionString = orderBy.optString("direction", "ASCENDING");
OrderBy.Direction direction = directionString.equals("ASCENDING") ? OrderBy.Direction.ASCENDING : OrderBy.Direction.DESCENDING;
result.add(OrderBy.getInstance(direction, fieldPath));
}
}
return result;
}
Aggregations