Skip to content

Commit b697abd

Browse files
committed
Dynamodb-enhanced: added 'conditionExpression' support to put, get, delete operations; slightly breaking style changes to immutable object getters
1 parent 140d941 commit b697abd

File tree

84 files changed

+1243
-667
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1243
-667
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "feature",
3+
"category": "Amazon DynamoDB Enhanced Client [Preview]",
4+
"description": "Write operations (put, get, delete) now support 'conditionExpression'"
5+
}

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/extensions/dynamodb/mappingclient/BatchableReadOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
@SdkProtectedApi
2121
public interface BatchableReadOperation {
22-
Boolean getConsistentRead();
22+
Boolean consistentRead();
2323

24-
Key getKey();
24+
Key key();
2525
}

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/extensions/dynamodb/mappingclient/CommonOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public interface CommonOperation<ItemT, RequestT, ResponseT, ResultT> {
5353
* @param dynamoDbClient A low level {@link DynamoDbClient} to make the call against.
5454
* @return A function that calls DynamoDb with a provided request object and returns the response object.
5555
*/
56-
Function<RequestT, ResponseT> getServiceCall(DynamoDbClient dynamoDbClient);
56+
Function<RequestT, ResponseT> serviceCall(DynamoDbClient dynamoDbClient);
5757

5858
/**
5959
* Takes the response object returned by the actual DynamoDb call and maps it into a higher level abstracted
@@ -89,7 +89,7 @@ default ResultT execute(TableSchema<ItemT> tableSchema,
8989
MapperExtension mapperExtension,
9090
DynamoDbClient dynamoDbClient) {
9191
RequestT request = generateRequest(tableSchema, context, mapperExtension);
92-
ResponseT response = getServiceCall(dynamoDbClient).apply(request);
92+
ResponseT response = serviceCall(dynamoDbClient).apply(request);
9393
return transformResponse(response, tableSchema, context, mapperExtension);
9494
}
9595
}

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/extensions/dynamodb/mappingclient/DatabaseOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public interface DatabaseOperation<RequestT, ResponseT, ResultT> {
4848
* @param dynamoDbClient A low level {@link DynamoDbClient} to make the call against.
4949
* @return A function that calls DynamoDb with a provided request object and returns the response object.
5050
*/
51-
Function<RequestT, ResponseT> getServiceCall(DynamoDbClient dynamoDbClient);
51+
Function<RequestT, ResponseT> serviceCall(DynamoDbClient dynamoDbClient);
5252

5353
/**
5454
* Takes the response object returned by the actual DynamoDb call and maps it into a higher level abstracted
@@ -73,7 +73,7 @@ public interface DatabaseOperation<RequestT, ResponseT, ResultT> {
7373
*/
7474
default ResultT execute(DynamoDbClient dynamoDbClient, MapperExtension mapperExtension) {
7575
RequestT request = generateRequest(mapperExtension);
76-
ResponseT response = getServiceCall(dynamoDbClient).apply(request);
76+
ResponseT response = serviceCall(dynamoDbClient).apply(request);
7777
return transformResponse(response, mapperExtension);
7878
}
7979
}

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/extensions/dynamodb/mappingclient/Expression.java

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ public static Expression coalesce(Expression condition1, Expression condition2,
5151

5252
return Expression.builder()
5353
.expression(coalesceExpressions(condition1.expression, condition2.expression, joinToken))
54-
.expressionValues(coalesceValues(condition1.getExpressionValues(),
55-
condition2.getExpressionValues()))
56-
.expressionNames(coalesceNames(condition1.getExpressionNames(),
57-
condition2.getExpressionNames()))
54+
.expressionValues(coalesceValues(condition1.expressionValues(),
55+
condition2.expressionValues()))
56+
.expressionNames(coalesceNames(condition1.expressionNames(),
57+
condition2.expressionNames()))
5858
.build();
5959
}
6060

