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

Introduce ability to append queries against a particular collection [DATAMONGO-1151] #2067

Open
spring-projects-issues opened this issue Jan 28, 2015 · 6 comments
Assignees
Labels
in: core Issues in core support in: repository Repositories abstraction status: pending-design-work Needs design work before any code can be developed type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link

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

@spring-projects-issues
Copy link
Author

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?

@spring-projects-issues
Copy link
Author

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 @Augmentor(MyImpl.class) would be a good solution on entity class (collection) level.
In my initial request I wanted to go for sure that there is no existing solution for my particular use case - seems to be not, but good to hear that it is planned.

SpEL would work for me too, but I'd although have to augment wach query explicitely

@spring-projects-issues
Copy link
Author

Heiko Scherrer commented

Do you plan a solution for all this in 2.0? I'd like to contribute!

@spring-projects-issues
Copy link
Author

Heiko Scherrer commented

see comments

@spring-projects-issues spring-projects-issues added in: repository Repositories abstraction type: enhancement A general enhancement in: core Issues in core support labels Dec 30, 2020
@arpanpreneur
Copy link

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?

@christophstrobl
Copy link
Member

@ArpanKIIT2017 Every repository query will be run by the template, though there's no easy way to work with the QueryMapper that is used. Nor is there support for augmenting the query, which is as you already know an open issue in data-commons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core support in: repository Repositories abstraction status: pending-design-work Needs design work before any code can be developed type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants