Skip to content

Commit 6743b42

Browse files
committed
Support DescribeTable operation in DynamoDbTable and DynamodbAsyncTable
1 parent 705d6b3 commit 6743b42

File tree

12 files changed

+439
-93
lines changed

12 files changed

+439
-93
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"category": "DynamoDB Enhanced Client",
3+
"contributor": "",
4+
"type": "feature",
5+
"description": "Implement `DescribeTable` operation in `DynamoDbTable` and `DynamoDbAsyncTable`"
6+
}

services-custom/dynamodb-enhanced/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@
170170
<artifactId>wiremock</artifactId>
171171
<scope>test</scope>
172172
</dependency>
173+
<dependency>
174+
<groupId>nl.jqno.equalsverifier</groupId>
175+
<artifactId>equalsverifier</artifactId>
176+
<scope>test</scope>
177+
</dependency>
173178
<dependency>
174179
<groupId>com.amazonaws</groupId>
175180
<artifactId>DynamoDBLocal</artifactId>

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

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import software.amazon.awssdk.enhanced.dynamodb.model.CreateTableEnhancedRequest;
2222
import software.amazon.awssdk.enhanced.dynamodb.model.DeleteItemEnhancedRequest;
2323
import software.amazon.awssdk.enhanced.dynamodb.model.DeleteItemEnhancedResponse;
24+
import software.amazon.awssdk.enhanced.dynamodb.model.DescribeTableEnhancedResponse;
2425
import software.amazon.awssdk.enhanced.dynamodb.model.GetItemEnhancedRequest;
2526
import software.amazon.awssdk.enhanced.dynamodb.model.Page;
2627
import software.amazon.awssdk.enhanced.dynamodb.model.PagePublisher;
@@ -33,6 +34,8 @@
3334
import software.amazon.awssdk.enhanced.dynamodb.model.UpdateItemEnhancedResponse;
3435
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient;
3536
import software.amazon.awssdk.services.dynamodb.model.ConsumedCapacity;
37+
import software.amazon.awssdk.services.dynamodb.model.DescribeTableRequest;
38+
import software.amazon.awssdk.services.dynamodb.waiters.DynamoDbAsyncWaiter;
3639

