Search in sources :

Example 1 with NamedQuery

use of com.google.firebase.firestore.bundle.NamedQuery in project firebase-android-sdk by firebase.

the class BundleCacheTestCase method testReturnsSavedLimitToFirstQueries.

@Test
public void testReturnsSavedLimitToFirstQueries() {
    Target target = new Target(path("room"), /* collectionGroup= */
    null, Collections.emptyList(), Collections.emptyList(), /* limit= */
    1, /* startAt= */
    null, /* endAt= */
    null);
    BundledQuery bundledQuery = new BundledQuery(target, Query.LimitType.LIMIT_TO_FIRST);
    NamedQuery expectedQuery = new NamedQuery("query-1", bundledQuery, new SnapshotVersion(Timestamp.now()));
    bundleCache.saveNamedQuery(expectedQuery);
    NamedQuery actualQuery = bundleCache.getNamedQuery("query-1");
    assertEquals(expectedQuery, actualQuery);
}
Also used : Target(com.google.firebase.firestore.core.Target) SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) BundledQuery(com.google.firebase.firestore.bundle.BundledQuery) NamedQuery(com.google.firebase.firestore.bundle.NamedQuery) Test(org.junit.Test)

Example 2 with NamedQuery

use of com.google.firebase.firestore.bundle.NamedQuery in project firebase-android-sdk by firebase.

the class BundleCacheTestCase method testReturnsSavedLimitToLastQueries.

@Test
public void testReturnsSavedLimitToLastQueries() {
    Target target = new Target(path("room"), /* collectionGroup= */
    null, Collections.emptyList(), Collections.emptyList(), /* limit= */
    1, /* startAt= */
    null, /* endAt= */
    null);
    BundledQuery bundledQuery = new BundledQuery(target, Query.LimitType.LIMIT_TO_LAST);
    NamedQuery expectedQuery = new NamedQuery("query-1", bundledQuery, new SnapshotVersion(Timestamp.now()));
    bundleCache.saveNamedQuery(expectedQuery);
    NamedQuery actualQuery = bundleCache.getNamedQuery("query-1");
    assertEquals(expectedQuery, actualQuery);
}
Also used : Target(com.google.firebase.firestore.core.Target) SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) BundledQuery(com.google.firebase.firestore.bundle.BundledQuery) NamedQuery(com.google.firebase.firestore.bundle.NamedQuery) Test(org.junit.Test)

Example 3 with NamedQuery

use of com.google.firebase.firestore.bundle.NamedQuery in project firebase-android-sdk by firebase.

the class FirestoreClient method getNamedQuery.

public Task<Query> getNamedQuery(String queryName) {
    verifyNotTerminated();
    TaskCompletionSource<Query> completionSource = new TaskCompletionSource<>();
    asyncQueue.enqueueAndForget(() -> {
        NamedQuery namedQuery = localStore.getNamedQuery(queryName);
        if (namedQuery != null) {
            Target target = namedQuery.getBundledQuery().getTarget();
            completionSource.setResult(new Query(target.getPath(), target.getCollectionGroup(), target.getFilters(), target.getOrderBy(), target.getLimit(), namedQuery.getBundledQuery().getLimitType(), target.getStartAt(), target.getEndAt()));
        } else {
            completionSource.setResult(null);
        }
    });
    return completionSource.getTask();
}
Also used : TaskCompletionSource(com.google.android.gms.tasks.TaskCompletionSource) NamedQuery(com.google.firebase.firestore.bundle.NamedQuery) NamedQuery(com.google.firebase.firestore.bundle.NamedQuery)

Example 4 with NamedQuery

use of com.google.firebase.firestore.bundle.NamedQuery in project firebase-android-sdk by firebase.

the class LocalStoreTestCase method assertHasNamedQuery.

private void assertHasNamedQuery(NamedQuery expectedNamedQuery) {
    NamedQuery actualNamedQuery = localStore.getNamedQuery(expectedNamedQuery.getName());
    assertEquals(expectedNamedQuery, actualNamedQuery);
}
Also used : NamedQuery(com.google.firebase.firestore.bundle.NamedQuery)

Example 5 with NamedQuery

use of com.google.firebase.firestore.bundle.NamedQuery in project firebase-android-sdk by firebase.

the class LocalStoreTestCase method testHandlesSavingAndLoadingNamedQueries.

@Test
public void testHandlesSavingAndLoadingNamedQueries() {
    Target target = query("foo").toTarget();
    NamedQuery namedQuery = new NamedQuery("testQuery", new BundledQuery(target, Query.LimitType.LIMIT_TO_FIRST), SnapshotVersion.NONE);
    saveNamedQuery(namedQuery);
    assertHasNamedQuery(namedQuery);
}
Also used : Target(com.google.firebase.firestore.core.Target) BundledQuery(com.google.firebase.firestore.bundle.BundledQuery) NamedQuery(com.google.firebase.firestore.bundle.NamedQuery) Test(org.junit.Test)

Aggregations

NamedQuery (com.google.firebase.firestore.bundle.NamedQuery)9 BundledQuery (com.google.firebase.firestore.bundle.BundledQuery)7 Target (com.google.firebase.firestore.core.Target)7 Test (org.junit.Test)7 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)5 TaskCompletionSource (com.google.android.gms.tasks.TaskCompletionSource)1