本文整理匯總了Java中com.amazonaws.services.dynamodbv2.model.KeySchemaElement.getAttributeName方法的典型用法代碼示例。如果您正苦於以下問題:Java KeySchemaElement.getAttributeName方法的具體用法?Java KeySchemaElement.getAttributeName怎麽用?Java KeySchemaElement.getAttributeName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.amazonaws.services.dynamodbv2.model.KeySchemaElement
的用法示例。
在下文中一共展示了KeySchemaElement.getAttributeName方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildHashKey
import com.amazonaws.services.dynamodbv2.model.KeySchemaElement; //導入方法依賴的package包/類
/**
* Builds hash key attribute from generic query received.
*
* @param qKey
*
* @returnAttributeValue build from query
*/
private Map<String, AttributeValue> buildHashKey(K qKey) {
Map<String, AttributeValue> hashKey = new HashMap<>();
for (KeySchemaElement key : getKeySchema()) {
AttributeValue attr = new AttributeValue();
if (key.getKeyType().equals(KeyType.HASH.toString())) {
if (keyItems.get(key.getAttributeName()).equals("N")) {
attr.withN(getHashKey(qKey).toString());
} else if (keyItems.get(key.getAttributeName()).equals("S")) {
attr.withS(getHashKey(qKey).toString());
} else if (keyItems.get(key.getAttributeName()).equals("B")) {
attr.withB(ByteBuffer.wrap(getHashKey(qKey).toString().getBytes(Charset.defaultCharset())));
} else {
throw new IllegalArgumentException("Data type not supported for "
+ key.getAttributeName());
}
hashKey.put(key.getAttributeName(), attr);
}
}
if (hashKey.isEmpty()) {
throw new IllegalStateException("No key value has been defined.");
}
return hashKey;
}
示例2: buildRangeKey
import com.amazonaws.services.dynamodbv2.model.KeySchemaElement; //導入方法依賴的package包/類
/**
* Builds range key attribute from generic query received.
*
* @param qKey
*
* @return
*/
private Map<String, AttributeValue> buildRangeKey(K qKey) {
Map<String, AttributeValue> kAttrs = new HashMap<>();
for (KeySchemaElement key : getKeySchema()) {
AttributeValue attr = new AttributeValue();
if (key.getKeyType().equals(KeyType.RANGE.toString())) {
if (keyItems.get(key.getAttributeName()).equals("N")) {
attr.withN(getRangeKey(qKey).toString());
} else if (keyItems.get(key.getAttributeName()).equals("S")) {
attr.withS(getRangeKey(qKey).toString());
} else if (keyItems.get(key.getAttributeName()).equals("B")) {
attr.withB(ByteBuffer.wrap(getRangeKey(qKey).toString().getBytes(Charset.defaultCharset())));
} else {
throw new IllegalArgumentException("Data type not supported for "
+ key.getAttributeName());
}
kAttrs.put(key.getAttributeName(), attr);
}
}
return kAttrs;
}
示例3: addColumnFromKeySchema
import com.amazonaws.services.dynamodbv2.model.KeySchemaElement; //導入方法依賴的package包/類
private void addColumnFromKeySchema(String indexName, List<KeySchemaElement> keySchema, MutableTable table,
boolean primaryKey) {
for (final KeySchemaElement keySchemaElement : keySchema) {
final String attributeName = keySchemaElement.getAttributeName();
if (table.getColumnByName(attributeName) == null) {
final String keyType = keySchemaElement.getKeyType();
final MutableColumn column = new MutableColumn(attributeName, table).setPrimaryKey(primaryKey);
appendRemarks(column, indexName + " member ('" + keyType + "' type)");
table.addColumn(column);
}
}
}
示例4: cleanupAggTable
import com.amazonaws.services.dynamodbv2.model.KeySchemaElement; //導入方法依賴的package包/類
public static void cleanupAggTable(AWSCredentialsProvider credentials,
Region region, final String dynamoTable, final String toSeq)
throws Exception {
final Double deleteBelow = Double.parseDouble(toSeq);
// create two clients - one synchronous for the read of all candidate
// values, and another for the delete operations
final AmazonDynamoDB dynamoClient = new AmazonDynamoDBClient(
credentials);
if (region != null)
dynamoClient.setRegion(region);
final AmazonDynamoDBAsyncClient deleteCli = new AmazonDynamoDBAsyncClient(
credentials);
deleteCli.setRegion(region);
Map<String, AttributeValue> lastKey = null;
Map<String, AttributeValue> deleteKey = null;
// work out what the key and date column name is
String keyColumn = null;
String dateColumn = null;
List<KeySchemaElement> keySchema = dynamoClient
.describeTable(dynamoTable).getTable().getKeySchema();
for (KeySchemaElement element : keySchema) {
if (element.getKeyType().equals(KeyType.HASH.name()))
keyColumn = element.getAttributeName();
if (element.getKeyType().equals(KeyType.RANGE.name()))
dateColumn = element.getAttributeName();
}
LOG.info(String.format(
"Deleting data from %s where %s values are below %s",
dynamoTable, StreamAggregator.LAST_WRITE_SEQ, deleteBelow));
int deleteCount = 0;
do {
// read data from the table
ScanRequest scan = new ScanRequest()
.withTableName(dynamoTable)
.withAttributesToGet(keyColumn, dateColumn,
StreamAggregator.LAST_WRITE_SEQ)
.withExclusiveStartKey(lastKey);
ScanResult results = dynamoClient.scan(scan);
// delete everything up to the system provided change number
for (Map<String, AttributeValue> map : results.getItems()) {
deleteKey = new HashMap<>();
deleteKey.put(keyColumn, map.get(keyColumn));
deleteKey.put(dateColumn, map.get(dateColumn));
if (Double.parseDouble(map.get(StreamAggregator.LAST_WRITE_SEQ)
.getS()) < deleteBelow) {
deleteCli.deleteItem(dynamoTable, deleteKey);
deleteCount++;
}
}
lastKey = results.getLastEvaluatedKey();
} while (lastKey != null);
LOG.info(String.format(
"Operation Complete - %s Records removed from Aggregate Store",
deleteCount));
}