use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class Datastore method lookup.
public Task<List<MutableDocument>> lookup(List<DocumentKey> keys) {
BatchGetDocumentsRequest.Builder builder = BatchGetDocumentsRequest.newBuilder();
builder.setDatabase(serializer.databaseName());
for (DocumentKey key : keys) {
builder.addDocuments(serializer.encodeKey(key));
}
return channel.runStreamingResponseRpc(FirestoreGrpc.getBatchGetDocumentsMethod(), builder.build()).continueWith(workerQueue.getExecutor(), task -> {
if (!task.isSuccessful()) {
if (task.getException() instanceof FirebaseFirestoreException && ((FirebaseFirestoreException) task.getException()).getCode() == FirebaseFirestoreException.Code.UNAUTHENTICATED) {
channel.invalidateToken();
}
}
Map<DocumentKey, MutableDocument> resultMap = new HashMap<>();
List<BatchGetDocumentsResponse> responses = task.getResult();
for (BatchGetDocumentsResponse response : responses) {
MutableDocument doc = serializer.decodeMaybeDocument(response);
resultMap.put(doc.getKey(), doc);
}
List<MutableDocument> results = new ArrayList<>();
for (DocumentKey key : keys) {
results.add(resultMap.get(key));
}
return results;
});
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class QueryEngineTestCase method addMutation.
/**
* Adds a mutation to the mutation queue.
*/
protected void addMutation(Mutation mutation) {
persistence.runTransaction("addMutation", () -> {
MutationBatch batch = mutationQueue.addMutationBatch(Timestamp.now(), Collections.emptyList(), Collections.singletonList(mutation));
Map<DocumentKey, Mutation> overlayMap = Collections.singletonMap(mutation.getKey(), mutation);
documentOverlayCache.saveOverlays(batch.getBatchId(), overlayMap);
});
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class QueryEngineTestCase method doesNotIncludeDocumentsDeletedByMutation.
@Test
public void doesNotIncludeDocumentsDeletedByMutation() throws Exception {
Query query = query("coll");
addDocument(MATCHING_DOC_A, MATCHING_DOC_B);
persistQueryMapping(MATCHING_DOC_A.getKey(), MATCHING_DOC_B.getKey());
// Add an unacknowledged mutation
addMutation(new DeleteMutation(key("coll/b"), Precondition.NONE));
ImmutableSortedMap<DocumentKey, Document> docs = expectFullCollectionScan(() -> queryEngine.getDocumentsMatchingQuery(query, LAST_LIMBO_FREE_SNAPSHOT, targetCache.getMatchingKeysForTargetId(TEST_TARGET_ID)));
assertEquals(emptyMutableDocumentMap().insert(MATCHING_DOC_A.getKey(), MATCHING_DOC_A), docs);
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class QueryEngineTestCase method persistQueryMapping.
/**
* Adds the provided documents to the query target mapping.
*/
private void persistQueryMapping(DocumentKey... documentKeys) {
persistence.runTransaction("persistQueryMapping", () -> {
ImmutableSortedSet<DocumentKey> remoteKeys = DocumentKey.emptyKeySet();
for (DocumentKey documentKey : documentKeys) {
remoteKeys = remoteKeys.insert(documentKey);
}
targetCache.addMatchingKeys(remoteKeys, TEST_TARGET_ID);
});
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class QueryEngineTestCase method runQuery.
private DocumentSet runQuery(Query query, SnapshotVersion lastLimboFreeSnapshotVersion) {
Preconditions.checkNotNull(expectFullCollectionScan, "Encountered runQuery() call not wrapped in expectOptimizedCollectionQuery()/expectFullCollectionQuery()");
ImmutableSortedMap<DocumentKey, Document> docs = queryEngine.getDocumentsMatchingQuery(query, lastLimboFreeSnapshotVersion, targetCache.getMatchingKeysForTargetId(TEST_TARGET_ID));
View view = new View(query, new ImmutableSortedSet<>(Collections.emptyList(), DocumentKey::compareTo));
View.DocumentChanges viewDocChanges = view.computeDocChanges(docs);
return view.applyChanges(viewDocChanges).getSnapshot().getDocuments();
}
Aggregations