spring-data-couchbase icon indicating copy to clipboard operation
spring-data-couchbase copied to clipboard

Ability to append mutliple attributes along with `_class` to each query [DATACOUCH-464]

Open spring-projects-issues opened this issue 6 years ago • 8 comments

UmairYasin opened DATACOUCH-464 and commented

 I am using document based multi tenant approach where each document in couchbase db have tenant-ID field. Now for all the queries that are executing in my application, i want extend tenant-ID to it which is present in Session Context One solution is to manually add the tenant-id clause to every query but this solution is not very optimal as i want to enforce that no query in applicaion should be executed without tenant-id.

There should be a way to extend couchbase base configuration to add tenant-id like the same way it is adding _class attribute to every query


Affects: 3.1.9 (Lovelace SR9)

spring-projects-issues avatar Jul 22 '19 19:07 spring-projects-issues

UmairYasin commented

David Nault - Can you please let me know if this is feasible to implement with spring data couchbase? If yes then let me know please so i can try and create a PR for this. Thanks

spring-projects-issues avatar Jul 24 '19 07:07 spring-projects-issues

David Nault commented

Assigning to David Kelly, new maintainer

spring-projects-issues avatar Jul 24 '19 15:07 spring-projects-issues

David Kelly commented

I'm thinking that this is a feature we could add, but in fact something that should cover this is coming.  There was a recent blog post which mentioned the coming 'collections' feature.  Though it is .net, it will be in java too.  We will add the support for that in spring data as well.   There may be other mentions of it, some with more detail, over in our blogs

spring-projects-issues avatar Jul 24 '19 23:07 spring-projects-issues

UmairYasin commented

Kelly - Can you please let me know the expected release date of stable couchbase 6.5 and related SDK's? Thanks

spring-projects-issues avatar Jul 29 '19 07:07 spring-projects-issues

Matt Ingenthron commented

As of this writing, expected to be toward the end of 2019.   Spring support would follow after that, aligned to Spring's release

spring-projects-issues avatar Sep 19 '19 14:09 spring-projects-issues

Michael Reiche commented

https://jira.spring.io/browse/DATACOUCH-525 will allow specifying a field other than _class, and a value other than the name of the class. (i.e. a mapper could replace _class = 'com.example.domain.Person' with  t='Person'), but this request seems to be beyond that and will need additional work

spring-projects-issues avatar May 13 '20 00:05 spring-projects-issues

Michael Reiche commented

The getTypeAlias(TypeInformation<?> info) method takes only a TypeInformation object - which does not contain any query data, so this mechanism cannot be used for partitioning multi-tenant data. Partitioning on Bucket or Collection are other options.

However - the id can be constructed from multiple prefixes, multiple attributes (or a generated UUID), and multiple suffixes - all of which are fields from the entity - for example this uses the value of the 'company' field as the prefix (for multi-tenant, possibly).  Queries would need to include the predicate (meta().id like ( company || '.%')).  (the period is the delimiter).   When a field is used as a prefix/suffix of the id, it is not included in the content (attributes are included in the content).

@Id
@GeneratedValue(strategy = GenerationStrategy.UNIQUE)
String id;  
@IdPrefix
String company;

  |Person : { id : Shuster.362e1bc3-e4c2-4f58-ac66-6c69d2f95fb4, firstname=Dwight, middlename : David, lastname='Smith', version : 1592605700734189568, },|

spring-projects-issues avatar Jun 16 '20 21:06 spring-projects-issues

Michael Reiche commented

This might be a good case for a custom mapper

spring-projects-issues avatar Jun 23 '20 18:06 spring-projects-issues

scope should be used to separate tenant data.

mikereiche avatar Aug 17 '22 14:08 mikereiche

i want to enforce that no query in applicaion should be executed without tenant-id

That is not sufficient for compartmentalizing data. Data should be compartmentalized with authorization, not just a convention.

mikereiche avatar Aug 17 '22 14:08 mikereiche