-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Enhance support for linking documents. #3647
Closed
Closed
Conversation
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
christophstrobl
force-pushed
the
issue/3602
branch
from
May 17, 2021 11:34
6c78727
to
026f98f
Compare
Add initial support for an alternative to the existing DBRef scenario. The enhancement allows to store and retrieve linked entites via their id or a customizable lookup query.
…query. Simplify usage by computing the pointer from the lookup. Update the reference documentation, add JavaDoc and refine API.
Rename ReferenceReader to ReferenceLookupDelegate. Rename LazyLoadingProxyGenerator to LazyLoadingProxyFactory. Rename DefaultReferenceLoader to MongoDatabaseFactoryReferenceLoader. Reduce scope of LookupFunction and move it to ReferenceLookupDelegate. Extract some checks into methods to reflect the underlying concepts. Simplify code, convert variables to constants where possible.
Also allow direct usage of (at)Reference from data commons to define associations.
christophstrobl
force-pushed
the
issue/3602
branch
from
May 20, 2021 10:25
de55ada
to
eb08e79
Compare
mp911de
added a commit
that referenced
this pull request
May 21, 2021
Rename ReferenceReader to ReferenceLookupDelegate. Rename LazyLoadingProxyGenerator to LazyLoadingProxyFactory. Rename DefaultReferenceLoader to MongoDatabaseFactoryReferenceLoader. Reduce scope of LookupFunction and move it to ReferenceLookupDelegate. Extract some checks into methods to reflect the underlying concepts. Simplify code, convert variables to constants where possible. Original pull request: #3647. Closes #3602.
That's merged and polished now. |
(Manually link because nobody linked these two related things) |
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Using
@DocumentReference
offers an alternative way of linking entities in MongoDB. While the goal is the same as when using@DBRef
, the store representation is different. Document references, do not follow a specific format. They can be literally anything, a single value, an entire document, basically everything that can be stored in MongoDB.By default, the mapping layer will use the referenced entities id value for storage and retrieval, like in the sample below.
The sample above uses an
_id
based fetch query ({ '_id' : ?#{#target} }
) for data retrieval and resolves linked entities eagerly.@DocumentReference(lookup=...)
allows to define custom queries that are independent from the_id
field and therefore offer a flexible way of defining links between entities as demonstrated in the sample below, where thePublisher
of a book is referenced by its acronym instead of the internalid
.The above snipped shows the reading side of things when working with custom linked objects. To make the writing part aware of the modified document pointer a custom converter, capable of the transformation into a
DocumentPointer
, like the one below, needs to be registered.