use of com.amazonaws.mobileconnectors.dynamodbv2.document.internal.KeyDescription in project aws-sdk-android by aws-amplify.
the class Table method loadTableDescription.
/**
* Load table description.
*/
public void loadTableDescription() {
clear();
final DescribeTableRequest request = Table.appendDynamoDBDocumentUserAgentString(new DescribeTableRequest(this.tableName));
final DescribeTableResult result = client.describeTable(request);
this.tableDescription = result.getTable();
for (final KeySchemaElement element : this.tableDescription.getKeySchema()) {
final String keyName = element.getAttributeName();
for (final AttributeDefinition ad : this.tableDescription.getAttributeDefinitions()) {
if (ad.getAttributeName().equals(keyName)) {
final KeyDescription kd = new KeyDescription();
kd.setHash("HASH".equalsIgnoreCase(element.getKeyType()));
kd.setType(getType(ad.getAttributeType()));
if (kd.isHash()) {
this.hashKeys.add(keyName);
} else {
this.rangeKeys.add(keyName);
}
this.keys.put(keyName, kd);
break;
}
}
}
if (this.tableDescription.getLocalSecondaryIndexes() != null) {
for (final LocalSecondaryIndexDescription index : this.tableDescription.getLocalSecondaryIndexes()) {
this.localSecondaryIndexes.put(index.getIndexName(), index);
this.localSecondaryIndexNames.add(index.getIndexName());
}
}
if (this.tableDescription.getGlobalSecondaryIndexes() != null) {
for (final GlobalSecondaryIndexDescription index : this.tableDescription.getGlobalSecondaryIndexes()) {
this.globalSecondaryIndexes.put(index.getIndexName(), index);
this.globalSecondaryIndexNames.add(index.getIndexName());
}
}
for (final AttributeDefinition ad : this.tableDescription.getAttributeDefinitions()) {
this.attributes.add(ad);
}
}
use of com.amazonaws.mobileconnectors.dynamodbv2.document.internal.KeyDescription in project aws-sdk-android by aws-amplify.
the class Table method makeKey.
private Key makeKey(Primitive hashKey, Primitive rangeKey) {
final Key key = new Key();
if (this.hashKeys.size() != 1) {
throw new IllegalStateException("no hashkeys in table");
}
final String hashKeyName = this.hashKeys.get(0);
final KeyDescription keyDescription = this.keys.get(hashKeyName);
if (keyDescription.getType() != hashKey.getType()) {
throw new IllegalStateException("hash key type does not match the one in table definition");
}
final AttributeValue av = hashKey.convertToAttributeValue();
key.put(hashKeyName, av);
if (rangeKey == null && this.rangeKeys.size() > 0) {
throw new IllegalStateException("range key not specificed for a table with range keys");
} else if (rangeKey != null) {
final String rangeKeyName = this.rangeKeys.get(0);
final KeyDescription kd = this.keys.get(rangeKeyName);
if (kd.getType() != rangeKey.getType()) {
throw new IllegalStateException("range key type does not match that of table definition");
}
final AttributeValue rangeKeyAttributeValue = rangeKey.convertToAttributeValue();
key.put(rangeKeyName, rangeKeyAttributeValue);
}
return key;
}
use of com.amazonaws.mobileconnectors.dynamodbv2.document.internal.KeyDescription in project aws-sdk-android by aws-amplify.
the class Table method makeKey.
private Key makeKey(Document doc) {
final Key key = new Key();
for (final Entry<String, KeyDescription> kvp : this.keys.entrySet()) {
final String keyName = kvp.getKey();
final KeyDescription description = kvp.getValue();
final DynamoDBEntry value = doc.get(keyName);
if (value == null) {
throw new IllegalStateException("no value for key " + keyName);
}
final Primitive primitive = value.asPrimitive();
if (primitive == null) {
throw new IllegalStateException("Key attribute " + keyName + " must be a Primitive type");
}
if (primitive.getType() != description.getType()) {
throw new IllegalStateException("Key attribute " + keyName + " must be of type " + description.getType());
}
key.put(keyName, primitive.convertToAttributeValue());
}
return key;
}
Aggregations