Search in sources :

Example 6 with OrderBy

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);
}
Also used : OrderBy(com.google.firebase.firestore.core.OrderBy) Query(com.google.firebase.firestore.core.Query) JSONArray(org.json.JSONArray) Bound(com.google.firebase.firestore.core.Bound) ByteString(com.google.protobuf.ByteString) Target(com.google.firebase.firestore.core.Target) ResourcePath(com.google.firebase.firestore.model.ResourcePath) JSONObject(org.json.JSONObject) FieldFilter(com.google.firebase.firestore.core.FieldFilter) Filter(com.google.firebase.firestore.core.Filter) Nullable(androidx.annotation.Nullable)

Example 7 with OrderBy

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;
}
Also used : OrderBy(com.google.firebase.firestore.core.OrderBy) JSONObject(org.json.JSONObject) FieldPath(com.google.firebase.firestore.model.FieldPath) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString)

Aggregations

OrderBy (com.google.firebase.firestore.core.OrderBy)7 Bound (com.google.firebase.firestore.core.Bound)4 ResourcePath (com.google.firebase.firestore.model.ResourcePath)4 ArrayList (java.util.ArrayList)3 FieldFilter (com.google.firebase.firestore.core.FieldFilter)2 Filter (com.google.firebase.firestore.core.Filter)2 FieldPath (com.google.firebase.firestore.model.FieldPath)2 ArrayValue (com.google.firestore.v1.ArrayValue)2 CollectionSelector (com.google.firestore.v1.StructuredQuery.CollectionSelector)2 QueryTarget (com.google.firestore.v1.Target.QueryTarget)2 Value (com.google.firestore.v1.Value)2 ByteString (com.google.protobuf.ByteString)2 JSONObject (org.json.JSONObject)2 Nullable (androidx.annotation.Nullable)1 Direction (com.google.firebase.firestore.core.OrderBy.Direction)1 Query (com.google.firebase.firestore.core.Query)1 Target (com.google.firebase.firestore.core.Target)1 Document (com.google.firebase.firestore.model.Document)1 DocumentKey (com.google.firebase.firestore.model.DocumentKey)1 Cursor (com.google.firestore.v1.Cursor)1