Details
-
Improvement
-
Resolution: Fixed
-
Minor
-
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
- is parent task of
-
JCBC-1622 Repository should search for meta-annotations
- Resolved