List of usage examples for com.amazonaws.services.dynamodbv2.model CreateTableRequest setGlobalSecondaryIndexes
public void setGlobalSecondaryIndexes(java.util.Collection<GlobalSecondaryIndex> globalSecondaryIndexes)
One or more global secondary indexes (the maximum is 20) to be created on the table.
From source file:io.venable.amazonaws.dynamo.table.builder.TableBuilder.java
License:Apache License
private CreateTableRequest buildCreateTableRequest() { Collection<KeySchemaElement> keySchemaElementCollection = new ArrayList<>(); Collection<AttributeDefinition> attributeDefinitionCollection = new ArrayList<>(); primaryKeyBuilder.buildPrimaryKey(keySchemaElementCollection, attributeDefinitionCollection); KeySchemaElement primaryHashKeySchemaElement = getHashKeySchemaElement(keySchemaElementCollection); Collection<GlobalSecondaryIndex> globalSecondaryIndexCollection = new ArrayList<>(); for (GlobalSecondaryIndexBuilderImpl globalSecondaryIndexBuilder : globalSecondaryIndexBuilderCollection) { globalSecondaryIndexBuilder.buildSecondaryIndexes(globalSecondaryIndexCollection, attributeDefinitionCollection); }//ww w . j av a 2 s . c o m Collection<LocalSecondaryIndex> localSecondaryIndexCollection = new ArrayList<>(); for (LocalSecondaryIndexBuilderImpl localSecondaryIndexBuilder : localSecondaryIndexBuilderCollection) { localSecondaryIndexBuilder.buildSecondaryIndexes(primaryHashKeySchemaElement, localSecondaryIndexCollection, attributeDefinitionCollection); } CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName) .withKeySchema(keySchemaElementCollection).withAttributeDefinitions(attributeDefinitionCollection); if (globalSecondaryIndexCollection.size() > 0) createTableRequest.setGlobalSecondaryIndexes(globalSecondaryIndexCollection); if (localSecondaryIndexCollection.size() > 0) createTableRequest.setLocalSecondaryIndexes(localSecondaryIndexCollection); primaryKeyBuilder.setProvisionedThroughput(new PrimaryKeyProvisionedThroughputSetter(createTableRequest)); return createTableRequest; }
From source file:org.apache.metamodel.dynamodb.DynamoDbTableCreationBuilder.java
License:Apache License
@Override public Table execute() throws MetaModelException { final MutableTable table = getTable(); final String tableName = table.getName(); final Collection<AttributeDefinition> attributes = new ArrayList<>(); final Collection<KeySchemaElement> keySchema = new ArrayList<>(); final Collection<GlobalSecondaryIndex> globalSecondaryIndices = new ArrayList<>(); final long readCapacity = Long .parseLong(System.getProperty(DynamoDbDataContext.SYSTEM_PROPERTY_THROUGHPUT_READ_CAPACITY, "5")); final long writeCapacity = Long .parseLong(System.getProperty(DynamoDbDataContext.SYSTEM_PROPERTY_THROUGHPUT_WRITE_CAPACITY, "5")); final ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput(readCapacity, writeCapacity); for (Column column : table.getColumns()) { if (column.isPrimaryKey()) { final KeyType keyType = getKeyType(column.getRemarks()); keySchema.add(new KeySchemaElement(column.getName(), keyType)); attributes.add(/*w w w . j ava 2s . c o m*/ new AttributeDefinition(column.getName(), DynamoDbUtils.toAttributeType(column.getType()))); } } final CreateTableRequest createTableRequest = new CreateTableRequest(); createTableRequest.setTableName(tableName); createTableRequest.setAttributeDefinitions(attributes); createTableRequest.setGlobalSecondaryIndexes(globalSecondaryIndices); createTableRequest.setKeySchema(keySchema); createTableRequest.setProvisionedThroughput(provisionedThroughput); final AmazonDynamoDB client = getUpdateCallback().getDataContext().getDynamoDb(); final CreateTableResult createTableResult = client.createTable(createTableRequest); // await the table creation to be "done". { String tableStatus = createTableResult.getTableDescription().getTableStatus(); while (TableStatus.CREATING.name().equals(tableStatus)) { logger.debug("Waiting for table status to be ACTIVE. Currently: {}", tableStatus); try { Thread.sleep(300); } catch (InterruptedException e) { getUpdateCallback().setInterrupted(true); } tableStatus = client.describeTable(tableName).getTable().getTableStatus(); } } return table; }
From source file:org.diksha.common.dyutils.SchedulerDynamoTable.java
License:Apache License
public void createDynamoTable(DynamoDB dynamoDB) { try {/*from w w w . j a v a 2 s . c om*/ System.out.println(toString()); ArrayList<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>(); keySchema.add(new KeySchemaElement().withAttributeName(hashKeyName).withKeyType(KeyType.HASH)); ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>(); attributeDefinitions .add(new AttributeDefinition().withAttributeName(hashKeyName).withAttributeType(hashKeyType)); if (rangeKeyType != null) { if (!rangeKeyType.isEmpty()) { attributeDefinitions.add(new AttributeDefinition().withAttributeName(rangeKeyName) .withAttributeType(rangeKeyType)); } } if (additionalAttributes.size() > 0) { for (int cnt = 0; cnt < additionalAttributes.size(); cnt++) { String[] args = (additionalAttributes.get(cnt).toString()).split(":"); if (args.length == 2) { attributeDefinitions.add( new AttributeDefinition().withAttributeName(args[0]).withAttributeType(args[1])); } } } CreateTableRequest request = new CreateTableRequest().withTableName(tableName).withKeySchema(keySchema) .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(readCapacityUnits) .withWriteCapacityUnits(writeCapacityUnits)); ArrayList<LocalSecondaryIndex> localSecondaryIndexes = new ArrayList<LocalSecondaryIndex>(); ArrayList<GlobalSecondaryIndex> globalSecondaryIndexes = new ArrayList<GlobalSecondaryIndex>(); if (rangeKeyType != null) { if (!rangeKeyType.isEmpty()) { if (rangeKeyTypeGlobalOrLocal.equals("L")) { localSecondaryIndexes .add(new LocalSecondaryIndex().withIndexName(rangeKeyName + "-Index") .withKeySchema( new KeySchemaElement().withAttributeName(hashKeyName) .withKeyType(KeyType.HASH), new KeySchemaElement().withAttributeName(rangeKeyName) .withKeyType(KeyType.RANGE)) .withProjection( new Projection().withProjectionType(ProjectionType.KEYS_ONLY))); } else { globalSecondaryIndexes .add(new GlobalSecondaryIndex().withIndexName(rangeKeyName + "-Index") .withKeySchema( new KeySchemaElement().withAttributeName(hashKeyName) .withKeyType(KeyType.HASH), new KeySchemaElement().withAttributeName(rangeKeyName) .withKeyType(KeyType.RANGE)) .withProvisionedThroughput(new ProvisionedThroughput() .withReadCapacityUnits(indexReadCapacityUnits) .withWriteCapacityUnits(indexWriteCapacityUnits)) .withProjection( new Projection().withProjectionType(ProjectionType.KEYS_ONLY))); } } } if (indices.size() > 0) { for (int cnt = 0; cnt < indices.size(); cnt++) { SchedulerDynamoTableIndex schedulerDynamoTableIndex = indices.get(cnt); if (schedulerDynamoTableIndex.isGlobal()) { // System.out.println("IS GLOBAL"); globalSecondaryIndexes.add(schedulerDynamoTableIndex.getGlobalSecondaryIndex()); // System.out.println("size = " + globalSecondaryIndexes.size()); } } } if (localSecondaryIndexes.size() > 0) request.setLocalSecondaryIndexes(localSecondaryIndexes); if (globalSecondaryIndexes.size() > 0) request.setGlobalSecondaryIndexes(globalSecondaryIndexes); request.setAttributeDefinitions(attributeDefinitions); System.out.println("Issuing CreateTable request for " + tableName); Table table = dynamoDB.createTable(request); System.out.println("Waiting for " + tableName + " to be created...this may take a while..."); table.waitForActive(); } catch (Exception e) { System.err.println("CreateTable request failed for " + tableName); System.err.println(e.getMessage()); } }