Skip to content

Commit 3b0c1c8

Browse files
committed
Functional Test Cases for Document DDB API and Surface API Review 2 comments
1 parent 5e15af7 commit 3b0c1c8

File tree

13 files changed

+3658
-194
lines changed

13 files changed

+3658
-194
lines changed

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/document/EnhancedDocument.java

Lines changed: 77 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
* {@snippet :
5252
* // CustomAttributeConverterProvider.create() is an example for some Custom converter provider
5353
* EnhancedDocument enhancedDocumentWithCustomConverter = EnhancedDocument.builder().attributeConverterProviders
54-
* (CustomAttributeConverterProvider.create(), AttributeConverterProvide.defaultProvider())
55-
* .putWithType("customObject", customObject, EnhancedType.of(CustomClass.class))
54+
* (CustomAttributeConverterProvider.create(), AttributeConverterProvide.defaultProvider()
55+
* .putWithTypethType("customObject", customObject, EnhancedType.of(CustomClass.class))
5656
* .build();
5757
*}
5858
* <p>Enhanced Document can be created with Json as input using Static factory method.In this case it used
@@ -143,7 +143,7 @@ static Builder builder() {
143143
* <p>
144144
* <b>Retrieving String Type for a document</b>
145145
* {@snippet :
146-
* Custom resultCustom = document.get("key", EnhancedType.of(Custom.class));
146+
* Custom resultCustom = document.get("key", EnhancedType.of(String.class));
147147
* }
148148
* <b>Retrieving Custom Type for which Convertor Provider was defined while creating the document</b>
149149
* {@snippet :
@@ -166,6 +166,31 @@ static Builder builder() {
166166
*/
167167
<T> T get(String attributeName, EnhancedType<T> type);
168168

169+
/**
170+
* Returns the value of the specified attribute in the current document as a specified class type; or null if the
171+
* attribute either doesn't exist or the attribute value is null.
172+
* <p>
173+
* <b>Retrieving String Type for a document</b>
174+
* {@snippet :
175+
* Custom resultCustom = document.get("key", String.class);
176+
* }
177+
* <b>Retrieving Custom Type for which Convertor Provider was defined while creating the document</b>
178+
* {@snippet :
179+
* Custom resultCustom = document.get("key", Custom.class);
180+
* }
181+
* <p>
182+
* Note :
183+
* This API should not be used to retrieve values of List and Map types.
184+
* Instead, getList and getMap APIs should be used to retrieve attributes of type List and Map, respectively.
185+
* </p>
186+
* @param attributeName Name of the attribute.
187+
* @param clazz Class type of value.
188+
* @param <T> The type of the attribute value.
189+
* @return Attribute value of type T
190+
* }
191+
*/
192+
<T> T get(String attributeName, Class<T> clazz);
193+
169194
/**
170195
* Gets the String value of specified attribute in the document.
171196
*
@@ -212,8 +237,8 @@ static Builder builder() {
212237
/**
213238
* Gets the Set of String values of the given attribute in the current document.
214239
* @param attributeName Name of the attribute.
215-
* @return value of the specified attribute in the current document as a set of SdkBytes; or null if the attribute either
216-
* doesn't exist or the attribute value is null.
240+
* @return value of the specified attribute in the current document as a set of SdkBytes;
241+
* or null if the attribute either doesn't exist.
217242
*/
218243
Set<SdkBytes> getBytesSet(String attributeName);
219244

@@ -223,8 +248,8 @@ static Builder builder() {
223248
* @param attributeName Name of the attribute.
224249
* @param type {@link EnhancedType} of Type T.
225250
* @param <T> Type T of List elements
226-
* @return value of the specified attribute in the current document as a list of type T; or null if the
227-
* attribute either doesn't exist or the attribute value is null.
251+
* @return value of the specified attribute in the current document as a list of type T,
252+
* or null if the attribute does not exist.
228253
*/
229254

230255
<T> List<T> getList(String attributeName, EnhancedType<T> type);
@@ -256,15 +281,15 @@ static Builder builder() {
256281
String getJson(String attributeName);
257282

258283
/**
259-
* Gets the {@link Boolean} value for the specified attribute.
284+
* Gets the boolean value for the specified attribute.
260285
*
261286
* @param attributeName Name of the attribute.
262287
* @return value of the specified attribute in the current document as a non-null Boolean.
263288
* @throws RuntimeException
264289
* if either the attribute doesn't exist or if the attribute
265290
* value cannot be converted into a boolean value.
266291
*/
267-
Boolean getBoolean(String attributeName);
292+
boolean getBoolean(String attributeName);
268293

269294

270295
/**
@@ -276,7 +301,7 @@ static Builder builder() {
276301
* @param attributeName Name of the attribute.
277302
* @return value of the specified attribute in the current document as a List of {@link AttributeValue}
278303
*/
279-
List<AttributeValue> getUnknownTypeList(String attributeName);
304+
List<AttributeValue> getListOfUnknownList(String attributeName);
280305

281306
/**
282307
* Retrieves a Map with String keys and corresponding AttributeValue objects as values for a specified attribute in a
@@ -287,7 +312,7 @@ static Builder builder() {
287312
* @param attributeName Name of the attribute.
288313
* @return value of the specified attribute in the current document as a {@link AttributeValue}
289314
*/
290-
Map<String, AttributeValue> getUnknownTypeMap(String attributeName);
315+
Map<String, AttributeValue> getMapOfUnknownType(String attributeName);
291316

292317
/**
293318
*
@@ -350,7 +375,7 @@ interface Builder {
350375
* @param value The boolean value that needs to be set.
351376
* @return Builder instance to construct a {@link EnhancedDocument}
352377
*/
353-
Builder putBoolean(String attributeName, Boolean value);
378+
Builder putBoolean(String attributeName, boolean value);
354379

355380
/**
356381
* Appends an attribute of name attributeName with a null value.
@@ -414,11 +439,33 @@ interface Builder {
414439
* provider.
415440
* Example:
416441
{@snippet :
417-
EnhancedDocument.builder().putWithType("customKey", customValue, EnhancedType.of(CustomClass.class));
418-
* }
442+
* EnhancedDocument.builder().put("customKey", customValue, EnhancedType.of(CustomClass.class));
443+
*}
444+
* Use {@link #putString(String, String)} or {@link #putNumber(String, Number)} for inserting simple value types of
445+
* attributes.
446+
* Use {@link #putList(String, List, EnhancedType)} or {@link #putMap(String, Map, EnhancedType, EnhancedType)} for
447+
* inserting collections of attribute values.
448+
* Note that the attribute converter provider added to the DocumentBuilder must provide the converter for the class T
449+
* that is to be inserted.
450+
@param attributeName the name of the attribute to be added to the document.
451+
@param value the value to set.
452+
@param type the Enhanced type of the value to set.
453+
@return a builder instance to construct a {@link EnhancedDocument}.
454+
@param <T> the type of the value to set.
455+
*/
456+
<T> Builder put(String attributeName, T value, EnhancedType<T> type);
457+
458+
/**
459+
* Appends an attribute named {@code attributeName} with a value of Class type T.
460+
* Use this method to insert attribute values of custom types that have attribute converters defined in a converter
461+
* provider.
462+
* Example:
463+
{@snippet :
464+
* EnhancedDocument.builder().put("customKey", customValue, CustomClass.class);
465+
*}
419466
* Use {@link #putString(String, String)} or {@link #putNumber(String, Number)} for inserting simple value types of
420467
* attributes.
421-
* Use {@link #putList(String, List, EnhancedType)} or {@link #putMapOfType(String, Map, EnhancedType, EnhancedType)} for
468+
* Use {@link #putList(String, List, EnhancedType)} or {@link #putMap(String, Map, EnhancedType, EnhancedType)} for
422469
* inserting collections of attribute values.
423470
* Note that the attribute converter provider added to the DocumentBuilder must provide the converter for the class T
424471
* that is to be inserted.
@@ -428,7 +475,7 @@ interface Builder {
428475
@return a builder instance to construct a {@link EnhancedDocument}.
429476
@param <T> the type of the value to set.
430477
*/
431-
<T> Builder putWithType(String attributeName, T value, EnhancedType<T> type);
478+
<T> Builder put(String attributeName, T value, Class<T> type);
432479

433480
/**
434481
* Appends an attribute with the specified name and a Map containing keys and values of {@link EnhancedType} K
@@ -437,14 +484,14 @@ interface Builder {
437484
* values.
438485
* <p>For example, to insert a map with String keys and Long values:
439486
* {@snippet :
440-
* EnhancedDocument.builder().putMapOfType("stringMap", mapWithStringKeyNumberValue, EnhancedType.of(String.class),
487+
* EnhancedDocument.builder().putMap("stringMap", mapWithStringKeyNumberValue, EnhancedType.of(String.class),
441488
* EnhancedType.of(String.class), EnhancedType.of(Long.class))
442-
* }
489+
*}
443490
* <p>For example, to insert a map of String Key and Custom Values:
444491
* {@snippet :
445-
* EnhancedDocument.builder().putMapOfType("customMap", mapWithStringKeyCustomValue, EnhancedType.of(String.class),
492+
* EnhancedDocument.builder().putMap("customMap", mapWithStringKeyCustomValue, EnhancedType.of(String.class),
446493
* EnhancedType.of(String.class), EnhancedType.of(Custom.class))
447-
* }
494+
*}
448495
* Note that the AttributeConverterProvider added to the DocumentBuilder should provide the converter for the classes
449496
* K and V that
450497
* are to be inserted.
@@ -454,7 +501,7 @@ interface Builder {
454501
* @param valueType Enhanced type of Value class.
455502
* @return Builder instance to construct a {@link EnhancedDocument}
456503
*/
457-
<K, V> Builder putMapOfType(String attributeName, Map<K, V> value, EnhancedType<K> keyType, EnhancedType<V> valueType);
504+
<K, V> Builder putMap(String attributeName, Map<K, V> value, EnhancedType<K> keyType, EnhancedType<V> valueType);
458505

459506
/**
460507
Appends an attribute to the document builder with the specified name and value of a JSON document in string format.
@@ -464,6 +511,15 @@ interface Builder {
464511
*/
465512
Builder putJson(String attributeName, String json);
466513

514+
515+
/**
516+
* Removes a previously appended attribute.
517+
* This can be used where a previously added attribute to the Builder is no longer needed.
518+
* @param attributeName The attribute that needs to be removed.
519+
* @return Builder instance to construct a {@link EnhancedDocument}
520+
*/
521+
Builder remove(String attributeName);
522+
467523
/**
468524
* Appends collection of attributeConverterProvider to the document builder. These
469525
* AttributeConverterProvider will be used to convert any given key to custom type T.

0 commit comments

Comments
 (0)