Skip to content

Commit 3276dde

Browse files
authored
Add sample code for DDB enhanced client (#3354)
1 parent b9d58c1 commit 3276dde

File tree

6 files changed

+175
-0
lines changed

6 files changed

+175
-0
lines changed

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/mapper/annotations/DynamoDbAttribute.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@
2525
* Used to explicitly designate a field or getter or setter to participate as an attribute in the mapped database
2626
* object with a custom name. A string value must be specified to specify a different name for the attribute than the
2727
* mapper would automatically infer using a naming strategy.
28+
*
29+
* <p>
30+
* Example using {@link DynamoDbAttribute}:
31+
* <pre>
32+
* {@code
33+
* @DynamoDbBean
34+
* public class Bean {
35+
* private String internalKey;
36+
*
37+
* @DynamoDbAttribute("renamedInternalKey")
38+
* public String getInternalKey() {
39+
* return this.internalKey;
40+
* }
41+
*
42+
* public void setInternalKey(String internalKey) {
43+
* return this.internalKey = internalKey;}
44+
* }
45+
* }
46+
* }
47+
* </pre>
2848
*/
2949
@Target({ElementType.METHOD})
3050
@Retention(RetentionPolicy.RUNTIME)

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/mapper/annotations/DynamoDbBean.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,33 @@
5252
* (converterProviders = {CustomAttributeConverter.class, DefaultAttributeConverterProvider.class});
5353
* }
5454
* </pre>
55+
* <p>
56+
* Example using {@link DynamoDbBean}:
57+
* <pre>
58+
* {@code
59+
* @DynamoDbBean
60+
* public class Customer {
61+
* private String id;
62+
* private Instant createdOn;
63+
*
64+
* @DynamoDbPartitionKey
65+
* public String getId() {
66+
* return this.id;
67+
* }
68+
*
69+
* public void setId(String id) {
70+
* this.name = id;
71+
* }
72+
*
73+
* public Instant getCreatedOn() {
74+
* return this.createdOn;
75+
* }
76+
* public void setCreatedOn(Instant createdOn) {
77+
* this.createdOn = createdOn;
78+
* }
79+
* }
80+
* }
81+
* </pre>
5582
*/
5683
@Target({ElementType.TYPE})
5784
@Retention(RetentionPolicy.RUNTIME)

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/mapper/annotations/DynamoDbIgnore.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,25 @@
2323

