Uploaded image for project: 'Couchbase Java Client'
  1. Couchbase Java Client
  2. JCBC-1544

Allow spring data couchbase annotations to be used in meta-annotation context

    XMLWordPrintable

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 2.7.12
    • None
    • None
    • 1

    Description

      As a developer, I want to be able to easily choose between using Couchbase or other simplar repositories that all use the same document and change the implementing repository at runtime, for example by profile configuration. This can be achieved by adding annotations required by each repository implementation to each field in the document.

       

      For example, if I wanted to support both Couchbase and DynamoDB, I might have the following

       

      class Entity {
       
         @Id
         @DynamoDBHashKey
         @DynamoDBAutoGeneratedKey
         public String id;
       
         @Field
         @DynamoDBAttribute
         public String field1;
       
         @Field
         @DynamoDBAttribute
         public String field2;
      }
      
      

      The annotation on the field is repetitive. (The same idea applies to the ID if I have multiple entity definitions).

       

      To eliminate the repetition and reduce the opportunity for defects, I would like to be able to define my own annotation, for example:

       @Id
       @DynamoDBHashKey
       @DynamoDBAutoGeneratedKey
       @Retention(RetentionPolicy.RUNTIME)
       @Target({ ElementType.FIELD })
       public @interface MyId {}
       
      AND
       
       @Field
       @DynamoDBAttribute
       public @interface MyField {}

       

      Then, I an write the simpler

       

      class Entity {
       
       @MyId
       public String id;
       
       @MyField
       public String field1;
       
       @MyField
       public String field2;
      }
       

      This is currently not possible because the target for the annotations only permits fields, but it is trivial to change.

       

      NOTE While this is not my current use case, it would also be possible to use this capability to create combinations that include JSR 380 annotations (for example @NotNull), again for the objective of not repeating yourself.

       

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            Thanks for the request Garret Fick! Note that we actually work inside the Spring JIRA (https://jira.spring.io/projects/DATACOUCH/) for items on that project. JCBC tracks just the Java SDK itself.

            David Kelly: passing to you to figure out how best to track this request.

            ingenthr Matt Ingenthron added a comment - Thanks for the request Garret Fick ! Note that we actually work inside the Spring JIRA ( https://jira.spring.io/projects/DATACOUCH/ ) for items on that project. JCBC tracks just the Java SDK itself. David Kelly : passing to you to figure out how best to track this request.

            People

              david.kelly David Kelly
              garretfick Garret Fick
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty