List of usage examples for com.amazonaws.services.dynamodbv2.model CreateTableRequest getGlobalSecondaryIndexes
public java.util.List<GlobalSecondaryIndex> getGlobalSecondaryIndexes()
One or more global secondary indexes (the maximum is 20) to be created on the table.
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/*ww w.j av a2 s. co 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; } }
From source file:org.socialsignin.spring.data.dynamodb.repository.util.Entity2DynamoDBTableSynchronizer.java
License:Apache License
private boolean performCreate(DynamoDBEntityInformation<T, ID> entityInformation) throws TableNeverTransitionedToStateException, InterruptedException { Class<T> domainType = entityInformation.getJavaType(); CreateTableRequest ctr = mapper.generateCreateTableRequest(domainType); LOGGER.trace("Creating table {} for entity {}", ctr.getTableName(), domainType); ctr.setProvisionedThroughput(pt);//from ww w.j ava 2s .co m if (ctr.getGlobalSecondaryIndexes() != null) { ctr.getGlobalSecondaryIndexes().forEach(gsi -> { gsi.setProjection(new Projection().withProjectionType(gsiProjectionType)); gsi.setProvisionedThroughput(pt); }); } boolean result = TableUtils.createTableIfNotExists(amazonDynamoDB, ctr); if (result) { TableUtils.waitUntilActive(amazonDynamoDB, ctr.getTableName()); LOGGER.debug("Created table {} for entity {}", ctr.getTableName(), domainType); } return result; }
From source file:org.socialsignin.spring.data.dynamodb.repository.util.Entity2DynamoDBTableSynchronizer.java
License:Apache License
/** * @param entityInformation/*from ww w.ja v a2 s. co m*/ * The entity to check for it's table * @throws IllegalStateException * is thrown if the existing table doesn't match the entity's * annotation */ private DescribeTableResult performValidate(DynamoDBEntityInformation<T, ID> entityInformation) throws IllegalStateException { Class<T> domainType = entityInformation.getJavaType(); CreateTableRequest expected = mapper.generateCreateTableRequest(domainType); DescribeTableResult result = amazonDynamoDB.describeTable(expected.getTableName()); TableDescription actual = result.getTable(); if (!expected.getKeySchema().equals(actual.getKeySchema())) { throw new IllegalStateException("KeySchema is not as expected. Expected: <" + expected.getKeySchema() + "> but found <" + actual.getKeySchema() + ">"); } LOGGER.debug("KeySchema is valid"); if (expected.getGlobalSecondaryIndexes() != null) { if (!Arrays.deepEquals(expected.getGlobalSecondaryIndexes().toArray(), actual.getGlobalSecondaryIndexes().toArray())) { throw new IllegalStateException("Global Secondary Indexes are not as expected. Expected: <" + expected.getGlobalSecondaryIndexes() + "> but found <" + actual.getGlobalSecondaryIndexes() + ">"); } } LOGGER.debug("Global Secondary Indexes are valid"); LOGGER.info("Validated table {} for entity{}", expected.getTableName(), domainType); return result; }