@Retention(value=RUNTIME) @Target(value={FIELD,METHOD,ANNOTATION_TYPE}) public @interface DynamoDBAutoGenerated
DynamoDBAutoGenerator.
A minimal example using getter annotations,
@DynamoDBTable(tableName="TestTable")
public class TestClass {
private String key, value;
@DynamoDBHashKey
@CustomGeneratedKey(prefix="test-") //<- user-defined annotation
public String getKey() { return this.key; }
public void setKey(String key) { this.key = key; }
public String getValue() { return this.value; }
public void setValue(String value) { this.value = value; }
}
And user-defined annotation,
@DynamoDBAutoGenerated(generator=CustomGeneratedKey.Generator.class)
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface CustomGeneratedKey {
String prefix() default "";
public static final class Generator implements DynamoDBAutoGenerator<String> {
private final String prefix;
public Generator(final CustomGeneratedKey annotation) {
this.prefix = annotation.prefix();
}
public Generator() {
this.prefix = "";
}
@Override
public DynamoDBAutoGenerateStrategy getGenerateStrategy() {
return DynamoDBAutoGenerateStrategy.CREATE;
}
@Override
public final T generate(final T currentValue) {
return prefix + UUID.randomUUID.toString();
}
}
}
Alternatively, the property/field may be annotated directly (which requires
the generator to provide a default constructor),
@DynamoDBHashKey
@DynamoDBAutoGenerated(generator=CustomGeneratedKey.Generator.class)
public String getKey() { return this.key; }
| 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 © 2016. All rights reserved.