To use, annotate domain classes with the annotations found in the com.amazonaws.services.dynamodbv2.datamodeling package. A minimal example:
@DynamoDBTable(tableName = "TestTable") public class TestClass { private Long key; private double rangeKey; private Long version; private Set<Integer> integerSetAttribute; @DynamoDBHashKey public Long getKey() { return key; } public void setKey(Long key) { this.key = key; } @DynamoDBRangeKey public double getRangeKey() { return rangeKey; } public void setRangeKey(double rangeKey) { this.rangeKey = rangeKey; } @DynamoDBAttribute(attributeName = "integerSetAttribute") public Set<Integer> getIntegerAttribute() { return integerSetAttribute; } public void setIntegerAttribute(Set<Integer> integerAttribute) { this.integerSetAttribute = integerAttribute; } @DynamoDBVersionAttribute public Long getVersion() { return version; } public void setVersion(Long version) { this.version = version; } }
Save instances of annotated classes to DynamoDB, retrieve them, and delete them using the {@link DynamoDBMapper} class, as in the following example.
DynamoDBMapper mapper = new DynamoDBMapper(dynamoDBClient); Long hashKey = 105L; double rangeKey = 1.0d; TestClass obj = mapper.load(TestClass.class, hashKey, rangeKey); obj.getIntegerAttribute().add(42); mapper.save(obj); mapper.delete(obj);
When using the save, load, and delete methods, {@link DynamoDBMapper} willthrow {@link DynamoDBMappingException}s to indicate that domain classes are incorrectly annotated or otherwise incompatible with this class. Service exceptions will always be propagated as {@link AmazonClientException}, and DynamoDB-specific subclasses such as {@link ConditionalCheckFailedException}will be used when possible.
This class is thread-safe and can be shared between threads. It's also very lightweight, so it doesn't need to be. @see DynamoDBTable @see DynamoDBHashKey @see DynamoDBRangeKey @see DynamoDBAutoGeneratedKey @see DynamoDBAttribute @see DynamoDBVersionAttribute @see DynamoDBIgnore @see DynamoDBMarshalling @see DynamoDBMapperConfig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|