3740
/**
3841
* Asynchronous interface for running commands against an object that is linked to a specific DynamoDb table resource
@@ -63,7 +66,7 @@ public interface DynamoDbAsyncTable<T> extends MappedTableResource<T> {
6366
* <p>
6467
* This operation calls the low-level DynamoDB API CreateTable operation. Note that this is an asynchronous operation and that
6568
* the table may not immediately be available for writes and reads.
66-
* Consult the CreateTable documentation for further details and constraints.
69+
* You can use {@link DynamoDbAsyncWaiter#waitUntilTableExists(DescribeTableRequest)} to wait for the resource to be ready.
6770
* <p>
6871
* Example:
6972
* <pre>
@@ -77,6 +80,7 @@ public interface DynamoDbAsyncTable<T> extends MappedTableResource<T> {
7780
* .provisionedThroughput(provisionedThroughput)
7881
* .build())
7982
* .join();
83+
* asyncClient.waiter().waitUntilTableExists(b -> b.tableName(tableName)).join();
8084
* }
8185
* </pre>
8286
*
@@ -94,8 +98,8 @@ default CompletableFuture<Void> createTable(CreateTableEnhancedRequest request)
9498
* Use {@link DynamoDbEnhancedClient#table(String, TableSchema)} to define the mapped table resource.
9599
* <p>
96100
* This operation calls the low-level DynamoDB API CreateTable operation. Note that this is an asynchronous operation and that
97-
* the table may not immediately be available for writes and reads.
98-
* Consult the CreateTable documentation for further details and constraints.
101+
* the table may not immediately be available for writes and reads. You can use
102+
* {@link DynamoDbAsyncWaiter#waitUntilTableExists(DescribeTableRequest)} to wait for the resource to be ready.
99103
* <p>
100104
* <b>Note:</b> This is a convenience method that creates an instance of the request builder avoiding the need to create one
101105
* manually via {@link CreateTableEnhancedRequest#builder()}.
@@ -109,6 +113,7 @@ default CompletableFuture<Void> createTable(CreateTableEnhancedRequest request)
109113
* .writeCapacityUnits(50L)
110114
* .build();
111115
* mappedTable.createTable(r -> r.provisionedThroughput(provisionedThroughput)).join();
116+
* asyncClient.waiter().waitUntilTableExists(b -> b.tableName(tableName)).join();
112117
* }
113118
* </pre>
114119
*
@@ -126,15 +131,15 @@ default CompletableFuture<Void> createTable(Consumer<CreateTableEnhancedRequest.
126131
* Use {@link DynamoDbEnhancedClient#table(String, TableSchema)} to define the mapped table resource.
127132
* <p>
128133
* This operation calls the low-level DynamoDB API CreateTable operation. Note that this is an asynchronous operation and that
129-
* the table may not immediately be available for writes and reads. Currently, there is no mechanism supported within this
130-
* library to wait for/check the status of a created table. You must provide this functionality yourself.
131-
* Consult the CreateTable documentation for further details and constraints.
134+
* the table may not immediately be available for writes and reads. You can use
135+
* {@link DynamoDbAsyncWaiter#waitUntilTableExists(DescribeTableRequest)} to wait for the resource to be ready.
132136
* <p>
133137
* Example:
134138
* <pre>
135139
* {@code
136140
*
137141
* mappedTable.createTable().join();
142+
* asyncClient.waiter().waitUntilTableExists(b -> b.tableName(tableName)).join();
138143
* }
139144
* </pre>
140145
*
@@ -861,4 +866,22 @@ default CompletableFuture<UpdateItemEnhancedResponse<T>> updateItemWithResponse(
861866
default CompletableFuture<Void> deleteTable() {
862867
throw new UnsupportedOperationException();
863868
}
869+
870+
/**
871+
* Describes a table in DynamoDb with the name defined for this {@link DynamoDbAsyncTable).
872+
* This operation calls the low-level DynamoDB API DescribeTable operation,
873+
* see {@link DynamoDbAsyncClient#describeTable(DescribeTableRequest)}
874+
*
875+
* <p>
876+
* Example:
877+
* <pre>
878+
* {@code
879+
*
880+
* DescribeTableEnhancedResponse response = mappedTable.describeTable().join();
881+
* }
882+
* </pre>
883+
*/
884+
default CompletableFuture<DescribeTableEnhancedResponse> describeTable() {
885+
throw new UnsupportedOperationException();
886+
}
864887
}

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

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import software.amazon.awssdk.enhanced.dynamodb.model.CreateTableEnhancedRequest;
2222
import software.amazon.awssdk.enhanced.dynamodb.model.DeleteItemEnhancedRequest;
2323
import software.amazon.awssdk.enhanced.dynamodb.model.DeleteItemEnhancedResponse;
24+
import software.amazon.awssdk.enhanced.dynamodb.model.DescribeTableEnhancedResponse;
2425
import software.amazon.awssdk.enhanced.dynamodb.model.GetItemEnhancedRequest;
2526
import software.amazon.awssdk.enhanced.dynamodb.model.Page;
2627
import software.amazon.awssdk.enhanced.dynamodb.model.PageIterable;
@@ -33,6 +34,8 @@
3334
import software.amazon.awssdk.enhanced.dynamodb.model.UpdateItemEnhancedResponse;
3435
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
3536
import software.amazon.awssdk.services.dynamodb.model.ConsumedCapacity;
37+
import software.amazon.awssdk.services.dynamodb.model.DescribeTableRequest;
38+
import software.amazon.awssdk.services.dynamodb.waiters.DynamoDbWaiter;
3639