61-
private static String coalesceExpressions(String expression1, String expression2, String joinToken) {
61+
public static String coalesceExpressions(String expression1, String expression2, String joinToken) {
6262
if (expression1 == null) {
6363
return expression2;
6464
}
@@ -67,7 +67,7 @@ private static String coalesceExpressions(String expression1, String expression2
6767
return expression1;
6868
}
6969

70-
return expression1 + joinToken + expression2;
70+
return "(" + expression1 + ")" + joinToken + "(" + expression2 + ")";
7171
}
7272

7373
public static Map<String, AttributeValue> coalesceValues(Map<String, AttributeValue> expressionValues1,
@@ -118,15 +118,15 @@ public static Map<String, String> coalesceNames(Map<String, String> expressionVa
118118
return Collections.unmodifiableMap(result);
119119
}
120120

121-
public String getExpression() {
121+
public String expression() {
122122
return expression;
123123
}
124124

125-
public Map<String, AttributeValue> getExpressionValues() {
125+
public Map<String, AttributeValue> expressionValues() {
126126
return expressionValues;
127127
}
128128

129-
public Map<String, String> getExpressionNames() {
129+
public Map<String, String> expressionNames() {
130130
return expressionNames;
131131
}
132132

@@ -173,12 +173,30 @@ public Builder expression(String expression) {
173173
}
174174

175175
public Builder expressionValues(Map<String, AttributeValue> expressionValues) {
176-
this.expressionValues = expressionValues;
176+
this.expressionValues = expressionValues == null ? null : new HashMap<>(expressionValues);
177+
return this;
178+
}
179+
180+
public Builder putExpressionValue(String key, AttributeValue value) {
181+
if (this.expressionValues == null) {
182+
this.expressionValues = new HashMap<>();
183+
}
184+
185+
this.expressionValues.put(key, value);
177186
return this;
178187
}
179188

180189
public Builder expressionNames(Map<String, String> expressionNames) {
181-
this.expressionNames = expressionNames;
190+
this.expressionNames = expressionNames == null ? null : new HashMap<>(expressionNames);
191+
return this;
192+
}
193+
194+
public Builder putExpressionName(String key, String value) {
195+
if (this.expressionNames == null) {
196+
this.expressionNames = new HashMap<>();
197+
}
198+
199+
this.expressionNames.put(key, value);
182200
return this;
183201
}
184202

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/extensions/dynamodb/mappingclient/Key.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ public static Key of(AttributeValue partitionKeyValue, AttributeValue sortKeyVal
6666
* @param index The name of the index to use when determining the key attribute names.
6767
* @return A map of attribute names to {@link AttributeValue}.
6868
*/
69-
public Map<String, AttributeValue> getKeyMap(TableSchema<?> tableSchema, String index) {
69+
public Map<String, AttributeValue> keyMap(TableSchema<?> tableSchema, String index) {
7070
Map<String, AttributeValue> keyMap = new HashMap<>();
71-
keyMap.put(tableSchema.getTableMetadata().getIndexPartitionKey(index), partitionKeyValue);
71+
keyMap.put(tableSchema.tableMetadata().indexPartitionKey(index), partitionKeyValue);
7272

7373
if (sortKeyValue != null) {
74-
keyMap.put(tableSchema.getTableMetadata().getIndexSortKey(index).orElseThrow(
74+
keyMap.put(tableSchema.tableMetadata().indexSortKey(index).orElseThrow(
7575
() -> new IllegalArgumentException("A sort key value was supplied for an index that does not support "
7676
+ "one. Index: " + index)), sortKeyValue);
7777
}
@@ -83,7 +83,7 @@ public Map<String, AttributeValue> getKeyMap(TableSchema<?> tableSchema, String
8383
* Get the literal value of the partition key stored in this object.
8484
* @return An {@link AttributeValue} representing the literal value of the partition key.
8585
*/
86-
public AttributeValue getPartitionKeyValue() {
86+
public AttributeValue partitionKeyValue() {
8787
return partitionKeyValue;
8888
}
8989

@@ -92,7 +92,7 @@ public AttributeValue getPartitionKeyValue() {
9292
* @return An optional {@link AttributeValue} representing the literal value of the sort key, or empty if there
9393
* is no sort key value in this Key.
9494
*/
95-
public Optional<AttributeValue> getSortKeyValue() {
95+
public Optional<AttributeValue> sortKeyValue() {
9696
return Optional.ofNullable(sortKeyValue);
9797
}
9898

@@ -101,8 +101,8 @@ public Optional<AttributeValue> getSortKeyValue() {
101101
* @param tableSchema A tableschema to determine the key attribute names from.
102102
* @return A map of attribute names to {@link AttributeValue}.
103103
*/
104-
public Map<String, AttributeValue> getPrimaryKeyMap(TableSchema<?> tableSchema) {
105-
return getKeyMap(tableSchema, TableMetadata.getPrimaryIndexName());
104+
public Map<String, AttributeValue> primaryKeyMap(TableSchema<?> tableSchema) {
105+
return keyMap(tableSchema, TableMetadata.primaryIndexName());
106106
}
107107

108108
@Override

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/extensions/dynamodb/mappingclient/MappedIndex.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,25 @@ public interface MappedIndex<T> {
5050
* Gets the {@link MapperExtension} associated with this mapped resource.
5151
* @return The {@link MapperExtension} associated with this mapped resource.
5252
*/
53-
MapperExtension getMapperExtension();
53+
MapperExtension mapperExtension();
5454

5555
/**
5656
* Gets the {@link TableSchema} object that this mapped table was built with.
5757
* @return The {@link TableSchema} object for this mapped table.
5858
*/
59-
TableSchema<T> getTableSchema();
59+
TableSchema<T> tableSchema();
6060

6161
/**
6262
* Gets the physical table name that operations performed by this object will be executed against.
6363
* @return The physical table name.
6464
*/
65-
String getTableName();
65+
String tableName();
6666

6767
/**
6868
* Gets the physical secondary index name that operations performed by this object will be executed against.
6969
* @return The physical secondary index name.
7070
*/
71-
String getIndexName();
71+
String indexName();
7272

7373
/**
7474
* Creates a {@link Key} object from a modelled item. This key can be used in query conditionals and get

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/extensions/dynamodb/mappingclient/MappedTable.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,19 @@ public interface MappedTable<T> {
5656
* Gets the {@link MapperExtension} associated with this mapped resource.
5757
* @return The {@link MapperExtension} associated with this mapped resource.
5858
*/
59-
MapperExtension getMapperExtension();
59+
MapperExtension mapperExtension();
6060

6161
/**
6262
* Gets the {@link TableSchema} object that this mapped table was built with.
6363
* @return The {@link TableSchema} object for this mapped table.
6464
*/
65-
TableSchema<T> getTableSchema();
65+
TableSchema<T> tableSchema();
6666

6767
/**
6868
* Gets the physical table name that operations performed by this object will be executed against.
6969
* @return The physical table name.
7070
*/
71-
String getTableName();
71+
String tableName();
7272

7373
/**
7474
* Creates a {@link Key} object from a modelled item. This key can be used in query conditionals and get

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/extensions/dynamodb/mappingclient/OperationContext.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ public static OperationContext of(String tableName, String indexName) {
3232
}
3333

3434
public static OperationContext of(String tableName) {
35-
return new OperationContext(tableName, TableMetadata.getPrimaryIndexName());
35+
return new OperationContext(tableName, TableMetadata.primaryIndexName());
3636
}
3737

38-
public String getTableName() {
38+
public String tableName() {
3939
return tableName;
4040
}
4141

42-
public String getIndexName() {
42+
public String indexName() {
4343
return indexName;
4444
}
4545

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/extensions/dynamodb/mappingclient/Page.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static <T> Page<T> of(List<T> items) {
6161
* Returns a page of mapped objects that represent records from a database query or scan.
6262
* @return A list of mapped objects.
6363
*/
64-
public List<T> getItems() {
64+
public List<T> items() {
6565
return items;
6666
}
6767

@@ -70,7 +70,7 @@ public List<T> getItems() {
7070
* to continue the query or scan if passed into a request.
7171
* @return The 'lastEvaluatedKey' from the last query or scan operation or null if the no more pages are available.
7272
*/
73-
public Map<String, AttributeValue> getLastEvaluatedKey() {
73+
public Map<String, AttributeValue> lastEvaluatedKey() {
7474
return lastEvaluatedKey;
7575
}
7676

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/extensions/dynamodb/mappingclient/TableMetadata.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public interface TableMetadata {
3434
* @throws IllegalArgumentException if the index does not exist in the metadata or does not have a partition key
3535
* associated with it..
3636
*/
37-
String getIndexPartitionKey(String indexName);
37+
String indexPartitionKey(String indexName);
3838

3939
/**
4040
* Returns the attribute name of the sort key for an index.
@@ -43,7 +43,7 @@ public interface TableMetadata {
4343
* @return Optional of the attribute name representing the sort key for this index; empty if the index does not
4444
* have a sort key.
4545
*/
46-
Optional<String> getIndexSortKey(String indexName);
46+
Optional<String> indexSortKey(String indexName);
4747

4848
/**
4949
* Returns a custom metadata object. These objects are used by extensions to the library, therefore the type of
@@ -56,15 +56,15 @@ public interface TableMetadata {
5656
* @param <T> The flexible type for the object being returned. The compiler will typically infer this.
5757
* @return An optional containing custom metadata object or empty if the object was not found.
5858
*/
59-
<T> Optional<T> getCustomMetadataObject(String key, Class<? extends T> objectClass);
59+
<T> Optional<T> customMetadataObject(String key, Class<? extends T> objectClass);
6060

6161
/**
6262
* Returns all the names of attributes associated with the keys of a specified index.
6363
*
6464
* @param indexName The name of the index.
6565
* @return A collection of all key attribute names for that index.
6666
*/
67-
Collection<String> getIndexKeys(String indexName);
67+
Collection<String> indexKeys(String indexName);
6868

6969
/**
7070
* Returns all the names of attributes associated with any index (primary or secondary) known for this table.
@@ -74,42 +74,42 @@ public interface TableMetadata {
7474
*
7575
* @return A collection of all key attribute names for the table.
7676
*/
77-
Collection<String> getAllKeys();
77+
Collection<String> allKeys();
7878

7979
/**
8080
* Returns the DynamoDb scalar attribute type associated with a key attribute if one is applicable.
8181
* @param keyAttribute The key attribute name to return the scalar attribute type of.
8282
* @return Optional {@link ScalarAttributeType} of the attribute, or empty if attribute is a non-scalar type.
8383
* @throws IllegalArgumentException if the keyAttribute is not found.
8484
*/
85-
Optional<ScalarAttributeType> getScalarAttributeType(String keyAttribute);
85+
Optional<ScalarAttributeType> scalarAttributeType(String keyAttribute);
8686

8787
/**
8888
* Returns the attribute name used as the primary partition key for the table.
8989
*
9090
* @return The primary partition key attribute name.
9191
* @throws IllegalArgumentException if the primary partition key is not known.
9292
*/
93-
default String getPrimaryPartitionKey() {
94-
return getIndexPartitionKey(getPrimaryIndexName());
93+
default String primaryPartitionKey() {
94+
return indexPartitionKey(primaryIndexName());
9595
}
9696

9797
/**
9898
* Returns the attribute name used as the primary sort key for the table.
9999
*
100100
* @return An optional of the primary sort key attribute name; empty if this key is not known.
101101
*/
102-
default Optional<String> getPrimarySortKey() {
103-
return getIndexSortKey(getPrimaryIndexName());
102+
default Optional<String> primarySortKey() {
103+
return indexSortKey(primaryIndexName());
104104
}
105105

106106
/**
107107
* Returns the names of the attributes that make up the primary key for the table.
108108
*
109109
* @return A collection of attribute names that make up the primary key for the table.
110110
*/
111-
default Collection<String> getPrimaryKeys() {
112-
return getIndexKeys(getPrimaryIndexName());
111+
default Collection<String> primaryKeys() {
112+
return indexKeys(primaryIndexName());
113113
}
114114

115115
/**
@@ -119,7 +119,7 @@ default Collection<String> getPrimaryKeys() {
119119
*
120120
* @return An arbitrary constant that internally represents the primary index name.
121121
*/
122-
static String getPrimaryIndexName() {
122+
static String primaryIndexName() {
123123
// Must include illegal symbols that cannot be used by a real index.
124124
// This value is arbitrary and ephemeral but could end up being serialized with TableMetadata through the
125125
// actions of a client, so it should not be altered unless absolutely necessary.

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/extensions/dynamodb/mappingclient/TableOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ default ResultT executeOnPrimaryIndex(TableSchema<ItemT> tableSchema,
5555
String tableName,
5656
MapperExtension mapperExtension,
5757
DynamoDbClient dynamoDbClient) {
58-
OperationContext context = OperationContext.of(tableName, TableMetadata.getPrimaryIndexName());
58+
OperationContext context = OperationContext.of(tableName, TableMetadata.primaryIndexName());
5959
return execute(tableSchema, context, mapperExtension, dynamoDbClient);
6060
}
6161
}

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/extensions/dynamodb/mappingclient/TableSchema.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ public interface TableSchema<T> {
7676
* @return A single {@link AttributeValue} representing the requested modelled attribute in the model object or
7777
* null if the attribute has not been set with a value in the modelled object.
7878
*/
79-
AttributeValue getAttributeValue(T item, String key);
79+
AttributeValue attributeValue(T item, String key);
8080

8181
/**
8282
* Returns the object that describes the structure of the table being modelled by the mapper. This includes
8383
* information such as the table name, index keys and attribute tags.
8484
* @return A {@link TableMetadata} object that contains structural information about the table being modelled.
8585
*/
86-
TableMetadata getTableMetadata();
86+
TableMetadata tableMetadata();
8787

8888
/**
8989
* Returns a builder for the default implementation of this interface which is an immutable, declarative, type-safe

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/extensions/dynamodb/mappingclient/core/AttributeValueType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public enum AttributeValueType {
4040
this.scalarAttributeType = scalarAttributeType;
4141
}
4242

43-
public ScalarAttributeType getScalarAttributeType() {
43+
public ScalarAttributeType scalarAttributeType() {
4444
return scalarAttributeType;
4545
}
4646
}

0 commit comments

Comments
 (0)