Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add API to serialize Queries to Proto #241

Merged
merged 3 commits into from Jun 16, 2020

Commits on Jun 16, 2020

  1. feat: ability to serialize Query to Proto

    ### Feature
    Add new methods `toProto` and `fromProto` to Query, allowing
    serialization to and deserialization from RunQueryRequest.
    
    ### Refactoring
    FieldFilter in Query has had a `fromProto` defined on it.
    
    Properties in FieldFilter and corresponding subclasses have been
    refactored to use proto types internally rather than previously using
    high level api types.
    
    Add a new interface FirestoreRpcContext which defines all the methods
    needed by model classes that were only provided by FirestoreImpl.
    FirestoreImpl now implements FirestoreRpcContext, and the new interface
    methods are all the same implementation as before.
    
    All dependency on FirestoreImpl from the following classes has been
    replaced with FirestoreRpcContext:
    * CollectionReference
    * DocumentReference
    * DocumentSnapshot
    * Query
    * QueryDocumentSnapshot
    
    Motivation for this change is due to the fact that we want to expose a
    new method on Query `fromProto` to allow a Query to be loaded from a
    proto. However, Query requires additional context & access to be able
    execute queries and thus has a dependency on a Firestore instance as
    well as those methods now defined in FirestoreRpcContext.
    
    Due to the constraints of Java's type system, the constraint on the
    instance passed to `fromProto` is runtime checked versus compile
    time checked. The method signature accepts any `Firestore` instance, but
    we assert that the instance is also a `FirestoreRpcContext`. This isn't
    ideal as it is a runtime error when not satisfied. However, Firestore is
    annotated @InternalExtensionOnly so we have policy control that the
    instance returned from FirestoreOptions will always also implement
    FirestoreRpcContext.
    
    A test has been added to verify that a proxy instance of FirestoreImpl
    could satisfy the compile and runtime checks present such that use
    should allow the code to work with java ee container based approaches
    using dynamic class proxies for things like instrumentation and
    dependency injection.
    
    As part of the change, the constructors for the above mentioned model
    classes have had their scope narrowed to package private from protected.
    The classes themselves are now also annotated with @InternalExtensionOnly
    along with the note in their Javadoc stating the policy.
    
    clirr rules have been added to ignore the constructor changes in the
    model classes.
    
    Co-authored-by: Sebastian Schmidt <mrschmidt@google.com>
    Co-authored-by: BenWhitehead <BenWhitehead@users.noreply.github.com>
    BenWhitehead and schmidt-sebastian committed Jun 16, 2020
    Copy the full SHA
    62f2866 View commit details
    Browse the repository at this point in the history
  2. format

    BenWhitehead committed Jun 16, 2020
    Copy the full SHA
    6b97130 View commit details
    Browse the repository at this point in the history
  3. fix dependency check

    BenWhitehead committed Jun 16, 2020
    Copy the full SHA
    3058753 View commit details
    Browse the repository at this point in the history