use of com.google.firebase.firestore.model.ResourcePath in project firebase-android-sdk by firebase.
the class RemoteSerializer method decodeKey.
public DocumentKey decodeKey(String name) {
ResourcePath resource = decodeResourceName(name);
Assert.hardAssert(resource.getSegment(1).equals(databaseId.getProjectId()), "Tried to deserialize key from different project.");
Assert.hardAssert(resource.getSegment(3).equals(databaseId.getDatabaseId()), "Tried to deserialize key from different database.");
return DocumentKey.fromPath(extractLocalPathFromResourceName(resource));
}
use of com.google.firebase.firestore.model.ResourcePath in project firebase-android-sdk by firebase.
the class SQLiteSchemaTest method usesMultipleBatchesToAddPathLengths.
@Test
public void usesMultipleBatchesToAddPathLengths() {
schema.runSchemaUpgrades(0, 12);
for (int i = 0; i < SQLiteSchema.MIGRATION_BATCH_SIZE + 1; ++i) {
ResourcePath path = path(String.format("coll/doc%03d", i));
db.execSQL("INSERT INTO remote_documents (path) VALUES (?)", new Object[] { EncodedPath.encode(path) });
}
schema.runSchemaUpgrades(12, 13);
int[] current = new int[] { 0 };
new SQLitePersistence.Query(db, "SELECT path_length FROM remote_documents ORDER by path").forEach(cursor -> {
assertEquals(2, cursor.getInt(0));
++current[0];
});
assertEquals(SQLiteSchema.MIGRATION_BATCH_SIZE + 1, current[0]);
}
use of com.google.firebase.firestore.model.ResourcePath in project firebase-android-sdk by firebase.
the class SQLiteSchemaTest method addPathLengths.
@Test
public void addPathLengths() {
schema.runSchemaUpgrades(0, 12);
ResourcePath[] paths = new ResourcePath[] { path("collA/doc"), path("collA/doc/collB/doc") };
for (ResourcePath path : paths) {
db.execSQL("INSERT INTO remote_documents (path, read_time_seconds, read_time_nanos, contents) VALUES (?, ?, ?, ?)", new Object[] { EncodedPath.encode(path) });
}
schema.runSchemaUpgrades(12, 13);
int[] current = new int[] { 0 };
new SQLitePersistence.Query(db, "SELECT path_length FROM remote_documents ORDER BY path").forEach(cursor -> {
assertEquals(paths[current[0]].length(), cursor.getInt(0));
++current[0];
});
assertEquals(2, current[0]);
}
use of com.google.firebase.firestore.model.ResourcePath in project firebase-android-sdk by firebase.
the class RemoteDocumentCacheTestCase method testGetAllFromSinceReadTimeAndSeconds.
@Test
public void testGetAllFromSinceReadTimeAndSeconds() {
addTestDocumentAtPath("b/old", /* updateTime= */
1, /* readTime= */
11);
addTestDocumentAtPath("b/current", /* updateTime= */
2, /* readTime= = */
12);
addTestDocumentAtPath("b/new", /* updateTime= */
3, /* readTime= = */
13);
ResourcePath collection = path("b");
Map<DocumentKey, MutableDocument> results = remoteDocumentCache.getAll(collection, IndexOffset.createSuccessor(version(12), -1));
assertThat(results.values()).containsExactly(doc("b/new", 3, DOC_DATA));
}
use of com.google.firebase.firestore.model.ResourcePath in project firebase-android-sdk by firebase.
the class Query method parseDocumentIdValue.
/**
* Parses the given documentIdValue into a ReferenceValue, throwing appropriate errors if the
* value is anything other than a DocumentReference or String, or if the string is malformed.
*/
private Value parseDocumentIdValue(Object documentIdValue) {
if (documentIdValue instanceof String) {
String documentId = (String) documentIdValue;
if (documentId.isEmpty()) {
throw new IllegalArgumentException("Invalid query. When querying with FieldPath.documentId() you must provide a valid " + "document ID, but it was an empty string.");
}
if (!query.isCollectionGroupQuery() && documentId.contains("/")) {
throw new IllegalArgumentException("Invalid query. When querying a collection by FieldPath.documentId() you must " + "provide a plain document ID, but '" + documentId + "' contains a '/' character.");
}
ResourcePath path = query.getPath().append(ResourcePath.fromString(documentId));
if (!DocumentKey.isDocumentKey(path)) {
throw new IllegalArgumentException("Invalid query. When querying a collection group by FieldPath.documentId(), the " + "value provided must result in a valid document path, but '" + path + "' is not because it has an odd number of segments (" + path.length() + ").");
}
return Values.refValue(this.getFirestore().getDatabaseId(), DocumentKey.fromPath(path));
} else if (documentIdValue instanceof DocumentReference) {
DocumentReference ref = (DocumentReference) documentIdValue;
return Values.refValue(this.getFirestore().getDatabaseId(), ref.getKey());
} else {
throw new IllegalArgumentException("Invalid query. When querying with FieldPath.documentId() you must provide a valid " + "String or DocumentReference, but it was of type: " + Util.typeName(documentIdValue));
}
}
Aggregations