@Retention(value=RUNTIME) @Target(value={TYPE,FIELD,METHOD,ANNOTATION_TYPE}) public @interface DynamoDBAutoGenerated
May be annotated on a user-defined annotation to pass additional
properties to the DynamoDBAutoGenerator
.
@DynamoDBHashKey @CustomGeneratedKey(prefix="test-") //<- user-defined annotation public String getKey()
Where,
@DynamoDBAutoGenerated(generator=CustomGeneratedKey.Generator.class) @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) public @interface CustomGeneratedKey { String prefix() default ""; public static class Generator implements DynamoDBAutoGenerator<String> { private final String prefix; public Generator(final Class<String> targetType, final CustomGeneratedKey annotation) { this.prefix = annotation.prefix(); } public Generator() { //<- required if annotating directly this.prefix = ""; } @Override public DynamoDBAutoGenerateStrategy getGenerateStrategy() { return DynamoDBAutoGenerateStrategy.CREATE; } @Override public final String generate(final String currentValue) { return prefix + UUID.randomUUID.toString(); } } }
Alternately, the property/field may be annotated directly (which requires the generator to provide a default constructor),
@DynamoDBAutoGenerated(generator=CustomGeneratedKey.Generator.class) public String getKey()
May be used as a meta-annotation.
Modifier and Type | Required Element and Description |
---|---|
Class<? extends DynamoDBAutoGenerator> |
generator
The auto-generator class for this property.
|
public abstract Class<? extends DynamoDBAutoGenerator> generator
Copyright © 2020. All rights reserved.