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
    • Resolution: Fixed
    • Minor
    • 2.7.12
    • None
    • 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

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:

                PagerDuty