Search in sources :

Example 26 with DocumentKey

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

the class LocalDocumentsView method getDocumentsMatchingDocumentQuery.

/**
 * Performs a simple document lookup for the given path.
 */
private ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingDocumentQuery(ResourcePath path) {
    ImmutableSortedMap<DocumentKey, Document> result = emptyDocumentMap();
    // Just do a simple document lookup.
    Document doc = getDocument(DocumentKey.fromPath(path));
    if (doc.isFoundDocument()) {
        result = result.insert(doc.getKey(), doc);
    }
    return result;
}
Also used : DocumentKey(com.google.firebase.firestore.model.DocumentKey) Document(com.google.firebase.firestore.model.Document) MutableDocument(com.google.firebase.firestore.model.MutableDocument)

Example 27 with DocumentKey

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

the class SyncEngine method trackLimboChange.

private void trackLimboChange(LimboDocumentChange change) {
    DocumentKey key = change.getKey();
    if (!activeLimboTargetsByKey.containsKey(key) && !enqueuedLimboResolutions.contains(key)) {
        Logger.debug(TAG, "New document in limbo: %s", key);
        enqueuedLimboResolutions.add(key);
        pumpEnqueuedLimboResolutions();
    }
}
Also used : DocumentKey(com.google.firebase.firestore.model.DocumentKey)

Example 28 with DocumentKey

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

the class TestCaseConverter method convertDatabaseContents.

private List<Collection> convertDatabaseContents(DatastoreTestTrace.FirestoreV1Action action) {
    LinkedHashMap<String, List<Document>> collections = new LinkedHashMap<>();
    List<RunQueryResponse> responses = action.getDatabaseContentsBeforeAction().getResponseList();
    for (RunQueryResponse response : responses) {
        if (response.hasDocument()) {
            Document document = response.getDocument();
            DocumentKey documentKey = DocumentKey.fromName(document.getName());
            String collectionId = documentKey.getCollectionGroup();
            List<Document> documents = collections.computeIfAbsent(collectionId, name -> new ArrayList<>());
            documents.add(document);
        }
    }
    return collections.entrySet().stream().map(entry -> Collection.Builder.builder().setName(entry.getKey()).setDocuments(entry.getValue()).build()).collect(Collectors.toList());
}
Also used : StructuredQuery(com.google.firestore.v1.StructuredQuery) DatastoreTestTrace(com.google.apphosting.datastore.testing.DatastoreTestTrace) Document(com.google.firestore.v1.Document) Where(com.google.firebase.firestore.conformance.model.Where) ResourcePath(com.google.firebase.firestore.model.ResourcePath) QueryFilter(com.google.firebase.firestore.conformance.model.QueryFilter) Collectors(java.util.stream.Collectors) Order(com.google.firebase.firestore.conformance.model.Order) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) Value(com.google.firestore.v1.Value) Result(com.google.firebase.firestore.conformance.model.Result) Cursor(com.google.firestore.v1.Cursor) Query(com.google.firebase.firestore.conformance.model.Query) Collection(com.google.firebase.firestore.conformance.model.Collection) RunQueryResponse(com.google.firestore.v1.RunQueryResponse) DocumentKey(com.google.firebase.firestore.model.DocumentKey) TestCase(com.google.firebase.firestore.conformance.model.TestCase) RunQueryResponse(com.google.firestore.v1.RunQueryResponse) DocumentKey(com.google.firebase.firestore.model.DocumentKey) ArrayList(java.util.ArrayList) List(java.util.List) Document(com.google.firestore.v1.Document) LinkedHashMap(java.util.LinkedHashMap)

Example 29 with DocumentKey

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

the class SpecTestCase method doMutation.

private void doMutation(Mutation mutation) throws Exception {
    DocumentKey documentKey = mutation.getKey();
    TaskCompletionSource<Void> callback = new TaskCompletionSource<>();
    Task<Void> writeProcessed = callback.getTask().continueWith(backgroundExecutor, task -> {
        if (task.isSuccessful()) {
            SpecTestCase.this.acknowledgedDocs.add(documentKey);
        } else {
            SpecTestCase.this.rejectedDocs.add(documentKey);
        }
        return null;
    });
    getCurrentOutstandingWrites().add(new Pair<>(mutation, writeProcessed));
    log("      Sending this write: " + mutation);
    queue.runSync(() -> syncEngine.writeMutations(singletonList(mutation), callback));
}
Also used : TaskCompletionSource(com.google.android.gms.tasks.TaskCompletionSource) DocumentKey(com.google.firebase.firestore.model.DocumentKey)

Example 30 with DocumentKey

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

the class RemoteEventTest method testTracksLimboDocuments.

@Test
public void testTracksLimboDocuments() {
    Map<Integer, TargetData> listens = activeQueries(1);
    listens.putAll(activeLimboQueries("doc/2", 2));
    // Add 3 docs: 1 is limbo and non-limbo, 2 is limbo-only, 3 is non-limbo
    MutableDocument doc1 = doc("docs/1", 1, map("key", "value"));
    MutableDocument doc2 = doc("docs/2", 1, map("key", "value"));
    MutableDocument doc3 = doc("docs/3", 1, map("key", "value"));
    // Target 2 is a limbo target
    DocumentChange docChange1 = new DocumentChange(asList(1, 2), emptyList(), doc1.getKey(), doc1);
    DocumentChange docChange2 = new DocumentChange(asList(2), emptyList(), doc2.getKey(), doc2);
    DocumentChange docChange3 = new DocumentChange(asList(1), emptyList(), doc3.getKey(), doc3);
    WatchTargetChange targetsChange = new WatchTargetChange(WatchTargetChangeType.Current, asList(1, 2));
    RemoteEvent event = createRemoteEvent(3, listens, noOutstandingResponses, noExistingKeys, docChange1, docChange2, docChange3, targetsChange);
    Set<DocumentKey> limboDocuments = event.getResolvedLimboDocuments();
    // Doc1 is in both limbo and non-limbo targets, therefore not tracked as limbo
    assertFalse(limboDocuments.contains(doc1.getKey()));
    // Doc2 is only in the limbo target, so is tracked as a limbo document
    assertTrue(limboDocuments.contains(doc2.getKey()));
    // Doc3 is only in the non-limbo target, therefore not tracked as limbo
    assertFalse(limboDocuments.contains(doc3.getKey()));
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) MutableDocument(com.google.firebase.firestore.model.MutableDocument) DocumentKey(com.google.firebase.firestore.model.DocumentKey) DocumentChange(com.google.firebase.firestore.remote.WatchChange.DocumentChange) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) Test(org.junit.Test)

Aggregations

DocumentKey (com.google.firebase.firestore.model.DocumentKey)134 MutableDocument (com.google.firebase.firestore.model.MutableDocument)52 Test (org.junit.Test)36 HashMap (java.util.HashMap)29 ArrayList (java.util.ArrayList)25 Document (com.google.firebase.firestore.model.Document)23 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)16 Mutation (com.google.firebase.firestore.model.mutation.Mutation)15 Map (java.util.Map)15 ResourcePath (com.google.firebase.firestore.model.ResourcePath)13 MutationBatch (com.google.firebase.firestore.model.mutation.MutationBatch)11 HashSet (java.util.HashSet)11 Overlay (com.google.firebase.firestore.model.mutation.Overlay)10 ImmutableSortedMap (com.google.firebase.database.collection.ImmutableSortedMap)9 TestUtil.patchMutation (com.google.firebase.firestore.testutil.TestUtil.patchMutation)7 TestUtil.setMutation (com.google.firebase.firestore.testutil.TestUtil.setMutation)7 ByteString (com.google.protobuf.ByteString)7 Query (com.google.firebase.firestore.core.Query)6 ObjectValue (com.google.firebase.firestore.model.ObjectValue)6 Timestamp (com.google.firebase.Timestamp)5