Database Reference
In-Depth Information
ArrayList<AttributeDefinition> attributeDefinitions =
newArrayList<AttributeDefinition>();
attributeDefinitions.add(new AttributeDefinition()
.withAttributeName("BookTitle")
.withAttributeType("S"));
attributeDefinitions.add(new AttributeDefinition()
.withAttributeName("Author")
.withAttributeType("S"));
attributeDefinitions.add(new AttributeDefinition()
.withAttributeName("PubDate")
.withAttributeType("S"));
attributeDefinitions.add(new AttributeDefinition()
.withAttributeName("Publisher")
.withAttributeType("S"));
attributeDefinitions.add(new AttributeDefinition()
.withAttributeName("Edition")
.withAttributeType("N"));
return attributeDefinitions;
}
The next method will return
ArrayList
of the
KeySchemaElement
type. To this
ArrayList
, we are adding two
KeySchemaElement
. The first element is to set the
BookTitle
attribute as the hash key type and the second element is to set the
Author
attribute as the range key type. Finally we return this
ArrayList
as shown in the fol-
lowing code:
private static ArrayList<KeySchemaElement>
getTableKeySchema() {
ArrayList<KeySchemaElement> ks =
newArrayList<KeySchemaElement>();
ks.add(new KeySchemaElement()
.withAttributeName("BookTitle")
.withKeyType(KeyType.HASH));
ks.add(new KeySchemaElement()
.withAttributeName("Author")
.withKeyType(KeyType.RANGE));
return ks;
}