Example usage for com.amazonaws.services.dynamodbv2.model ConditionalCheckFailedException ConditionalCheckFailedException

List of usage examples for com.amazonaws.services.dynamodbv2.model ConditionalCheckFailedException ConditionalCheckFailedException

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.model ConditionalCheckFailedException ConditionalCheckFailedException.

Prototype

public ConditionalCheckFailedException(String message) 

Source Link

Document

Constructs a new ConditionalCheckFailedException with the specified error message.

Usage

From source file:com.clicktravel.infrastructure.persistence.aws.dynamodb.DynamoDbTemplate.java

License:Apache License

public <T extends Item> Collection<UniqueConstraint> getUpdatedUniqueConstraints(final T item,
        final T previousItem, final ItemConfiguration itemConfiguration) {
    final Map<String, AttributeValue> previousItemAttributeMap = getAttributeMap(previousItem,
            itemConfiguration, item.getVersion());
    if (!previousItemAttributeMap.get(VERSION_ATTRIBUTE).getN().equals(String.valueOf(item.getVersion()))) {
        throw new ConditionalCheckFailedException("Version attribute has changed: Conflict!");
    }/* w w  w  .  ja  v  a  2  s  .  c  om*/
    final Map<String, AttributeValue> updateItemAttributeMap = getAttributeMap(item, itemConfiguration,
            item.getVersion());
    final Collection<String> updatedProperties = getUpdateProperties(previousItemAttributeMap,
            updateItemAttributeMap);
    final Collection<UniqueConstraint> updatedUniqueConstraints = new HashSet<>();
    for (final UniqueConstraint uniqueConstraint : itemConfiguration.uniqueConstraints()) {
        final String propertyName = uniqueConstraint.propertyDescriptor().getName();
        if (updatedProperties.contains(propertyName)) {
            final AttributeValue previousAttributeValue = previousItemAttributeMap.get(propertyName);
            final AttributeValue updatedAttributeValue = updateItemAttributeMap.get(propertyName);
            if (previousAttributeValue == null || updatedAttributeValue == null
                    || !previousAttributeValue.getS().equalsIgnoreCase(updatedAttributeValue.getS())) {
                updatedUniqueConstraints.add(uniqueConstraint);
            }
        }
    }
    return updatedUniqueConstraints;
}