Class TableUtils
- java.lang.Object
-
- com.amazonaws.services.dynamodbv2.util.TableUtils
-
public class TableUtils extends Object
Utility methods for working with DynamoDB tables.// ... create DynamoDB table ... try { waitUntilActive(dynamoDB, myTableName()); } catch (AmazonClientException e) { // table didn't become active } // ... start making calls to table ...
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TableUtils.TableNeverTransitionedToStateException
Thrown byTableUtils
when a table never reaches a desired state
-
Constructor Summary
Constructors Constructor Description TableUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
createTableIfNotExists(AmazonDynamoDB dynamo, CreateTableRequest createTableRequest)
Creates the table and ignores any errors if it already exists.static boolean
deleteTableIfExists(AmazonDynamoDB dynamo, DeleteTableRequest deleteTableRequest)
Deletes the table and ignores any errors if it doesn't exist.static void
waitUntilActive(AmazonDynamoDB dynamo, String tableName)
Waits up to 10 minutes for a specified DynamoDB table to move into theACTIVE
state.static void
waitUntilActive(AmazonDynamoDB dynamo, String tableName, int timeout, int interval)
Waits up to a specified amount of time for a specified DynamoDB table to move into theACTIVE
state.static void
waitUntilExists(AmazonDynamoDB dynamo, String tableName)
Waits up to 10 minutes for a specified DynamoDB table to resolve, indicating that it exists.static void
waitUntilExists(AmazonDynamoDB dynamo, String tableName, int timeout, int interval)
Waits up to a specified amount of time for a specified DynamoDB table to resolve, indicating that it exists.
-
-
-
Method Detail
-
waitUntilExists
public static void waitUntilExists(AmazonDynamoDB dynamo, String tableName) throws InterruptedException
Waits up to 10 minutes for a specified DynamoDB table to resolve, indicating that it exists. If the table doesn't return a result after this time, an AmazonClientException is thrown.- Parameters:
dynamo
- The DynamoDB client to use to make requests.tableName
- The name of the table being resolved.- Throws:
AmazonClientException
- If the specified table does not resolve before this method times out and stops polling.InterruptedException
- If the thread is interrupted while waiting for the table to resolve.
-
waitUntilExists
public static void waitUntilExists(AmazonDynamoDB dynamo, String tableName, int timeout, int interval) throws InterruptedException
Waits up to a specified amount of time for a specified DynamoDB table to resolve, indicating that it exists. If the table doesn't return a result after this time, an AmazonClientException is thrown.- Parameters:
dynamo
- The DynamoDB client to use to make requests.tableName
- The name of the table being resolved.timeout
- The maximum number of milliseconds to wait.interval
- The poll interval in milliseconds.- Throws:
AmazonClientException
- If the specified table does not resolve before this method times out and stops polling.InterruptedException
- If the thread is interrupted while waiting for the table to resolve.
-
waitUntilActive
public static void waitUntilActive(AmazonDynamoDB dynamo, String tableName) throws InterruptedException, TableUtils.TableNeverTransitionedToStateException
Waits up to 10 minutes for a specified DynamoDB table to move into theACTIVE
state. If the table does not exist or does not transition to theACTIVE
state after this time, then an AmazonClientException is thrown.- Parameters:
dynamo
- The DynamoDB client to use to make requests.tableName
- The name of the table whose status is being checked.- Throws:
TableUtils.TableNeverTransitionedToStateException
- If the specified table does not exist or does not transition into theACTIVE
state before this method times out and stops polling.InterruptedException
- If the thread is interrupted while waiting for the table to transition into theACTIVE
state.
-
waitUntilActive
public static void waitUntilActive(AmazonDynamoDB dynamo, String tableName, int timeout, int interval) throws InterruptedException, TableUtils.TableNeverTransitionedToStateException
Waits up to a specified amount of time for a specified DynamoDB table to move into theACTIVE
state. If the table does not exist or does not transition to theACTIVE
state after this time, then an AmazonClientException is thrown.- Parameters:
dynamo
- The DynamoDB client to use to make requests.tableName
- The name of the table whose status is being checked.timeout
- The maximum number of milliseconds to wait.interval
- The poll interval in milliseconds.- Throws:
TableUtils.TableNeverTransitionedToStateException
- If the specified table does not exist or does not transition into theACTIVE
state before this method times out and stops polling.InterruptedException
- If the thread is interrupted while waiting for the table to transition into theACTIVE
state.
-
createTableIfNotExists
public static final boolean createTableIfNotExists(AmazonDynamoDB dynamo, CreateTableRequest createTableRequest)
Creates the table and ignores any errors if it already exists.- Parameters:
dynamo
- The Dynamo client to use.createTableRequest
- The create table request.- Returns:
- True if created, false otherwise.
-
deleteTableIfExists
public static final boolean deleteTableIfExists(AmazonDynamoDB dynamo, DeleteTableRequest deleteTableRequest)
Deletes the table and ignores any errors if it doesn't exist.- Parameters:
dynamo
- The Dynamo client to use.deleteTableRequest
- The delete table request.- Returns:
- True if deleted, false otherwise.
-
-