
com.amazon.titan.diskstorage.dynamodb.builder.SingleExpectedAttributeValueBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dynamodb-titan054-storage-backend Show documentation
Show all versions of dynamodb-titan054-storage-backend Show documentation
The Amazon DynamoDB Storage Backend for Titan: Distributed Graph Database allows Titan graphs to use DynamoDB as a storage backend.
The newest version!
/*
* Copyright 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.amazon.titan.diskstorage.dynamodb.builder;
import java.util.Map;
import com.amazon.titan.diskstorage.dynamodb.DynamoDBStoreTransaction;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.ComparisonOperator;
import com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue;
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
import com.thinkaurelius.titan.diskstorage.Entry;
import com.thinkaurelius.titan.diskstorage.StaticBuffer;
import com.thinkaurelius.titan.diskstorage.keycolumnvalue.KCVMutation;
/**
* Builder for ExpectedAttributeValue maps for updates to SINGLE records.
* We avoid the use of expressions here
* because we can exceed the max expression size for very large updates.
* @author Michael Rodaitis
*/
public class SingleExpectedAttributeValueBuilder extends AbstractBuilder {
private DynamoDBStoreTransaction txh = null;
private StaticBuffer key = null;
public SingleExpectedAttributeValueBuilder transaction(DynamoDBStoreTransaction txh) {
this.txh = txh;
return this;
}
public SingleExpectedAttributeValueBuilder key(StaticBuffer key) {
this.key = key;
return this;
}
public Map build(KCVMutation mutation) {
Preconditions.checkState(txh != null, "Transaction must not be null");
Preconditions.checkState(key != null, "Key must not be null");
final Map expected = Maps.newHashMapWithExpectedSize(mutation.getTotalMutations());
for (Entry addedColumn : mutation.getAdditions()) {
final StaticBuffer columnKey = addedColumn.getColumn();
addExpectedValueIfPresent(key, columnKey, expected);
}
for (StaticBuffer deletedKey : mutation.getDeletions()) {
addExpectedValueIfPresent(key, deletedKey, expected);
}
return expected;
}
private void addExpectedValueIfPresent(StaticBuffer key, StaticBuffer column, Map expectedValueMap) {
final String dynamoDbColumn = encodeKeyBuffer(column);
if (expectedValueMap.containsKey(dynamoDbColumn)) {
return;
}
if (txh.contains(key, column)) {
final StaticBuffer expectedValue = txh.get(key, column);
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);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy