-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Introduce ability to append queries against a particular collection [DATAMONGO-1151] #2067
Comments
Oliver Drotbohm commented In Spring Data Commons, we're currently investigating what we call a query augmentation engine that provides an SPI to augment (as the name suggests) store interaction of different kinds. As a working prototype we use the scenario of soft-deletes as it's kind of sophisticated as it not only needs query augmentation but complete exchanges of persistence operations (a delete turning into an update etc.). You use case (multi-tenancy) sounds very similar and also closely related to the usage of SpEL to implement security constraints we already support in Spring Data JPA. Let's assume you'd use the repository abstraction, what kind of mechanism would you prefer to express your custom augmentation? Would - such as in the case of soft deletes - an annotation on the repository work? |
Heiko Scherrer commented Thanks for clarification. An annotation on Repository level would work for me but I guess many requests will follow - Think about inheritance. An SpEL would work for me too, but I'd although have to augment wach query explicitely |
Heiko Scherrer commented Do you plan a solution for all this in 2.0? I'd like to contribute! |
Heiko Scherrer commented see comments |
Is there any updates on this? Even I need the tenantId based multi-tenancy support. We figured it is too confusing to find a place to append the extra criteria. Just wanted to understand, does implementing a mongo template also automatically scope the autogenerated queries from arbitrary interface method names? |
@ArpanKIIT2017 Every repository query will be run by the template, though there's no easy way to work with the |
Heiko Scherrer opened DATAMONGO-1151 and commented
Task description
I request a feature that I couldn't find in the current implementation. Probably there's another elegant way to solve the requested behaviour. I need to append all queries to a particular collection with a specific criteria. Think about a multi-tenancy scenario where a discriminator property (holding the tenants name) has to be compared in each query. Doing this within application code is cumbersome and error-prone. IMO this should be applied somewhere deep in the framework, at best near to execution.
Investigation
I had a look at MongoTemplate and implemented a solution with a so called QueryAppender, that is able to add a criteria to a query (for a collection). Unfortunately MongoTemplate uses several alternatives within the finder methods. Some work with Query, others with DBObjects. So before opening Pandoras Box and implementing too many changes within MongoTemplate, I wanted to clarify that my approach might be a solution and no other solution already exists.
Affects: 1.6.2 (Evans SR2)
Issue Links:
DATACMNS-293 Add infrastructure for generic query augmentation
("depends on")
DATAJPA-307 Add support for soft deletes
DATAJPA-564 Support for SpEL based parameter expressions in repository query methods
The text was updated successfully, but these errors were encountered: