List of usage examples for com.amazonaws.services.dynamodbv2.model CreateTableRequest getAttributeDefinitions
public java.util.List<AttributeDefinition> getAttributeDefinitions()
An array of attributes that describe the key schema for the table and indexes.
From source file:awslabs.lab22.SolutionCode.java
License:Open Source License
@Override public void buildTable(AmazonDynamoDBClient ddbClient, String tableName) { System.out.println("Creating table."); CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName); createTableRequest.setAttributeDefinitions(new ArrayList<AttributeDefinition>()); // Define attributes createTableRequest.getAttributeDefinitions() .add(new AttributeDefinition().withAttributeName("Company").withAttributeType("S")); createTableRequest.getAttributeDefinitions() .add(new AttributeDefinition().withAttributeName("Email").withAttributeType("S")); // Define key schema createTableRequest.setKeySchema(new ArrayList<KeySchemaElement>()); createTableRequest.getKeySchema()/*from w w w .j ava 2 s . c om*/ .add(new KeySchemaElement().withAttributeName("Company").withKeyType("HASH")); createTableRequest.getKeySchema() .add(new KeySchemaElement().withAttributeName("Email").withKeyType("RANGE")); // Define provisioned throughput createTableRequest.setProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(10L).withWriteCapacityUnits(5L)); // Submit create request ddbClient.createTable(createTableRequest); // Pause until the table is active waitForStatus(ddbClient, tableName, "ACTIVE"); System.out.println("Table created and active."); }
From source file:awslabs.lab51.SolutionCode.java
License:Open Source License
@Override public void buildTable(AmazonDynamoDBClient ddbClient, String tableName) { CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName); createTableRequest.setAttributeDefinitions(new ArrayList<AttributeDefinition>()); // Define attributes createTableRequest.getAttributeDefinitions() .add(new AttributeDefinition().withAttributeName("Key").withAttributeType("S")); createTableRequest.getAttributeDefinitions() .add(new AttributeDefinition().withAttributeName("Bucket").withAttributeType("S")); // Define key schema createTableRequest.setKeySchema(new ArrayList<KeySchemaElement>()); createTableRequest.getKeySchema().add(new KeySchemaElement().withAttributeName("Key").withKeyType("HASH")); createTableRequest.getKeySchema()/* w w w .j a v a2 s . co m*/ .add(new KeySchemaElement().withAttributeName("Bucket").withKeyType("RANGE")); // Define provisioned throughput createTableRequest.setProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(5L).withWriteCapacityUnits(5L)); // Submit create request ddbClient.createTable(createTableRequest); // Pause until the table is active waitForStatus(ddbClient, tableName, "ACTIVE"); labController.logMessageToPage("Table created and active."); }
From source file:com.makariev.dynamodb.data.tables.creators.ReplyCreator.java
License:Apache License
@Override public CreateTableRequest getCreateTableRequest() { final String tableName = Reply.TABLE_NAME; final String hashKeyName = "Id"; final ScalarAttributeType hashKeyType = ScalarAttributeType.S; final Long readCapacityUnits = 10L; final Long writeCapacityUnits = 10L; final String rangeKeyName = "ReplyDateTime"; final ScalarAttributeType rangeKeyType = ScalarAttributeType.S; //////////////// final CreateTableRequest request = basicTable(tableName, readCapacityUnits, writeCapacityUnits, hashKeyName, hashKeyType);//w ww . j a v a2 s.com /////////////////////// //defining range key request.getKeySchema() .add(new KeySchemaElement().withAttributeName(rangeKeyName).withKeyType(KeyType.RANGE)); //defining range key request.getAttributeDefinitions() .add(new AttributeDefinition().withAttributeName(rangeKeyName).withAttributeType(rangeKeyType)); ////////////////////// //follows defininig of a local secondary index request.getAttributeDefinitions().add( new AttributeDefinition().withAttributeName("PostedBy").withAttributeType(ScalarAttributeType.S)); final List<KeySchemaElement> iks = new ArrayList<>(); iks.add(new KeySchemaElement().withAttributeName(hashKeyName).withKeyType(KeyType.HASH)); iks.add(new KeySchemaElement().withAttributeName("PostedBy").withKeyType(KeyType.RANGE)); final LocalSecondaryIndex localSecondaryIndex = new LocalSecondaryIndex().withIndexName("PostedByIndex") .withKeySchema(iks).withProjection(new Projection().withProjectionType(ProjectionType.KEYS_ONLY)); final List<LocalSecondaryIndex> localSecondaryIndexes = new ArrayList<>(); localSecondaryIndexes.add(localSecondaryIndex); request.setLocalSecondaryIndexes(localSecondaryIndexes); return request; }
From source file:com.makariev.dynamodb.data.tables.creators.ThreadCreator.java
License:Apache License
@Override public CreateTableRequest getCreateTableRequest() { final String tableName = Thread.TABLE_NAME; final String hashKeyName = "ForumName"; final ScalarAttributeType hashKeyType = ScalarAttributeType.S; final Long readCapacityUnits = 10L; final Long writeCapacityUnits = 10L; final String rangeKeyName = "Subject"; final ScalarAttributeType rangeKeyType = ScalarAttributeType.S; //////////////// final CreateTableRequest request = basicTable(tableName, readCapacityUnits, writeCapacityUnits, hashKeyName, hashKeyType);/* ww w . j a va2 s.c o m*/ //defining range key request.getKeySchema() .add(new KeySchemaElement().withAttributeName(rangeKeyName).withKeyType(KeyType.RANGE)); //defining range key request.getAttributeDefinitions() .add(new AttributeDefinition().withAttributeName(rangeKeyName).withAttributeType(rangeKeyType)); return request; }
From source file:com.makariev.dynamodb.data.tables.creators.UserPreferenceCreator.java
License:Apache License
@Override public CreateTableRequest getCreateTableRequest() { final String tableName = UserPreference.TABLE_NAME; final String hashKeyName = "userNo"; final ScalarAttributeType hashKeyType = ScalarAttributeType.N; final Long readCapacityUnits = 10L; final Long writeCapacityUnits = 10L; //////////////// final CreateTableRequest request = basicTable(tableName, readCapacityUnits, writeCapacityUnits, hashKeyName, hashKeyType);/*from w w w . j a v a2 s .c om*/ //define GlobalSecondaryIndex request.getAttributeDefinitions().add( new AttributeDefinition().withAttributeName("firstName").withAttributeType(ScalarAttributeType.S)); request.getAttributeDefinitions().add( new AttributeDefinition().withAttributeName("lastName").withAttributeType(ScalarAttributeType.S)); // NameIndex final GlobalSecondaryIndex nameIndex = new GlobalSecondaryIndex().withIndexName(UserPreference.NAME_INDEX) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(10L).withWriteCapacityUnits(10L)) .withProjection(new Projection().withProjectionType("ALL")); final List<KeySchemaElement> indexKeySchema = new ArrayList<>(); indexKeySchema.add(new KeySchemaElement().withAttributeName("firstName").withKeyType(KeyType.HASH)); indexKeySchema.add(new KeySchemaElement().withAttributeName("lastName").withKeyType(KeyType.RANGE)); nameIndex.setKeySchema(indexKeySchema); request.withGlobalSecondaryIndexes(nameIndex); return request; }