Skip to content

Commit c6aa961

Browse files
committed
Updated README.md to match current design iteration of interface
1 parent 59219bb commit c6aa961

File tree

1 file changed

+61
-37
lines changed

1 file changed

+61
-37
lines changed

services-custom/dynamodb-enhanced/README.md

Lines changed: 61 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,26 @@ values used are also completely arbitrary.
4141
class itself, or somewhere else :-
4242
```java
4343
static final TableSchema<Customer> CUSTOMER_TABLE_SCHEMA =
44-
TableSchema.builder()
44+
StaticTableSchema.builder()
4545
.newItemSupplier(Customer::new) // Tells the mapper how to make new objects when reading items
4646
.attributes(
47-
string("account_id", Customer::getAccountId, Customer::setAccountId)
47+
stringAttribute("account_id",
48+
Customer::getAccountId,
49+
Customer::setAccountId)
4850
.as(primaryPartitionKey()), // primary partition key
49-
integerNumber("sub_id", Customer::getSubId, Customer::setSubId)
51+
integerNumberAttribute("sub_id",
52+
Customer::getSubId,
53+
Customer::setSubId)
5054
.as(primarySortKey()), // primary sort key
51-
string("name", Customer::getName, Customer::setName)
55+
stringAttribute("name",
56+
Customer::getName,
57+
Customer::setName)
5258
.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
5664
.build();
5765
```
5866

@@ -82,36 +90,50 @@ available in the low-level DynamoDB SDK client.
8290
customerTable.execute(CreateTable.create());
8391

8492
// GetItem
85-
Customer customer = customerTable.execute(GetItem.of(Key.of(stringValue("a123"))));
93+
Customer customer = customerTable.execute(GetItem.create(Key.create(stringValue("a123"))));
8694

8795
// UpdateItem
88-
Customer updatedCustomer = customerTable.execute(UpdateItem.of(customer));
96+
Customer updatedCustomer = customerTable.execute(UpdateItem.create(customer));
8997

9098
// PutItem
91-
customerTable.execute(PutItem.of(customer));
99+
customerTable.execute(PutItem.create(customer));
92100

93101
// 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))));
95103

96104
// 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")))));
98106

99107
// Scan
100108
Iterable<Page<Customer>> customers = customerTable.execute(Scan.create());
101109

102110
// 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))));
104117

105118
// 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))));
107125

108126
// 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))));
111131

112132
// 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))));
115137
```
116138

117139
### Using secondary indices
@@ -120,7 +142,7 @@ index. Here's an example of how to do this:
120142
```
121143
MappedIndex<Customer> customersByName = customerTable.index("customers_by_name");
122144
123-
Iterable<Page<Customer>> customersWithName = customersByName.query(equalTo(Key.of(stringValue("Smith"))));
145+
Iterable<Page<Customer>> customersWithName = customersByName.query(equalTo(Key.create(stringValue("Smith"))));
124146
```
125147
126148
### Non-blocking asynchronous operations
@@ -134,7 +156,7 @@ key differences:
134156
an asynchronous DynamoDb client from the SDK as well):
135157
```java
136158
AsyncMappedDatabase database = DynamoDbAsyncMappedDatabase.builder()
137-
.dynamoDbAsyncClient(dynamoDbAsyncClient)
159+
.dynamoDbClient(dynamoDbAsyncClient)
138160
.build();
139161
```
140162

@@ -143,7 +165,7 @@ key differences:
143165
application can then do other work without having to block on the
144166
result:
145167
```java
146-
CompletableFuture<Customer> result = mappedTable.execute(GetItem.of(customerKey));
168+
CompletableFuture<Customer> result = mappedTable.execute(GetItem.create(customerKey));
147169
// Perform other work here
148170
return result.join(); // now block and wait for the result
149171
```
@@ -184,18 +206,20 @@ that write will fail.
184206
To load the extension:
185207
```java
186208
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();
191213
```
192214

193215
To tell the extension which attribute to use to track the record version
194216
number tag a numeric attribute in the TableSchema with the version()
195217
AttributeTag:
196218
```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
199223
```
200224

201225
## Advanced scenarios
@@ -219,18 +243,18 @@ public abstract class GenericRecord {
219243
}
220244

221245
private static final StaticTableSchema<GenericRecord> GENERIC_RECORD_SCHEMA =
222-
TableSchema.builder()
246+
StaticTableSchema.builder()
223247
.attributes(
224248
// 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))
227251
.build();
228252

229253
private static final StaticTableSchema<Customer> CUSTOMER_TABLE_SCHEMA =
230-
TableSchema.builder()
254+
StaticTableSchema.builder()
231255
.newItemSupplier(Customer::new)
232256
.attributes(
233-
string("name", Customer::getName, Customer::setName))
257+
stringAttribute("name", Customer::getName, Customer::setName))
234258
.extend(GENERIC_RECORD_SCHEMA) // All the attributes of the GenericRecord schema are added to Customer
235259
.build();
236260
```
@@ -250,17 +274,17 @@ public class GenericRecord {
250274
}
251275

252276
private static final StaticTableSchema<GenericRecord> GENERIC_RECORD_SCHEMA =
253-
TableSchema.builder()
277+
StaticTableSchema.builder()
254278
.newItemSupplier(GenericRecord::new)
255279
.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))
258282
.build();
259283

260284
private static final StaticTableSchema<Customer> CUSTOMER_TABLE_SCHEMA =
261-
TableSchema.builder()
285+
StaticTableSchema.builder()
262286
.newItemSupplier(Customer::new)
263-
.attributes(string("name", Customer::getName, Customer::setName))
287+
.attributes(stringAttribute("name", Customer::getName, Customer::setName))
264288
// Because we are flattening a component object, we supply a getter and setter so the
265289
// mapper knows how to access it
266290
.flatten(CUSTOMER_TABLE_SCHEMA, Customer::getRecordMetadata, Customer::setRecordMetadata)

0 commit comments

Comments
 (0)