Search in sources :

Example 1 with Target

use of com.google.firestore.v1.Target in project firebase-android-sdk by firebase.

the class SQLiteIndexManager method encodeValues.

/**
 * Encodes the given field values according to the specification in {@code target}. For IN
 * queries, a list of possible values is returned.
 */
@Nullable
private Object[] encodeValues(FieldIndex fieldIndex, Target target, @Nullable Collection<Value> values) {
    if (values == null)
        return null;
    List<IndexByteEncoder> encoders = new ArrayList<>();
    encoders.add(new IndexByteEncoder());
    Iterator<Value> position = values.iterator();
    for (FieldIndex.Segment segment : fieldIndex.getDirectionalSegments()) {
        Value value = position.next();
        for (IndexByteEncoder encoder : encoders) {
            if (isInFilter(target, segment.getFieldPath()) && isArray(value)) {
                encoders = expandIndexValues(encoders, segment, value);
            } else {
                DirectionalIndexByteEncoder directionalEncoder = encoder.forKind(segment.getKind());
                FirestoreIndexValueWriter.INSTANCE.writeIndexValue(value, directionalEncoder);
            }
        }
    }
    return getEncodedBytes(encoders);
}
Also used : FieldIndex(com.google.firebase.firestore.model.FieldIndex) DirectionalIndexByteEncoder(com.google.firebase.firestore.index.DirectionalIndexByteEncoder) ArrayList(java.util.ArrayList) Value(com.google.firestore.v1.Value) DirectionalIndexByteEncoder(com.google.firebase.firestore.index.DirectionalIndexByteEncoder) IndexByteEncoder(com.google.firebase.firestore.index.IndexByteEncoder) Nullable(androidx.annotation.Nullable)

Example 2 with Target

use of com.google.firestore.v1.Target in project firebase-android-sdk by firebase.

the class RemoteSerializerTest method testEncodesFirstLevelKeyQueries.

@Test
public void testEncodesFirstLevelKeyQueries() {
    Query q = Query.atPath(ResourcePath.fromString("docs/1"));
    Target actual = serializer.encodeTarget(new TargetData(q.toTarget(), 1, 2, QueryPurpose.LISTEN));
    DocumentsTarget.Builder docs = DocumentsTarget.newBuilder().addDocuments("projects/p/databases/d/documents/docs/1");
    Target expected = Target.newBuilder().setDocuments(docs).setTargetId(1).setResumeToken(ByteString.EMPTY).build();
    assertEquals(expected, actual);
    assertEquals(serializer.decodeDocumentsTarget(serializer.encodeDocumentsTarget(q.toTarget())), q.toTarget());
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) DocumentsTarget(com.google.firestore.v1.Target.DocumentsTarget) DocumentsTarget(com.google.firestore.v1.Target.DocumentsTarget) Target(com.google.firestore.v1.Target) QueryTarget(com.google.firestore.v1.Target.QueryTarget) StructuredQuery(com.google.firestore.v1.StructuredQuery) Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 3 with Target

use of com.google.firestore.v1.Target in project firebase-android-sdk by firebase.

the class RemoteSerializerTest method testEncodesFirstLevelAncestorQueries.

@Test
public void testEncodesFirstLevelAncestorQueries() {
    Query q = Query.atPath(ResourcePath.fromString("messages"));
    Target actual = serializer.encodeTarget(wrapTargetData(q));
    StructuredQuery.Builder structuredQueryBuilder = StructuredQuery.newBuilder().addFrom(CollectionSelector.newBuilder().setCollectionId("messages")).addOrderBy(defaultKeyOrder());
    QueryTarget.Builder queryBuilder = QueryTarget.newBuilder().setParent("projects/p/databases/d/documents").setStructuredQuery(structuredQueryBuilder);
    Target expected = Target.newBuilder().setQuery(queryBuilder).setTargetId(1).setResumeToken(ByteString.EMPTY).build();
    assertEquals(expected, actual);
    assertEquals(serializer.decodeQueryTarget(serializer.encodeQueryTarget(q.toTarget())), q.toTarget());
}
Also used : StructuredQuery(com.google.firestore.v1.StructuredQuery) QueryTarget(com.google.firestore.v1.Target.QueryTarget) DocumentsTarget(com.google.firestore.v1.Target.DocumentsTarget) Target(com.google.firestore.v1.Target) QueryTarget(com.google.firestore.v1.Target.QueryTarget) StructuredQuery(com.google.firestore.v1.StructuredQuery) Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 4 with Target

use of com.google.firestore.v1.Target in project firebase-android-sdk by firebase.

