@@ -41,18 +41,26 @@ values used are also completely arbitrary.
41
41
class itself, or somewhere else :-
42
42
``` java
43
43
static final TableSchema<Customer > CUSTOMER_TABLE_SCHEMA =
44
- TableSchema . builder()
44
+ StaticTableSchema . builder()
45
45
.newItemSupplier(Customer :: new ) // Tells the mapper how to make new objects when reading items
46
46
.attributes(
47
- string(" account_id" , Customer :: getAccountId, Customer :: setAccountId)
47
+ stringAttribute(" account_id" ,
48
+ Customer :: getAccountId,
49
+ Customer :: setAccountId)
48
50
.as(primaryPartitionKey()), // primary partition key
49
- integerNumber(" sub_id" , Customer :: getSubId, Customer :: setSubId)
51
+ integerNumberAttribute(" sub_id" ,
52
+ Customer :: getSubId,
53
+ Customer :: setSubId)
50
54
.as(primarySortKey()), // primary sort key
51
- string(" name" , Customer :: getName, Customer :: setName)
55
+ stringAttribute(" name" ,
56
+ Customer :: getName,
57
+ Customer :: setName)
52
58
.as(secondaryPartitionKey(" customers_by_name" )), // GSI partition key
53
- string(" created_date" , Customer :: getCreatedDate, Customer :: setCreatedDate)
54
- .as(secondarySortKey(" customers_by_date" ), secondarySortKey(" customers_by_name" )) // Sort key for both the LSI and the GSI
55
- )
59
+ stringAttribute(" created_date" ,
60
+ Customer :: getCreatedDate,
61
+ Customer :: setCreatedDate)
62
+ .as(secondarySortKey(" customers_by_date" ),
63
+ secondarySortKey(" customers_by_name" ))) // Sort key for both the LSI and the GSI
56
64
.build();
57
65
```
58
66
@@ -82,36 +90,50 @@ available in the low-level DynamoDB SDK client.
82
90
customerTable. execute(CreateTable . create());
83
91
84
92
// GetItem
85
- Customer customer = customerTable. execute(GetItem . of (Key . of (stringValue(" a123" ))));
93
+ Customer customer = customerTable. execute(GetItem . create (Key . create (stringValue(" a123" ))));
86
94
87
95
// UpdateItem
88
- Customer updatedCustomer = customerTable. execute(UpdateItem . of (customer));
96
+ Customer updatedCustomer = customerTable. execute(UpdateItem . create (customer));
89
97
90
98
// PutItem
91
- customerTable. execute(PutItem . of (customer));
99
+ customerTable. execute(PutItem . create (customer));
92
100
93
101
// DeleteItem
94
- Customer deletedCustomer = customerTable. execute(DeleteItem . of (Key . of (stringValue(" a123" ), numberValue(456 ))));
102
+ Customer deletedCustomer = customerTable. execute(DeleteItem . create (Key . create (stringValue(" a123" ), numberValue(456 ))));
95
103
96
104
// Query
97
- Iterable<Page<Customer > > customers = customerTable. execute(Query . of (equalTo(Key . of (stringValue(" a123" )))));
105
+ Iterable<Page<Customer > > customers = customerTable. execute(Query . create (equalTo(Key . create (stringValue(" a123" )))));
98
106
99
107
// Scan
100
108
Iterable<Page<Customer > > customers = customerTable. execute(Scan . create());
101
109
102
110
// BatchGetItem
103
- batchResults = database. execute(BatchGetItem . of(ReadBatch . of(customerTable, GetItem . of(key1), GetItem . of(key2), GetItem . of(key3)));
111
+ batchResults = database. execute(
112
+ BatchGetItem . create(
113
+ ReadBatch . create(customerTable,
114
+ GetItem . create(key1),
115
+ GetItem . create(key2),
116
+ GetItem . create(key3))));
104
117
105
118
// BatchWriteItem
106
- batchResults = database. execute(BatchWriteItem . of(WriteBatch . of(customerTable, PutItem . of(item), DeleteItem . of(key1), DeleteItem . of(key2))));
119
+ batchResults = database. execute(
120
+ BatchWriteItem . create(
121
+ WriteBatch . create(customerTable,
122
+ PutItem . create(item),
123
+ DeleteItem . create(key1),
124
+ DeleteItem . create(key2))));
107
125
108
126
// TransactGetItems
109
- transactResults = mappedDatabase. execute(TransactGetItems . of(ReadTransaction . of(customerTable, GetItem . of(key1)),
110
- ReadTransaction . of(orderTable, GetItem . of(key2)));
127
+ transactResults = mappedDatabase. execute(
128
+ TransactGetItems . create(
129
+ ReadTransaction . create(customerTable, GetItem . create(key1)),
130
+ ReadTransaction . create(orderTable, GetItem . create(key2))));
111
131
112
132
// TransactWriteItems
113
- mappedDatabase. execute(TransactWriteItems . of(WriteTransaction . of(customerTable, UpdateItem . of(customer)),
114
- WriteTransaction . of(orderTable, ConditionCheck . of(orderKey, conditionExpression)));
133
+ mappedDatabase. execute(
134
+ TransactWriteItems . create(
135
+ WriteTransaction . create(customerTable, UpdateItem . create(customer)),
136
+ WriteTransaction . create(orderTable, ConditionCheck . create(orderKey, conditionExpression))));
115
137
```
116
138
117
139
### Using secondary indices
@@ -120,7 +142,7 @@ index. Here's an example of how to do this:
120
142
```
121
143
MappedIndex<Customer> customersByName = customerTable.index("customers_by_name");
122
144
123
- Iterable<Page<Customer>> customersWithName = customersByName.query(equalTo(Key.of (stringValue("Smith"))));
145
+ Iterable<Page<Customer>> customersWithName = customersByName.query(equalTo(Key.create (stringValue("Smith"))));
124
146
```
125
147
126
148
### Non-blocking asynchronous operations
@@ -134,7 +156,7 @@ key differences:
134
156
an asynchronous DynamoDb client from the SDK as well):
135
157
```java
136
158
AsyncMappedDatabase database = DynamoDbAsyncMappedDatabase . builder()
137
- .dynamoDbAsyncClient (dynamoDbAsyncClient)
159
+ .dynamoDbClient (dynamoDbAsyncClient)
138
160
.build();
139
161
```
140
162
@@ -143,7 +165,7 @@ key differences:
143
165
application can then do other work without having to block on the
144
166
result:
145
167
```java
146
- CompletableFuture<Customer > result = mappedTable. execute(GetItem . of (customerKey));
168
+ CompletableFuture<Customer > result = mappedTable. execute(GetItem . create (customerKey));
147
169
// Perform other work here
148
170
return result. join(); // now block and wait for the result
149
171
```
@@ -184,18 +206,20 @@ that write will fail.
184
206
To load the extension:
185
207
```java
186
208
MappedDatabase database =
187
- MappedDatabase . builder()
188
- .dynamoDbClient(dynbamoDbClient)
189
- .extendWith(VersionedRecordExtension . builder(). build())
190
- .build();
209
+ DynamoDbMappedDatabase . builder()
210
+ .dynamoDbClient(dynbamoDbClient)
211
+ .extendWith(VersionedRecordExtension . builder(). build())
212
+ .build();
191
213
```
192
214
193
215
To tell the extension which attribute to use to track the record version
194
216
number tag a numeric attribute in the TableSchema with the version()
195
217
AttributeTag :
196
218
```java
197
- integerNumber(" version" , Customer :: getVersion, Customer :: setVersion)
198
- .as(version())
219
+ integerNumberAttribute(" version" ,
220
+ Customer :: getVersion,
221
+ Customer :: setVersion)
222
+ .as(version()) // Apply the 'version' tag to the attribute
199
223
```
200
224
201
225
## Advanced scenarios
@@ -219,18 +243,18 @@ public abstract class GenericRecord {
219
243
}
220
244
221
245
private static final StaticTableSchema<GenericRecord > GENERIC_RECORD_SCHEMA =
222
- TableSchema . builder()
246
+ StaticTableSchema . builder()
223
247
.attributes(
224
248
// The partition key will be inherited by the top level mapper
225
- string (" id" , GenericRecord :: getId, GenericRecord :: setId). as(primaryPartitionKey()),
226
- string (" created_date" , GenericRecord :: getCreatedDate, GenericRecord :: setCreatedDate))
249
+ stringAttribute (" id" , GenericRecord :: getId, GenericRecord :: setId). as(primaryPartitionKey()),
250
+ stringAttribute (" created_date" , GenericRecord :: getCreatedDate, GenericRecord :: setCreatedDate))
227
251
.build();
228
252
229
253
private static final StaticTableSchema<Customer > CUSTOMER_TABLE_SCHEMA =
230
- TableSchema . builder()
254
+ StaticTableSchema . builder()
231
255
.newItemSupplier(Customer :: new )
232
256
.attributes(
233
- string (" name" , Customer :: getName, Customer :: setName))
257
+ stringAttribute (" name" , Customer :: getName, Customer :: setName))
234
258
.extend(GENERIC_RECORD_SCHEMA ) // All the attributes of the GenericRecord schema are added to Customer
235
259
.build();
236
260
```
@@ -250,17 +274,17 @@ public class GenericRecord {
250
274
}
251
275
252
276
private static final StaticTableSchema<GenericRecord > GENERIC_RECORD_SCHEMA =
253
- TableSchema . builder()
277
+ StaticTableSchema . builder()
254
278
.newItemSupplier(GenericRecord :: new )
255
279
.attributes(
256
- string (" id" , GenericRecord :: getId, GenericRecord :: setId). as(primaryPartitionKey()),
257
- string (" created_date" , GenericRecord :: getCreatedDate, GenericRecord :: setCreatedDate))
280
+ stringAttribute (" id" , GenericRecord :: getId, GenericRecord :: setId). as(primaryPartitionKey()),
281
+ stringAttribute (" created_date" , GenericRecord :: getCreatedDate, GenericRecord :: setCreatedDate))
258
282
.build();
259
283
260
284
private static final StaticTableSchema<Customer > CUSTOMER_TABLE_SCHEMA =
261
- TableSchema . builder()
285
+ StaticTableSchema . builder()
262
286
.newItemSupplier(Customer :: new )
263
- .attributes(string (" name" , Customer :: getName, Customer :: setName))
287
+ .attributes(stringAttribute (" name" , Customer :: getName, Customer :: setName))
264
288
// Because we are flattening a component object, we supply a getter and setter so the
265
289
// mapper knows how to access it
266
290
.flatten(CUSTOMER_TABLE_SCHEMA , Customer :: getRecordMetadata, Customer :: setRecordMetadata)
0 commit comments