本文整理汇总了Java中com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate类的典型用法代码示例。如果您正苦于以下问题:Java AttributeValueUpdate类的具体用法?Java AttributeValueUpdate怎么用?Java AttributeValueUpdate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AttributeValueUpdate类属于com.amazonaws.services.dynamodbv2.model包,在下文中一共展示了AttributeValueUpdate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: update
import com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate; //导入依赖的package包/类
@Override
public void update(Entry entry, Entry existingEntry) {
readWriteLock.writeLock().lock();
try {
Map<String, AttributeValue> keys = createKey(entry);
Map<String, AttributeValueUpdate> attributes = createAttributes(entry);
Map<String, ExpectedAttributeValue> expected = expectExists(existingEntry);
try {
executeUpdate(keys, attributes, expected);
} catch (ConditionalCheckFailedException e) {
throw new DoesNotExistException("Precondition to update entry in DynamoDB failed:" + keys.toString());
}
} finally {
readWriteLock.writeLock().unlock();
}
}
示例2: create
import com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate; //导入依赖的package包/类
@Override
public void create(Entry entry) {
readWriteLock.writeLock().lock();
try {
Map<String, AttributeValue> keys = createKey(entry);
Map<String, AttributeValueUpdate> attributes = createAttributes(entry);
Map<String, ExpectedAttributeValue> expected = expectNotExists();
try {
executeUpdate(keys, attributes, expected);
} catch (ConditionalCheckFailedException e) {
throw new AlreadyExistsException("DynamoDB store entry already exists:" + keys.toString());
}
} finally {
readWriteLock.writeLock().unlock();
}
}
示例3: createAttributes
import com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate; //导入依赖的package包/类
private Map<String, AttributeValueUpdate> createAttributes(Entry entry) {
Map<String, AttributeValueUpdate> attributes = new HashMap<>();
attributes.put(SCHEMA_VERSION_FIELD_NAME, new AttributeValueUpdate()
.withAction(AttributeAction.PUT)
.withValue(new AttributeValue().withN(SCHEMA_VERSION)));
attributes.put(OPTIMISTIC_LOCK_FIELD_NAME, new AttributeValueUpdate()
.withAction(AttributeAction.PUT)
.withValue(new AttributeValue().withS(sha(entry))));
for (Map.Entry<Integer, String> e : attributeMappings.entrySet()) {
Object value = getValue(entry, e.getValue());
if (value != null) {
attributes.put(e.getKey().toString(),
new AttributeValueUpdate()
.withAction(AttributeAction.PUT)
.withValue(getAttribute(value)));
}
}
return attributes;
}
示例4: createsOnlyThreeOpenLogs
import com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate; //导入依赖的package包/类
@Test
public void createsOnlyThreeOpenLogs() throws Exception {
final User user = new DyUser(new Dynamo(), "yegor256");
final Script script = user.script("test5");
final AttributeValueUpdate upd = new AttributeValueUpdate().withValue(
new AttributeValue().withN(
Long.toString(System.currentTimeMillis())
)
).withAction(AttributeAction.PUT);
// @checkstyle MagicNumber (1 line)
for (int idx = 0; idx < 3; ++idx) {
final Item item = script.open().iterator().next();
item.put("finish", upd);
}
MatcherAssert.assertThat(
script.open(),
Matchers.emptyIterable()
);
}
示例5: updateItem
import com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate; //导入依赖的package包/类
public static void updateItem(AmazonDynamoDBClient client, String tableName, String id, String val) {
java.util.Map<String, AttributeValue> key = new HashMap<String, AttributeValue>();
key.put("Id", new AttributeValue().withN(id));
Map<String, AttributeValueUpdate> attributeUpdates = new HashMap<String, AttributeValueUpdate>();
AttributeValueUpdate update = new AttributeValueUpdate()
.withAction(AttributeAction.PUT)
.withValue(new AttributeValue().withS(val));
attributeUpdates.put("attribute-2", update);
UpdateItemRequest updateItemRequest = new UpdateItemRequest()
.withTableName(tableName)
.withKey(key)
.withAttributeUpdates(attributeUpdates);
client.updateItem(updateItemRequest);
}
示例6: sendUpdateRequest
import com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate; //导入依赖的package包/类
/**
* Sends an update request to the service and returns true if the request is successful.
*/
public boolean sendUpdateRequest(Map<String, AttributeValue> primaryKey, Map<String, AttributeValueUpdate> updateItems,
Map<String, ExpectedAttributeValue> expectedItems) throws Exception {
if (updateItems.isEmpty()) {
return false; // No update, return false
}
UpdateItemRequest updateItemRequest = new UpdateItemRequest().withTableName(tableName).withKey(primaryKey).withReturnValues(ReturnValue.UPDATED_NEW)
.withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL).withAttributeUpdates(updateItems);
if (expectedItems != null) {
updateItemRequest.withExpected(expectedItems);
}
UpdateItemResult result = dynamoDBClient.updateItem(updateItemRequest);
if(!isRunningOnDDBLocal) {
// DDB Local does not support rate limiting
tableWriteRateLimiter.adjustRateWithConsumedCapacity(result.getConsumedCapacity());
}
return true;
}
示例7: genUpdateItemsForRecord
import com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate; //导入依赖的package包/类
protected Map<String, AttributeValueUpdate> genUpdateItemsForRecord() {
Map<String, AttributeValueUpdate> updateItems = null;
AttributeValue GSIHashKeyUpdateValue = tableWriter.genAttributeValueForGSIKey(options.getGsiHashKeyType(), getNextGsiHashKeyUpdateValue());
AttributeValue GSIRangeKeyUpdateValue = tableWriter.genAttributeValueForGSIKey(options.getGsiRangeKeyType(), getNextGsiRangeKeyUpdateValue());
// Find if gsi hash key/range key has violations. This will be needed when both hash and range violations
// are to be found but only one has a violation.
String gsiHashKeyName = getNextGsiHashKeyViolationType() == null ? null : options.getGsiHashKeyName();
String gsiRangeKeyName = getNextGsiRangeKeyViolationType() == null ? null : options.getGsiRangeKeyName();
boolean deleteBlank = getNextDeleteBlankAttribute();
if (deleteBlank) {
updateItems = genUpdateItemsWithEmptyAttributeDeleted(gsiHashKeyName, GSIHashKeyUpdateValue, gsiRangeKeyName,
GSIRangeKeyUpdateValue);
} else {
updateItems = genUpdateItemsWithEmptyAttributeKept(gsiHashKeyName, GSIHashKeyUpdateValue, gsiRangeKeyName,
GSIRangeKeyUpdateValue);
}
return updateItems;
}
示例8: genUpdateItemsWithEmptyAttributeKept
import com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate; //导入依赖的package包/类
/**
* Do nothing to an attribute if update value for it is null.
*/
public Map<String, AttributeValueUpdate> genUpdateItemsWithEmptyAttributeKept(String GSIHashKeyName, AttributeValue GSIHashKeyUpdateValue,
String GSIRangeKeyName, AttributeValue GSIRangeKeyUpdateValue) {
Map<String, AttributeValueUpdate> updateItems = new HashMap<String, AttributeValueUpdate>();
boolean updateFound = false;
if (GSIHashKeyName != null && GSIHashKeyUpdateValue != null) {
updateItems.put(GSIHashKeyName, new AttributeValueUpdate().withAction(AttributeAction.PUT).withValue(GSIHashKeyUpdateValue));
updateFound = true;
}
if (GSIRangeKeyName != null && GSIRangeKeyUpdateValue != null) {
updateItems.put(GSIRangeKeyName, new AttributeValueUpdate().withAction(AttributeAction.PUT).withValue(GSIRangeKeyUpdateValue));
updateFound = true;
}
if(updateFound) {
violationUpdateRequests++;
}
return updateItems;
}
示例9: test_updateItem_WithAllParameters
import com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate; //导入依赖的package包/类
@Test
public void test_updateItem_WithAllParameters() throws Exception {
createTable();
putItem(TEST_ATTRIBUTE, TEST_ATTRIBUTE_VALUE);
String UPDATE_ATTRIBUTE_VALUE = "UpdateAttributeValue1";
Map<String, AttributeValue> key = new HashMap<String, AttributeValue>();
key.put(TEST_ATTRIBUTE, new AttributeValue()
.withS(TEST_ATTRIBUTE_VALUE));
Map<String, AttributeValueUpdate> attributeUpdates = new HashMap<String, AttributeValueUpdate>();
attributeUpdates.put(TEST_ATTRIBUTE, new AttributeValueUpdate()
.withAction(AttributeAction.PUT)
.withValue(new AttributeValue()
.withS(UPDATE_ATTRIBUTE_VALUE)));
String returnValues = "";
UpdateItemResult result = dynamoDb.updateItem(TEST_TABLE_NAME, key, attributeUpdates, returnValues);
Double units = result.getConsumedCapacity().getCapacityUnits();
GetItemResult getItemResult = getItem(TEST_ATTRIBUTE, UPDATE_ATTRIBUTE_VALUE);
String updatedValue = getItemResult.getItem().get(TEST_ATTRIBUTE).getS();
assertThat(units.doubleValue(), equalTo(1.0));
assertThat(updatedValue, equalTo(UPDATE_ATTRIBUTE_VALUE));
}
示例10: updateEntityByUniqueId
import com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate; //导入依赖的package包/类
/**
* Move or rename entity to other folder
*
* @param entity
* - current entity want to move or rename
* @param newParent
* - parent of entity
* @param newEntityName
* - new name of entity
* @param isRenamingAction
* - TRUE is renaming file, otherwise FALSE
* @return TRUE/FALSE
*/
@Override
public boolean updateEntityByUniqueId(String tableName, Entity entity, Folder newParent,
String newEntityName, boolean isRenamingAction) {
HashMap<String, AttributeValue> primaryKey = new HashMap<String, AttributeValue>();
primaryKey.put(AttributeKey.UUID, new AttributeValue().withS(entity.getId().toString()));
Map<String, AttributeValueUpdate> updateItems = new HashMap<String, AttributeValueUpdate>();
updateItems.put(AttributeKey.ENTITY_NAME, new AttributeValueUpdate()
.withAction(AttributeAction.PUT).withValue(new AttributeValue().withS(newEntityName)));
updateItems.put(AttributeKey.MODIFIED_DATE, new AttributeValueUpdate()
.withAction(AttributeAction.PUT).withValue(new AttributeValue().withS(DateUtils.dateToString(new Date()))));
if (!isRenamingAction) {
updateItems.put(AttributeKey.PARENT_UUID, new AttributeValueUpdate()
.withAction(AttributeAction.PUT).withValue(new AttributeValue()
.withS(newParent.getId().toString())));
}
UpdateItemResult updateStatus = dynamoDBService.updateItem(tableName, primaryKey, updateItems);
if (updateStatus != null) {
return true;
}
return false;
}
示例11: updateRow
import com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate; //导入依赖的package包/类
private void updateRow(String key, String appid, Map<String, AttributeValue> row) {
if (StringUtils.isBlank(key) || StringUtils.isBlank(appid) || row == null || row.isEmpty()) {
return;
}
Map<String, AttributeValueUpdate> rou = new HashMap<>();
try {
for (Entry<String, AttributeValue> attr : row.entrySet()) {
rou.put(attr.getKey(), new AttributeValueUpdate(attr.getValue(), AttributeAction.PUT));
}
UpdateItemRequest updateItemRequest = new UpdateItemRequest(getTableNameForAppid(appid),
Collections.singletonMap(Config._KEY, new AttributeValue(getKeyForAppid(key, appid))), rou);
client().updateItem(updateItemRequest);
} catch (Exception e) {
logger.error("Could not update row in DB - appid={}, key={}", appid, key, e);
}
}
示例12: toString
import com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate; //导入依赖的package包/类
@Override
public String toString() {
final Collection<String> terms =
new ArrayList<String>(this.attrs.size());
for (final Map.Entry<String, AttributeValueUpdate> attr
: this.attrs.entrySet()) {
terms.add(
String.format(
"%s=%s",
attr.getKey(),
attr.getValue()
)
);
}
return Joiner.on("; ").join(terms);
}
示例13: storesAndReadsSingleAttribute
import com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate; //导入依赖的package包/类
/**
* MkRegion can store and read items.
* @throws Exception If some problem inside
*/
@Test
public void storesAndReadsSingleAttribute() throws Exception {
final String table = "ideas";
final String key = "number";
final String attr = "total";
final Region region = new MkRegion(
new H2Data().with(table, new String[] {key}, attr)
);
final Table tbl = region.table(table);
tbl.put(
new Attributes()
.with(key, "32443")
.with(attr, "0")
);
final Item item = tbl.frame().iterator().next();
item.put(
attr,
new AttributeValueUpdate().withValue(
new AttributeValue().withN("2")
).withAction(AttributeAction.PUT)
);
MatcherAssert.assertThat(item.get(attr).getN(), Matchers.equalTo("2"));
}
示例14: putThrowsException
import com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate; //导入依赖的package包/类
/**
* AttributesUpdates can throw exception when put is called.
*/
@Test
public void putThrowsException() {
boolean passed;
try {
new AttributeUpdates().put(
"key9", Mockito.mock(AttributeValueUpdate.class)
);
passed = false;
} catch (final UnsupportedOperationException ex) {
passed = true;
}
if (!passed) {
Assert.fail("#put should not be supported");
}
}
示例15: executeUpdate
import com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate; //导入依赖的package包/类
private void executeUpdate(Map<String, AttributeValue> keys, Map<String, AttributeValueUpdate> attributes, Map<String, ExpectedAttributeValue> expected) {
UpdateItemRequest updateEntry = new UpdateItemRequest()
.withTableName(tableName)
.withKey(keys)
.withAttributeUpdates(attributes)
.withExpected(expected);
client.updateItem(updateEntry);
}