the class RemoteSerializerTest method testEncodesSortOrders.

@Test
public void testEncodesSortOrders() {
    Query q = Query.atPath(ResourcePath.fromString("docs")).orderBy(orderBy("prop"));
    Target actual = serializer.encodeTarget(wrapTargetData(q));
    StructuredQuery.Builder structuredQueryBuilder = StructuredQuery.newBuilder().addFrom(CollectionSelector.newBuilder().setCollectionId("docs")).addOrderBy(Order.newBuilder().setDirection(Direction.ASCENDING).setField(FieldReference.newBuilder().setFieldPath("prop"))).addOrderBy(defaultKeyOrder());
    QueryTarget.Builder queryBuilder = QueryTarget.newBuilder().setParent("projects/p/databases/d/documents").setStructuredQuery(structuredQueryBuilder);
    Target expected = Target.newBuilder().setQuery(queryBuilder).setTargetId(1).setResumeToken(ByteString.EMPTY).build();
    assertEquals(expected, actual);
    assertEquals(serializer.decodeQueryTarget(serializer.encodeQueryTarget(q.toTarget())), q.toTarget());
}
Also used : StructuredQuery(com.google.firestore.v1.StructuredQuery) QueryTarget(com.google.firestore.v1.Target.QueryTarget) DocumentsTarget(com.google.firestore.v1.Target.DocumentsTarget) Target(com.google.firestore.v1.Target) QueryTarget(com.google.firestore.v1.Target.QueryTarget) StructuredQuery(com.google.firestore.v1.StructuredQuery) Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 5 with Target

use of com.google.firestore.v1.Target in project firebase-android-sdk by firebase.

the class RemoteSerializerTest method testEncodesResumeTokens.

@Test
public void testEncodesResumeTokens() {
    Query q = Query.atPath(ResourcePath.fromString("docs"));
    TargetData targetData = new TargetData(q.toTarget(), 1, 2, QueryPurpose.LISTEN).withResumeToken(TestUtil.resumeToken(1000), SnapshotVersion.NONE);
    Target actual = serializer.encodeTarget(targetData);
    StructuredQuery.Builder structuredQueryBuilder = StructuredQuery.newBuilder().addFrom(CollectionSelector.newBuilder().setCollectionId("docs")).addOrderBy(defaultKeyOrder());
    QueryTarget.Builder queryBuilder = QueryTarget.newBuilder().setParent("projects/p/databases/d/documents").setStructuredQuery(structuredQueryBuilder);
    Target expected = Target.newBuilder().setQuery(queryBuilder).setTargetId(1).setResumeToken(TestUtil.resumeToken(1000)).build();
    assertEquals(expected, actual);
    assertEquals(serializer.decodeQueryTarget(serializer.encodeQueryTarget(q.toTarget())), q.toTarget());
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) StructuredQuery(com.google.firestore.v1.StructuredQuery) QueryTarget(com.google.firestore.v1.Target.QueryTarget) DocumentsTarget(com.google.firestore.v1.Target.DocumentsTarget) Target(com.google.firestore.v1.Target) QueryTarget(com.google.firestore.v1.Target.QueryTarget) StructuredQuery(com.google.firestore.v1.StructuredQuery) Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Aggregations

StructuredQuery (com.google.firestore.v1.StructuredQuery)14 QueryTarget (com.google.firestore.v1.Target.QueryTarget)14 Test (org.junit.Test)14 Query (com.google.firebase.firestore.core.Query)13 Target (com.google.firestore.v1.Target)13 DocumentsTarget (com.google.firestore.v1.Target.DocumentsTarget)13 FieldIndex (com.google.firebase.firestore.model.FieldIndex)4 Value (com.google.firestore.v1.Value)4 TargetData (com.google.firebase.firestore.local.TargetData)3 Nullable (androidx.annotation.Nullable)2 Target (com.github.zhenwei.core.asn1.x509.Target)2 TargetInformation (com.github.zhenwei.core.asn1.x509.TargetInformation)2 Targets (com.github.zhenwei.core.asn1.x509.Targets)2 DocumentKey (com.google.firebase.firestore.model.DocumentKey)2 Status (io.grpc.Status)2 ArrayList (java.util.ArrayList)2 ASN1InputStream (com.github.zhenwei.core.asn1.ASN1InputStream)1 DEROctetString (com.github.zhenwei.core.asn1.DEROctetString)1 Extension (com.github.zhenwei.core.asn1.x509.Extension)1 X509AttributeCertificateHolder (com.github.zhenwei.pkix.cert.X509AttributeCertificateHolder)1