3740
/**
3841
* Synchronous interface for running commands against an object that is linked to a specific DynamoDb table resource
@@ -62,9 +65,8 @@ public interface DynamoDbTable<T> extends MappedTableResource<T> {
6265
* Use {@link DynamoDbEnhancedClient#table(String, TableSchema)} to define the mapped table resource.
6366
* <p>
6467
* This operation calls the low-level DynamoDB API CreateTable operation. Note that this is an asynchronous
65-
* operation and that the table may not immediately be available for writes and reads. Currently, there is no
66-
* mechanism supported within this library to wait for/check the status of a created table. You must provide this
67-
* functionality yourself. Consult the CreateTable documentation for further details and constraints.
68+
* operation and that the table may not immediately be available for writes and reads. You can use
69+
* {@link DynamoDbWaiter#waitUntilTableExists(DescribeTableRequest)} to wait for the resource to be ready.
6870
* <p>
6971
* Example:
7072
* <pre>
@@ -77,6 +79,8 @@ public interface DynamoDbTable<T> extends MappedTableResource<T> {
7779
* mappedTable.createTable(CreateTableEnhancedRequest.builder()
7880
* .provisionedThroughput(provisionedThroughput)
7981
* .build());
82+
*
83+
* dynamoDbClient.waiter().waitUntilTableExists(b -> b.tableName(tableName));
8084
* }
8185
* </pre>
8286
*
@@ -93,9 +97,8 @@ default void createTable(CreateTableEnhancedRequest request) {
9397
* Use {@link DynamoDbEnhancedClient#table(String, TableSchema)} to define the mapped table resource.
9498
* <p>
9599
* This operation calls the low-level DynamoDB API CreateTable operation. Note that this is an asynchronous
96-
* operation and that the table may not immediately be available for writes and reads. Currently, there is no
97-
* mechanism supported within this library to wait for/check the status of a created table. You must provide this
98-
* functionality yourself. Consult the CreateTable documentation for further details and constraints.
100+
* operation and that the table may not immediately be available for writes and reads. You can use
101+
* {@link DynamoDbWaiter#waitUntilTableExists(DescribeTableRequest)} to wait for the resource to be ready.
99102
* <p>
100103
* <b>Note:</b> This is a convenience method that creates an instance of the request builder avoiding the need to
101104
* create one manually via {@link CreateTableEnhancedRequest#builder()}.
@@ -109,6 +112,7 @@ default void createTable(CreateTableEnhancedRequest request) {
109112
* .writeCapacityUnits(50L)
110113
* .build();
111114
* mappedTable.createTable(r -> r.provisionedThroughput(provisionedThroughput));
115+
* dynamoDbClient.waiter().waitUntilTableExists(b -> b.tableName(tableName));
112116
* }
113117
* </pre>
114118
*
@@ -125,15 +129,15 @@ default void createTable(Consumer<CreateTableEnhancedRequest.Builder> requestCon
125129
* Use {@link DynamoDbEnhancedClient#table(String, TableSchema)} to define the mapped table resource.
126130
* <p>
127131
* This operation calls the low-level DynamoDB API CreateTable operation. Note that this is an asynchronous
128-
* operation and that the table may not immediately be available for writes and reads. Currently, there is no
129-
* mechanism supported within this library to wait for/check the status of a created table. You must provide this
130-
* functionality yourself. Consult the CreateTable documentation for further details and constraints.
132+
* operation and that the table may not immediately be available for writes and reads. You can use
133+
* {@link DynamoDbWaiter#waitUntilTableExists(DescribeTableRequest)} to wait for the resource to be ready.
131134
* <p>
132135
* Example:
133136
* <pre>
134137
* {@code
135138
*
136139
* mappedTable.createTable();
140+
* dynamoDbClient.waiter().waitUntilTableExists(b -> b.tableName(tableName));
137141
* }
138142
* </pre>
139143
*
@@ -827,8 +831,8 @@ default UpdateItemEnhancedResponse<T> updateItemWithResponse(Consumer<UpdateItem
827831
* Use {@link DynamoDbEnhancedClient#table(String, TableSchema)} to define the mapped table resource.
828832
* <p>
829833
* This operation calls the low-level DynamoDB API DeleteTable operation.
830-
* Note that this is an asynchronousoperation and that the table may not immediately be deleted. You can use
831-
* {@link software.amazon.awssdk.services.dynamodb.waiters.DynamoDbWaiter#waitUntilTableNotExists}
834+
* Note that this is an asynchronous operation and that the table may not immediately be deleted. You can use
835+
* {@link DynamoDbWaiter#waitUntilTableNotExists}
832836
* in the underlying client.
833837
* <p>
834838
* Example:
@@ -843,4 +847,22 @@ default UpdateItemEnhancedResponse<T> updateItemWithResponse(Consumer<UpdateItem
843847
default void deleteTable() {
844848
throw new UnsupportedOperationException();
845849
}
850+
851+
/**
852+
* Describes a table in DynamoDb with the name defined for this {@link DynamoDbTable).
853+
* This operation calls the low-level DynamoDB API DescribeTable operation,
854+
* see {@link DynamoDbClient#describeTable(DescribeTableRequest)}
855+
* <p>
856+
* Example:
857+
* <pre>
858+
* {@code
859+
*
860+
* DescribeTableEnhancedResponse response = mappedTable.describeTable();
861+
* }
862+
* </pre>
863+
*
864+
*/
865+
default DescribeTableEnhancedResponse describeTable() {
866+
throw new UnsupportedOperationException();
867+
}
846868
}

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/client/DefaultDynamoDbAsyncTable.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import software.amazon.awssdk.enhanced.dynamodb.internal.operations.CreateTableOperation;
2929
import software.amazon.awssdk.enhanced.dynamodb.internal.operations.DeleteItemOperation;
3030
import software.amazon.awssdk.enhanced.dynamodb.internal.operations.DeleteTableOperation;
31+
import software.amazon.awssdk.enhanced.dynamodb.internal.operations.DescribeTableOperation;
3132
import software.amazon.awssdk.enhanced.dynamodb.internal.operations.GetItemOperation;
3233
import software.amazon.awssdk.enhanced.dynamodb.internal.operations.PaginatedTableOperation;
3334
import software.amazon.awssdk.enhanced.dynamodb.internal.operations.PutItemOperation;
@@ -38,6 +39,7 @@
3839
import software.amazon.awssdk.enhanced.dynamodb.model.CreateTableEnhancedRequest;
3940
import software.amazon.awssdk.enhanced.dynamodb.model.DeleteItemEnhancedRequest;
4041
import software.amazon.awssdk.enhanced.dynamodb.model.DeleteItemEnhancedResponse;
42+
import software.amazon.awssdk.enhanced.dynamodb.model.DescribeTableEnhancedResponse;
4143
import software.amazon.awssdk.enhanced.dynamodb.model.GetItemEnhancedRequest;
4244
import software.amazon.awssdk.enhanced.dynamodb.model.PagePublisher;
4345
import software.amazon.awssdk.enhanced.dynamodb.model.PutItemEnhancedRequest;
@@ -48,6 +50,8 @@
4850
import software.amazon.awssdk.enhanced.dynamodb.model.UpdateItemEnhancedRequest;
4951
import software.amazon.awssdk.enhanced.dynamodb.model.UpdateItemEnhancedResponse;
5052
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient;
53+
import software.amazon.awssdk.services.dynamodb.model.DescribeTableRequest;
54+
import software.amazon.awssdk.services.dynamodb.model.DescribeTableResponse;
5155

