本文整理汇总了Java中com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue类的典型用法代码示例。如果您正苦于以下问题:Java ExpectedAttributeValue类的具体用法?Java ExpectedAttributeValue怎么用?Java ExpectedAttributeValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExpectedAttributeValue类属于com.amazonaws.services.dynamodbv2.model包,在下文中一共展示了ExpectedAttributeValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: update
import com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue; //导入依赖的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.ExpectedAttributeValue; //导入依赖的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: createItemIfNotExists
import com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue; //导入依赖的package包/类
boolean createItemIfNotExists(String key, long currentTimeMillis, Context context) {
LambdaLogger logger = context.getLogger();
AmazonDynamoDB client = createDynamoDBClient(cc);
String functionName = context.getFunctionName();
try {
// Create a record if it does not exist
PutItemRequest req = new PutItemRequest().withTableName(TABLE_NAME)
.addItemEntry(COL_FUNCTION_NAME, new AttributeValue(functionName))
.addItemEntry(COL_KEY, new AttributeValue(key))
.addItemEntry(COL_CREATED_TIME, new AttributeValue().withN(Long.toString(currentTimeMillis)))
.addExpectedEntry(COL_FUNCTION_NAME, new ExpectedAttributeValue().withExists(false))
.addExpectedEntry(COL_KEY, new ExpectedAttributeValue().withExists(false));
client.putItem(req);
return true;
} catch (ConditionalCheckFailedException e) {
logger.log("Record exsited. functionName[" + functionName + "] key[" + key + "]");
return false;
} finally {
client.shutdown();
}
}
示例4: execute
import com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue; //导入依赖的package包/类
@Test
public void execute() {
Map<String, AttributeValue> key = new HashMap<String, AttributeValue>();
key.put("1", new AttributeValue("Key_1"));
exchange.getIn().setHeader(DdbConstants.KEY, key);
Map<String, ExpectedAttributeValue> updateCondition = new HashMap<String, ExpectedAttributeValue>();
updateCondition
.put("name", new ExpectedAttributeValue(new AttributeValue("expected value")));
exchange.getIn().setHeader(DdbConstants.UPDATE_CONDITION, updateCondition);
exchange.getIn().setHeader(DdbConstants.RETURN_VALUES, "ALL_OLD");
command.execute();
assertEquals("DOMAIN1", ddbClient.deleteItemRequest.getTableName());
assertEquals(key, ddbClient.deleteItemRequest.getKey());
assertEquals(updateCondition, ddbClient.deleteItemRequest.getExpected());
assertEquals("ALL_OLD", ddbClient.deleteItemRequest.getReturnValues());
assertEquals(new AttributeValue("attrValue"),
exchange.getIn().getHeader(DdbConstants.ATTRIBUTES, Map.class).get(
"attrName"));
}
示例5: execute
import com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue; //导入依赖的package包/类
@Test
public void execute() {
Map<String, AttributeValue> attributeMap = new HashMap<String, AttributeValue>();
AttributeValue attributeValue = new AttributeValue("test value");
attributeMap.put("name", attributeValue);
exchange.getIn().setHeader(DdbConstants.ITEM, attributeMap);
Map<String, ExpectedAttributeValue> expectedAttributeValueMap = new HashMap<String, ExpectedAttributeValue>();
expectedAttributeValueMap.put("name", new ExpectedAttributeValue(attributeValue));
exchange.getIn().setHeader(DdbConstants.UPDATE_CONDITION, expectedAttributeValueMap);
command.execute();
assertEquals("DOMAIN1", ddbClient.putItemRequest.getTableName());
assertEquals(attributeMap, ddbClient.putItemRequest.getItem());
assertEquals(expectedAttributeValueMap, ddbClient.putItemRequest.getExpected());
assertEquals(new AttributeValue("attrValue"),
exchange.getIn().getHeader(DdbConstants.ATTRIBUTES, Map.class).get("attrName"));
}
示例6: build
import com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue; //导入依赖的package包/类
public Map<String, ExpectedAttributeValue> build(final KCVMutation mutation) {
Preconditions.checkState(transaction != null, "Transaction must not be null");
Preconditions.checkState(key != null, "Key must not be null");
final Map<String, ExpectedAttributeValue> expected = Maps.newHashMapWithExpectedSize(mutation.getTotalMutations());
for (Entry addedColumn : mutation.getAdditions()) {
final StaticBuffer columnKey = addedColumn.getColumn();
addExpectedValueIfPresent(columnKey, expected);
}
for (StaticBuffer deletedKey : mutation.getDeletions()) {
addExpectedValueIfPresent(deletedKey, expected);
}
return expected;
}
开发者ID:awslabs,项目名称:dynamodb-janusgraph-storage-backend,代码行数:18,代码来源:SingleExpectedAttributeValueBuilder.java
示例7: addExpectedValueIfPresent
import com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue; //导入依赖的package包/类
private void addExpectedValueIfPresent(final StaticBuffer column, final Map<String, ExpectedAttributeValue> expectedValueMap) {
final String dynamoDbColumn = encodeKeyBuffer(column);
if (expectedValueMap.containsKey(dynamoDbColumn)) {
return;
}
if (transaction.contains(store, key, column)) {
final StaticBuffer expectedValue = transaction.get(store, key, column);
final ExpectedAttributeValue expectedAttributeValue;
if (expectedValue == null) {
expectedAttributeValue = new ExpectedAttributeValue().withExists(false);
} else {
final AttributeValue attributeValue = encodeValue(expectedValue);
expectedAttributeValue = new ExpectedAttributeValue().withValue(attributeValue)
.withComparisonOperator(ComparisonOperator.EQ);
}
expectedValueMap.put(dynamoDbColumn, expectedAttributeValue);
}
}
开发者ID:awslabs,项目名称:dynamodb-janusgraph-storage-backend,代码行数:21,代码来源:SingleExpectedAttributeValueBuilder.java
示例8: sendUpdateRequest
import com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue; //导入依赖的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;
}
示例9: addTask
import com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue; //导入依赖的package包/类
public static void addTask(String taskID, String task){
HashMap<String, AttributeValue> item = new HashMap<String, AttributeValue>();
item.put("taskID", new AttributeValue().withS(taskID));
item.put("Task", new AttributeValue(task));
ExpectedAttributeValue notExpected = new ExpectedAttributeValue(false);
Map<String, ExpectedAttributeValue> expected = new HashMap<String, ExpectedAttributeValue>();
expected.put("taskID", notExpected);
PutItemRequest putItemRequest = new PutItemRequest()
.withTableName(TABLE_NAME)
.withItem(item)
.withExpected(expected); //put item only if no taskID exists!
dynamoDB.putItem(putItemRequest);
}
示例10: addFilter
import com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue; //导入依赖的package包/类
public void addFilter(Map<String, ExpectedAttributeValue> expected, FieldDescriptor fieldDescriptor,
Object fieldValue) throws DataStoreException {
AttributeMapping attributeMapping = getAttributeMapping(fieldDescriptor);
if (attributeMapping.isHashKey || attributeMapping.isRangeKey) {
// Skip; we assume that the caller will use the filter
return;
}
if (!attributeMapping.isFilterable) {
throw new DataStoreException("Field not extracted: " + fieldDescriptor.getName());
}
AttributeValue attributeValue = attributeMapping.buildAttributeValue(fieldValue);
expected.put(attributeMapping.attributeName,
new ExpectedAttributeValue(attributeValue).withComparisonOperator(ComparisonOperator.EQ));
}
示例11: executeUpdate
import com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue; //导入依赖的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);
}
示例12: expectExists
import com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue; //导入依赖的package包/类
private Map<String, ExpectedAttributeValue> expectExists(Entry entry) {
Map<String, ExpectedAttributeValue> expected = new HashMap<>();
ExpectedAttributeValue expectedAttributeValue = new ExpectedAttributeValue(true);
expectedAttributeValue.setValue(new AttributeValue(getPartitionKeyValue(entry)));
expected.put(partitionKeyName.toString(), expectedAttributeValue);
// FIXME: hardcode whole file, or make generic
ExpectedAttributeValue expectedSha = new ExpectedAttributeValue(true);
expectedSha.setValue(new AttributeValue(sha(entry)));
expected.put(OPTIMISTIC_LOCK_FIELD_NAME, expectedSha);
return expected;
}
示例13: lockRequest
import com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue; //导入依赖的package包/类
private void lockRequest(DynamoDBPlanoRequest dynamoDBPlanoRequest) {
AttributeValue previousLockExpireTime = DateToStringMarshaller.instance().marshall(
dynamoDBPlanoRequest.getLockExpireTime());
Date lockExpireTime = new Date(System.currentTimeMillis() + lockDurationMs);
dynamoDBPlanoRequest.setLockExpireTime(lockExpireTime);
DynamoDBSaveExpression saveExpression = new DynamoDBSaveExpression()
.withExpectedEntry("LockExpireTime",
new ExpectedAttributeValue()
.withComparisonOperator(ComparisonOperator.EQ)
.withValue(previousLockExpireTime));
dynamoDBMapper.save(dynamoDBPlanoRequest, saveExpression);
}
示例14: insertFood
import com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue; //导入依赖的package包/类
/**
* Inserting the food into the database, dislike and like are set to 0
* @param food
*/
public static void insertFood(FoodReceive food){
Log.d(LOG_TAG, "Inserting: " + food.getName());
final DynamoDBMapper mapper = AWSMobileClient.defaultMobileClient().getDynamoDBMapper();
final FoodDO firstItem = new FoodDO();
firstItem.setFoodId(food.getFood_id());
firstItem.setRestaurantId(food.getLocation().getRestaurantId());
firstItem.setName(food.getName());
AmazonClientException lastException = null;
DynamoDBSaveExpression saveExpression = new DynamoDBSaveExpression();
Map<String, ExpectedAttributeValue> expectedAttributes =
ImmutableMapParameter.<String, ExpectedAttributeValue>builder()
.put("foodId", new ExpectedAttributeValue(false)).build();
saveExpression.setExpected(expectedAttributes);
try {
// mapper.save(firstItem);
mapper.save(firstItem, saveExpression);
} catch (ConditionalCheckFailedException e){
Log.e(LOG_TAG,"The foodId exists: " + e.getMessage());
lastException = e;
} catch (final AmazonClientException ex) {
Log.e(LOG_TAG,"Failed saving item batch: " + ex.getMessage());
lastException = ex;
}
if (lastException != null) {
// Re-throw the last exception encountered to alert the user.
throw lastException;
}
Log.d(LOG_TAG, "Insert successful");
}
示例15: execute
import com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue; //导入依赖的package包/类
@Test
public void execute() {
Map<String, AttributeValue> key = new HashMap<String, AttributeValue>();
key.put("1", new AttributeValue("Key_1"));
exchange.getIn().setHeader(DdbConstants.KEY, key);
Map<String, AttributeValueUpdate> attributeMap = new HashMap<String, AttributeValueUpdate>();
AttributeValueUpdate attributeValue = new AttributeValueUpdate(
new AttributeValue("new value"), AttributeAction.ADD);
attributeMap.put("name", attributeValue);
exchange.getIn().setHeader(DdbConstants.UPDATE_VALUES, attributeMap);
Map<String, ExpectedAttributeValue> expectedAttributeValueMap = new HashMap<String, ExpectedAttributeValue>();
expectedAttributeValueMap
.put("name", new ExpectedAttributeValue(new AttributeValue("expected value")));
exchange.getIn().setHeader(DdbConstants.UPDATE_CONDITION, expectedAttributeValueMap);
exchange.getIn().setHeader(DdbConstants.RETURN_VALUES, "ALL_OLD");
command.execute();
assertEquals("DOMAIN1", ddbClient.updateItemRequest.getTableName());
assertEquals(attributeMap, ddbClient.updateItemRequest.getAttributeUpdates());
assertEquals(key, ddbClient.updateItemRequest.getKey());
assertEquals(expectedAttributeValueMap, ddbClient.updateItemRequest.getExpected());
assertEquals("ALL_OLD", ddbClient.updateItemRequest.getReturnValues());
assertEquals(new AttributeValue("attrValue"),
exchange.getIn().getHeader(DdbConstants.ATTRIBUTES, Map.class).get(
"attrName"));
}