List of usage examples for com.amazonaws.services.dynamodbv2.datamodeling DynamoDBMapper generateCreateTableRequest
@Override
public CreateTableRequest generateCreateTableRequest(Class<?> clazz)
From source file:org.openhab.persistence.dynamodb.internal.DynamoDBPersistenceService.java
License:Open Source License
/** * Create table (if not present) and wait for table to become active. * * Synchronized in order to ensure that at most single thread is creating the table at a time * * @param mapper/*from w w w. j ava 2 s . c o m*/ * @param dtoClass * @return whether table creation succeeded. */ private synchronized boolean createTable(DynamoDBMapper mapper, Class<?> dtoClass) { if (db == null) { return false; } String tableName; try { ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput(dbConfig.getReadCapacityUnits(), dbConfig.getWriteCapacityUnits()); CreateTableRequest request = mapper.generateCreateTableRequest(dtoClass); request.setProvisionedThroughput(provisionedThroughput); if (request.getGlobalSecondaryIndexes() != null) { for (GlobalSecondaryIndex index : request.getGlobalSecondaryIndexes()) { index.setProvisionedThroughput(provisionedThroughput); } } tableName = request.getTableName(); try { db.getDynamoClient().describeTable(tableName); } catch (ResourceNotFoundException e) { // No table present, continue with creation db.getDynamoClient().createTable(request); } catch (AmazonClientException e) { logger.error("Table creation failed due to error in describeTable operation", e); return false; } // table found or just created, wait return waitForTableToBecomeActive(tableName); } catch (AmazonClientException e) { logger.error("Exception when creating table", e); return false; } }