Java Code Examples for com.amazonaws.services.dynamodbv2.model.KeySchemaElement#getAttributeName()

The following examples show how to use com.amazonaws.services.dynamodbv2.model.KeySchemaElement#getAttributeName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DynamoDSETranslatorJSONBlob.java    From dynamo-cassandra-proxy with Apache License 2.0 6 votes vote down vote up
public String getPrimaryKey(List<KeySchemaElement> keySchema){
    String partitionKey = null;
    String clusteringColumn = null;

    for (KeySchemaElement keySchemaElement : keySchema) {
        String type = keySchemaElement.getKeyType();
        String name = keySchemaElement.getAttributeName();
        if (type.equals(HASH.toString()))
            partitionKey = name;

        else if (type.equals(RANGE.toString()))
            clusteringColumn = name;
    }
    String primaryKey;
    if(clusteringColumn != null)
        primaryKey = String.format("((\"%s\"), \"%s\")", partitionKey, clusteringColumn);
    else
        primaryKey = String.format("(\"%s\")", partitionKey);

    return primaryKey;
}
 
Example 2
Source File: DDBTableUtils.java    From aws-athena-query-federation with Apache License 2.0 5 votes vote down vote up
private static KeyNames getKeys(List<KeySchemaElement> keys)
{
    String hashKey = null;
    String rangeKey = null;
    for (KeySchemaElement key : keys) {
        if (key.getKeyType().equals(KeyType.HASH.toString())) {
            hashKey = key.getAttributeName();
        }
        else if (key.getKeyType().equals(KeyType.RANGE.toString())) {
            rangeKey = key.getAttributeName();
        }
    }
    return new KeyNames(hashKey, rangeKey);
}
 
Example 3
Source File: Request.java    From dynamodb-transactions with Apache License 2.0 5 votes vote down vote up
protected static Map<String, AttributeValue> getKeyFromItem(String tableName, Map<String, AttributeValue> item, TransactionManager txManager) {
    if(item == null) {
        throw new InvalidRequestException("PutItem must contain an Item", null, tableName, null, null);
    }
    Map<String, AttributeValue> newKey = new HashMap<String, AttributeValue>();
    List<KeySchemaElement> schema = txManager.getTableSchema(tableName);
    for(KeySchemaElement schemaElement : schema) {
        AttributeValue val = item.get(schemaElement.getAttributeName());
        if(val == null) {
            throw new InvalidRequestException("PutItem request must contain the key attribute " + schemaElement.getAttributeName(), null, tableName, null, null);
        }
        newKey.put(schemaElement.getAttributeName(), item.get(schemaElement.getAttributeName()));
    }
    return newKey;
}