use of com.google.firebase.firestore.model.ResourcePath in project firebase-android-sdk by firebase.
the class SQLiteIndexManager method addToCollectionParentIndex.
@Override
public void addToCollectionParentIndex(ResourcePath collectionPath) {
hardAssert(started, "IndexManager not started");
hardAssert(collectionPath.length() % 2 == 1, "Expected a collection path.");
if (collectionParentsCache.add(collectionPath)) {
String collectionId = collectionPath.getLastSegment();
ResourcePath parentPath = collectionPath.popLast();
db.execute("INSERT OR REPLACE INTO collection_parents " + "(collection_id, parent) " + "VALUES (?, ?)", collectionId, EncodedPath.encode(parentPath));
}
}
use of com.google.firebase.firestore.model.ResourcePath in project firebase-android-sdk by firebase.
the class LocalDocumentsView method getDocumentsMatchingCollectionGroupQuery.
private ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingCollectionGroupQuery(Query query, IndexOffset offset) {
hardAssert(query.getPath().isEmpty(), "Currently we only support collection group queries at the root.");
String collectionId = query.getCollectionGroup();
ImmutableSortedMap<DocumentKey, Document> results = emptyDocumentMap();
List<ResourcePath> parents = indexManager.getCollectionParents(collectionId);
// aggregate the results.
for (ResourcePath parent : parents) {
Query collectionQuery = query.asCollectionQueryAtPath(parent.append(collectionId));
ImmutableSortedMap<DocumentKey, Document> collectionResults = getDocumentsMatchingCollectionQuery(collectionQuery, offset);
for (Map.Entry<DocumentKey, Document> docEntry : collectionResults) {
results = results.insert(docEntry.getKey(), docEntry.getValue());
}
}
return results;
}
use of com.google.firebase.firestore.model.ResourcePath 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.ResourcePath in project firebase-android-sdk by firebase.
the class TestUtil method addedRemoteEvent.
public static RemoteEvent addedRemoteEvent(List<MutableDocument> docs, List<Integer> updatedInTargets, List<Integer> removedFromTargets) {
Preconditions.checkArgument(!docs.isEmpty(), "Cannot pass empty docs array");
WatchChangeAggregator aggregator = new WatchChangeAggregator(new WatchChangeAggregator.TargetMetadataProvider() {
@Override
public ImmutableSortedSet<DocumentKey> getRemoteKeysForTarget(int targetId) {
return DocumentKey.emptyKeySet();
}
@Override
public TargetData getTargetDataForTarget(int targetId) {
ResourcePath collectionPath = docs.get(0).getKey().getCollectionPath();
return targetData(targetId, QueryPurpose.LISTEN, collectionPath.toString());
}
});
SnapshotVersion version = SnapshotVersion.NONE;
for (MutableDocument doc : docs) {
DocumentChange change = new DocumentChange(updatedInTargets, removedFromTargets, doc.getKey(), doc);
aggregator.handleDocumentChange(change);
version = doc.getVersion().compareTo(version) > 0 ? doc.getVersion() : version;
}
return aggregator.createRemoteEvent(version);
}
use of com.google.firebase.firestore.model.ResourcePath in project firebase-android-sdk by firebase.
the class RemoteSerializer method decodeResourceName.
/**
* Decodes a fully qualified resource name into a resource path and validates that there is a
* project and database encoded in the path. There are no guarantees that a local path is also
* encoded in this resource name.
*/
private ResourcePath decodeResourceName(String encoded) {
ResourcePath resource = ResourcePath.fromString(encoded);
Assert.hardAssert(isValidResourceName(resource), "Tried to deserialize invalid key %s", resource);
return resource;
}
Aggregations