2424
/**
2525
* Opts this attribute out of participating in the table schema. It will be completely ignored by the mapper.
26+
* <p>
27+
* Example using {@link DynamoDbAttribute}:
28+
* <pre>
29+
* {@code
30+
* @DynamoDbBean
31+
* public class Bean {
32+
* private String internalKey;
33+
*
34+
* @DynamoDbIgnore
35+
* public String getInternalKey() {
36+
* return this.internalKey;
37+
* }
38+
*
39+
* public void setInternalKey(String internalKey) {
40+
* return this.internalKey = internalKey;}
41+
* }
42+
* }
43+
* }
44+
* </pre>
2645
*/
2746
@Target({ElementType.METHOD})
2847
@Retention(RetentionPolicy.RUNTIME)

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/mapper/annotations/DynamoDbImmutable.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,59 @@
5252
* (converterProviders = {CustomAttributeConverter.class, DefaultAttributeConverterProvider.class});
5353
* }
5454
* </pre>
55+
*
56+
* <p>
57+
* Example using {@link DynamoDbImmutable}:
58+
* <pre>
59+
* {@code
60+
* @DynamoDbImmutable(builder = Customer.Builder.class)
61+
* public class Customer {
62+
* private final String accountId;
63+
* private final int subId;
64+
* private final String name;
65+
* private final Instant createdDate;
66+
*
67+
* private Customer(Builder b) {
68+
* this.accountId = b.accountId;
69+
* this.subId = b.subId;
70+
* this.name = b.name;
71+
* this.createdDate = b.createdDate;
72+
* }
73+
*
74+
* // This method will be automatically discovered and used by the TableSchema
75+
* public static Builder builder() { return new Builder(); }
76+
*
77+
* @DynamoDbPartitionKey
78+
* public String accountId() { return this.accountId; }
79+
*
80+
* @DynamoDbSortKey
81+
* public int subId() { return this.subId; }
82+
*
83+
* @DynamoDbSecondaryPartitionKey(indexNames = "customers_by_name")
84+
* public String name() { return this.name; }
85+
*
86+
* @DynamoDbSecondarySortKey(indexNames = {"customers_by_date", "customers_by_name"})
87+
* public Instant createdDate() { return this.createdDate; }
88+
*
89+
* public static final class Builder {
90+
* private String accountId;
91+
* private int subId;
92+
* private String name;
93+
* private Instant createdDate;
94+
*
95+
* private Builder() {}
96+
*
97+
* public Builder accountId(String accountId) { this.accountId = accountId; return this; }
98+
* public Builder subId(int subId) { this.subId = subId; return this; }
99+
* public Builder name(String name) { this.name = name; return this; }
100+
* public Builder createdDate(Instant createdDate) { this.createdDate = createdDate; return this; }
101+
*
102+
* // This method will be automatically discovered and used by the TableSchema
103+
* public Customer build() { return new Customer(this); }
104+
* }
105+
* }
106+
* }
107+
* </pre>
55108
*/
56109
@Target({ElementType.TYPE})
57110
@Retention(RetentionPolicy.RUNTIME)

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/mapper/annotations/DynamoDbPartitionKey.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,34 @@
2525
/**
2626
* Denotes this attribute as being the primary partition key of the DynamoDb table. This attribute must map to a
2727
* DynamoDb scalar type (string, number or binary) to be valid. Every mapped table schema must have exactly one of these.
28+
*
29+
* <p>
30+
* Example using {@link DynamoDbPartitionKey}:
31+
* <pre>
32+
* {@code
33+
* @DynamoDbBean
34+
* public class Customer {
35+
* private String id;
36+
* private Instant createdOn;
37+
*
38+
* @DynamoDbPartitionKey
39+
* public String getId() {
40+
* return this.id;
41+
* }
42+
*
43+
* public void setId(String id) {
44+
* this.name = id;
45+
* }
46+
*
47+
* public Instant getCreatedOn() {
48+
* return this.createdOn;
49+
* }
50+
* public void setCreatedOn(Instant createdOn) {
51+
* this.createdOn = createdOn;
52+
* }
53+
* }
54+
* }
55+
* </pre>
2856
*/
2957
@SdkPublicApi
3058
@Target({ElementType.METHOD})

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/mapper/annotations/DynamoDbSortKey.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,34 @@
2525
/**
2626
* Denotes this attribute as being the optional primary sort key of the DynamoDb table. This attribute must map to a
2727
* DynamoDb scalar type (string, number or binary) to be valid.
28+
*
29+
* Example using {@link DynamoDbSortKey}:
30+
* <pre>
31+
* {@code
32+
* @DynamoDbBean
33+
* public class Customer {
34+
* private String accountId;
35+
* private int subId;
36+
*
37+
* @DynamoDbPartitionKey
38+
* public String getAccountId() {
39+
* return this.accountId;
40+
* }
41+
*
42+
* public void setAccountId(String accountId) {
43+
* this.accountId = accountId;
44+
* }
45+
*
46+
* @DynamoDbSortKey
47+
* public int getSubId() {
48+
* return this.subId;
49+
* }
50+
* public void setSubId(int subId) {
51+
* this.subId = subId;
52+
* }
53+
* }
54+
* }
55+
* </pre>
2856
*/
2957
@SdkPublicApi
3058
@Target({ElementType.METHOD})

0 commit comments

Comments
 (0)