@@ -80,66 +80,109 @@ values used are also completely arbitrary.
80
80
81
81
### Common primitive operations
82
82
These all strongly map to the primitive DynamoDB operations they are
83
- named after. These examples are the most simple variants of each
84
- operation possible. These commands can be customized by using the
85
- builders provided for each command and offer most of the features
86
- available in the low- level DynamoDB SDK client.
83
+ named after. The examples below are the most simple variants of each
84
+ operation possible, using the the two styles available for constructing
85
+ requests with either builder or consumers. These commands can be
86
+ customized by using the builders provided for each command and offer
87
+ most of the features available in the low- level DynamoDB SDK client.
87
88
88
89
```java
89
90
// CreateTable
90
- customerTable. createTable(CreateTableEnhancedRequest . create());
91
+ customerTable. createTable();
92
+ customerTable. createTable(CreateTableEnhancedRequest . builder(). build());
91
93
92
94
// GetItem
93
- Customer customer = customerTable. getItem(GetItemEnhancedRequest . create(Key . create(stringValue(" a123" ))));
94
-
95
+ Customer customer = customerTable. getItem(r - > r. key(Key . create(stringValue(" a123" ))));
96
+ Customer customer = customerTable. getItem(GetItemEnhancedRequest . builder()
97
+ .key(Key . create(stringValue(" a123" )))
98
+ .build());
95
99
// UpdateItem
96
- Customer updatedCustomer = customerTable. updateItem(UpdateItemEnhancedRequest . create(customer));
100
+ Customer updatedCustomer = customerTable. updateItem(Customer . class, r - > r. item(customer));
101
+ Customer updatedCustomer = customerTable. updateItem(UpdateItemEnhancedRequest . builder(Customer . class)
102
+ .item(customer)
103
+ .build());
97
104
98
105
// PutItem
99
- customerTable. putItem(PutItemEnhancedRequest . create(customer));
106
+ customerTable. putItem(Customer . class, r - > r. item(customer));
107
+ customerTable. putItem(PutItemEnhancedRequest . builder(Customer . class)
108
+ .item(customer)
109
+ .build());
100
110
101
111
// DeleteItem
102
- Customer deletedCustomer = customerTable. deleteItem(DeleteItemEnhancedRequest . create(Key . create(stringValue(" a123" ), numberValue(456 ))));
112
+ Customer deletedCustomer = customerTable. deleteItem(r - > r. key(Key . create(stringValue(" a123" ), numberValue(456 ))));
113
+ Customer deletedCustomer = customerTable. deleteItem(DeleteItemEnhancedRequest . builder()
114
+ .key(Key . create(stringValue(" a123" ), numberValue(456 )))
115
+ .build());
103
116
104
117
// Query
105
- Iterable<Page<Customer > > customers = customerTable. query(QueryEnhancedRequest . create(equalTo(Key . create(stringValue(" a123" )))));
106
-
118
+ Iterable<Page<Customer > > customers = customerTable. query(r - > r. queryConditional(equalTo(Key . create(stringValue(" a123" )))));
119
+ Iterable<Page<Customer > > customers = customerTable. query(QueryEnhancedRequest . builder()
120
+ .queryConditional(equalTo(Key . create(stringValue(" a123" ))))
121
+ .build());
107
122
// Scan
108
- Iterable<Page<Customer > > customers = customerTable. scan(ScanEnhancedRequest . create());
123
+ Iterable<Page<Customer > > customers = customerTable. scan();
124
+ Iterable<Page<Customer > > customers = customerTable. scan(ScanEnhancedRequest . builder(). build());
109
125
110
126
// BatchGetItem
127
+ batchResults = enhancedClient. batchGetItem(r - > r. addReadBatch(ReadBatch . builder(Customer . class)
128
+ .mappedTableResource(customerTable)
129
+ .addGetItem(i - > i. key(key1))
130
+ .addGetItem(i - > i. key(key2))
131
+ .addGetItem(i - > i. key(key3))
132
+ .build()));
111
133
batchResults = enhancedClient. batchGetItem(
112
- BatchGetItemEnhancedRequest . builder(). addReadBatch(ReadBatch . builder(Customer . class)
113
- .mappedTableResource(customerTable)
114
- .addGetItem(GetItemEnhancedRequest . create(key1))
115
- .addGetItem(GetItemEnhancedRequest . create(key2))
116
- .addGetItem(GetItemEnhancedRequest . create(key3))
117
- .build())
134
+ BatchGetItemEnhancedRequest . builder()
135
+ .readBatches(ReadBatch . builder(Customer . class)
136
+ .mappedTableResource(customerTable)
137
+ .addGetItem(GetItemEnhancedRequest . builder(). key(key1). build())
138
+ .addGetItem(GetItemEnhancedRequest . builder(). key(key2). build())
139
+ .addGetItem(GetItemEnhancedRequest . builder(). key(key3). build())
140
+ .build())
118
141
.build());
119
142
120
143
// BatchWriteItem
144
+ batchResults = enhancedClient. batchWriteItem(r - > r. addWriteBatch(WriteBatch . builder(Customer . class)
145
+ .mappedTableResource(customerTable)
146
+ .addPutItem(i - > i. item(customer))
147
+ .addDeleteItem(i - > i. key(key1))
148
+ .addDeleteItem(i - > i. key(key1))
149
+ .build()));
121
150
batchResults = enhancedClient. batchWriteItem(
122
- BatchWriteItemEnhancedRequest . builder(). addWriteBatch(WriteBatch . builder(Customer . class)
123
- .mappedTableResource(customerTable)
124
- .putItem(PutItemEnhancedRequest . create(item))
125
- .deleteItem(DeleteItemEnhancedRequest . create(key1))
126
- .deleteItem(DeleteItemEnhancedRequest . create(key2))
127
- .build())
151
+ BatchWriteItemEnhancedRequest . builder()
152
+ .addWriteBatch(WriteBatch . builder(Customer . class)
153
+ .mappedTableResource(customerTable)
154
+ .addPutItem(PutItemEnhancedRequest . builder(Customer . class). item(customer). build())
155
+ .addDeleteItem(DeleteItemEnhancedRequest . builder(). key(key1). build())
156
+ .addDeleteItem(DeleteItemEnhancedRequest . builder(). key(key2). build())
157
+ .build())
128
158
.build());
129
159
130
160
// TransactGetItems
161
+ transactResults = enhancedClient. transactGetItems(r - > r. addGetItem(customerTable, r - > r. key(Key . create(key1)))
162
+ .addGetItem(customerTable, r - > r. key(Key . create(key2))));
131
163
transactResults = enhancedClient. transactGetItems(
132
164
TransactGetItemsEnhancedRequest . builder()
133
- .addGetItem(customerTable, GetItemEnhancedRequest . create( Key . create(key1)))
134
- .addGetItem(customerTable, GetItemEnhancedRequest . create( Key . create(key2)))
165
+ .addGetItem(customerTable, GetItemEnhancedRequest . builder() . key( Key . create(key1)) . build( ))
166
+ .addGetItem(customerTable, GetItemEnhancedRequest . builder() . key( Key . create(key2)) . build( ))
135
167
.build());
136
168
137
169
// TransactWriteItems
170
+ enhancedClient. transactWriteItems(r - > r. addConditionCheck(customerTable, i - > i. key(orderKey). conditionExpression(conditionExpression))
171
+ .addUpdateItem(customerTable, Customer . class, i - > i. item(customer))
172
+ .addDeleteItem(customerTable, i - > i. key(key)));
173
+
138
174
enhancedClient. transactWriteItems(
139
175
TransactWriteItemsEnhancedRequest . builder()
140
- .addConditionCheck(customerTable, ConditionCheck . create(orderKey, conditionExpression))
141
- .addUpdateItem(customerTable, UpdateItemEnhancedRequest . create(customer))
142
- .addDeleteItem(customerTable, DeleteItemEnhancedRequest . create(key))
176
+ .addConditionCheck(customerTable, ConditionCheck . builder()
177
+ .key(orderKey)
178
+ .conditionExpression(conditionExpression)
179
+ .build())
180
+ .addUpdateItem(customerTable, UpdateItemEnhancedRequest . builder(Customer . class)
181
+ .item(customer)
182
+ .build())
183
+ .addDeleteItem(customerTable, DeleteItemEnhancedRequest . builder()
184
+ .key(key)
185
+ .build())
143
186
.build());
144
187
```
145
188
@@ -149,7 +192,7 @@ index. Here's an example of how to do this:
149
192
```
150
193
DynamoDbIndex<Customer> customersByName = customerTable.index("customers_by_name");
151
194
152
- Iterable<Page<Customer>> customersWithName = customersByName.query(QueryEnhancedRequest.create (equalTo(Key.create(stringValue("Smith")))));
195
+ Iterable<Page<Customer>> customersWithName = customersByName.query(r -> r.queryConditional (equalTo(Key.create(stringValue("Smith")))));
153
196
```
154
197
155
198
### Non-blocking asynchronous operations
@@ -172,7 +215,7 @@ key differences:
172
215
application can then do other work without having to block on the
173
216
result:
174
217
```java
175
- CompletableFuture<Customer > result = mappedTable. getItem(GetItemEnhancedRequest . create (customerKey));
218
+ CompletableFuture<Customer > result = mappedTable. getItem(r - > r . key (customerKey));
176
219
// Perform other work here
177
220
return result. join(); // now block and wait for the result
178
221
```
@@ -182,7 +225,7 @@ key differences:
182
225
application can then subscribe a handler to that publisher and deal
183
226
with the results asynchronously without having to block:
184
227
```java
185
- SdkPublisher<Customer > results = mappedTable. query(QueryEnhancedRequest . create (equalTo(Key . create(stringValue(" a123" )))));
228
+ SdkPublisher<Customer > results = mappedTable. query(r - > r . queryConditional (equalTo(Key . create(stringValue(" a123" )))));
186
229
results. subscribe(myCustomerResultsProcessor);
187
230
// Perform other work and let the processor handle the results asynchronously
188
231
```
0 commit comments