Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ability to serialize Query to Proto (#241)
### 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>
- Loading branch information
1 parent
bde9643
commit bae22e0
Showing
12 changed files
with
553 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.