5256
@SdkInternalApi
5357
public final class DefaultDynamoDbAsyncTable<T> implements DynamoDbAsyncTable<T> {
@@ -290,6 +294,13 @@ public CompletableFuture<Void> deleteTable() {
290294
return operation.executeOnPrimaryIndexAsync(tableSchema, tableName, extension, dynamoDbClient);
291295
}
292296

297+
@Override
298+
public CompletableFuture<DescribeTableEnhancedResponse> describeTable() {
299+
TableOperation<T, DescribeTableRequest, DescribeTableResponse, DescribeTableEnhancedResponse> operation =
300+
DescribeTableOperation.create();
301+
return operation.executeOnPrimaryIndexAsync(tableSchema, tableName, extension, dynamoDbClient);
302+
}
303+
293304
@Override
294305
public boolean equals(Object o) {
295306
if (this == o) {

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/client/DefaultDynamoDbTable.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import software.amazon.awssdk.enhanced.dynamodb.internal.operations.CreateTableOperation;
2828
import software.amazon.awssdk.enhanced.dynamodb.internal.operations.DeleteItemOperation;
2929
import software.amazon.awssdk.enhanced.dynamodb.internal.operations.DeleteTableOperation;
30+
import software.amazon.awssdk.enhanced.dynamodb.internal.operations.DescribeTableOperation;
3031
import software.amazon.awssdk.enhanced.dynamodb.internal.operations.GetItemOperation;
3132
import software.amazon.awssdk.enhanced.dynamodb.internal.operations.PaginatedTableOperation;
3233
import software.amazon.awssdk.enhanced.dynamodb.internal.operations.PutItemOperation;
@@ -37,6 +38,7 @@
3738
import software.amazon.awssdk.enhanced.dynamodb.model.CreateTableEnhancedRequest;
3839
import software.amazon.awssdk.enhanced.dynamodb.model.DeleteItemEnhancedRequest;
3940
import software.amazon.awssdk.enhanced.dynamodb.model.DeleteItemEnhancedResponse;
41+
import software.amazon.awssdk.enhanced.dynamodb.model.DescribeTableEnhancedResponse;
4042
import software.amazon.awssdk.enhanced.dynamodb.model.GetItemEnhancedRequest;
4143
import software.amazon.awssdk.enhanced.dynamodb.model.PageIterable;
4244
import software.amazon.awssdk.enhanced.dynamodb.model.PutItemEnhancedRequest;
@@ -47,6 +49,8 @@
4749
import software.amazon.awssdk.enhanced.dynamodb.model.UpdateItemEnhancedRequest;
4850
import software.amazon.awssdk.enhanced.dynamodb.model.UpdateItemEnhancedResponse;
4951
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
52+
import software.amazon.awssdk.services.dynamodb.model.DescribeTableRequest;
53+
import software.amazon.awssdk.services.dynamodb.model.DescribeTableResponse;
5054

5155
@SdkInternalApi
5256
public class DefaultDynamoDbTable<T> implements DynamoDbTable<T> {
@@ -286,6 +290,13 @@ public void deleteTable() {
286290
operation.executeOnPrimaryIndex(tableSchema, tableName, extension, dynamoDbClient);
287291
}
288292

293+
@Override
294+
public DescribeTableEnhancedResponse describeTable() {
295+
TableOperation<T, DescribeTableRequest, DescribeTableResponse, DescribeTableEnhancedResponse> operation =
296+
DescribeTableOperation.create();
297+
return operation.executeOnPrimaryIndex(tableSchema, tableName, extension, dynamoDbClient);
298+
}
299+
289300
@Override
290301
public boolean equals(Object o) {
291302
if (this == o) {

0 commit comments

Comments
 (0)