use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class ReferenceSet method removeReferencesForId.
/**
* Clears all references with a given ID. Calls removeReference() for each key removed.
*
* @return The keys of the documents that were removed.
*/
public ImmutableSortedSet<DocumentKey> removeReferencesForId(int targetId) {
DocumentKey emptyKey = DocumentKey.empty();
DocumentReference startRef = new DocumentReference(emptyKey, targetId);
Iterator<DocumentReference> it = referencesByTarget.iteratorFrom(startRef);
ImmutableSortedSet<DocumentKey> keys = DocumentKey.emptyKeySet();
while (it.hasNext()) {
DocumentReference ref = it.next();
if (ref.getId() == targetId) {
keys = keys.insert(ref.getKey());
removeReference(ref);
} else {
break;
}
}
return keys;
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class ReferenceSet method referencesForId.
/**
* Returns all of the document keys that have had references added for the given ID.
*/
public ImmutableSortedSet<DocumentKey> referencesForId(int target) {
DocumentKey emptyKey = DocumentKey.empty();
DocumentReference startRef = new DocumentReference(emptyKey, target);
Iterator<DocumentReference> iterator = referencesByTarget.iteratorFrom(startRef);
ImmutableSortedSet<DocumentKey> keys = DocumentKey.emptyKeySet();
while (iterator.hasNext()) {
DocumentReference reference = iterator.next();
if (reference.getId() == target) {
keys = keys.insert(reference.getKey());
} else {
break;
}
}
return keys;
}
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());
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class Query method boundFromFields.
/**
* Converts a list of field values to Bound.
*/
private Bound boundFromFields(String methodName, Object[] values, boolean inclusive) {
// Use explicit order by's because it has to match the query the user made
List<OrderBy> explicitOrderBy = query.getExplicitOrderBy();
if (values.length > explicitOrderBy.size()) {
throw new IllegalArgumentException("Too many arguments provided to " + methodName + "(). The number of arguments must be less " + "than or equal to the number of orderBy() clauses.");
}
List<Value> components = new ArrayList<>();
for (int i = 0; i < values.length; i++) {
Object rawValue = values[i];
OrderBy orderBy = explicitOrderBy.get(i);
if (orderBy.getField().equals(com.google.firebase.firestore.model.FieldPath.KEY_PATH)) {
if (!(rawValue instanceof String)) {
throw new IllegalArgumentException("Invalid query. Expected a string for document ID in " + methodName + "(), but got " + rawValue + ".");
}
String documentId = (String) rawValue;
if (!query.isCollectionGroupQuery() && documentId.contains("/")) {
throw new IllegalArgumentException("Invalid query. When querying a collection and ordering by FieldPath.documentId(), " + "the value passed to " + methodName + "() must be a plain document ID, but '" + documentId + "' contains a slash.");
}
ResourcePath path = query.getPath().append(ResourcePath.fromString(documentId));
if (!DocumentKey.isDocumentKey(path)) {
throw new IllegalArgumentException("Invalid query. When querying a collection group and ordering by " + "FieldPath.documentId(), the value passed to " + methodName + "() must result in a valid document path, but '" + path + "' is not because it contains an odd number of segments.");
}
DocumentKey key = DocumentKey.fromPath(path);
components.add(Values.refValue(firestore.getDatabaseId(), key));
} else {
Value wrapped = firestore.getUserDataReader().parseQueryValue(rawValue);
components.add(wrapped);
}
}
return new Bound(components, inclusive);
}
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));
}
Aggregations