List of usage examples for com.amazonaws.services.dynamodbv2.model AttributeValue setS
public void setS(String s)
An attribute of type String.
From source file:com.amazon.janusgraph.diskstorage.dynamodb.DynamoDbDelegate.java
License:Open Source License
/** * Helper method that can clone an Attribute Value * * @param val the AttributeValue to copy * @param sourceDestinationMap used to avoid loops by keeping track of references * @return a copy of val//w ww . j a v a 2 s .c o m */ public static AttributeValue clone(final AttributeValue val, final IdentityHashMap<AttributeValue, AttributeValue> sourceDestinationMap) { if (val == null) { return null; } if (sourceDestinationMap.containsKey(val)) { return sourceDestinationMap.get(val); } final AttributeValue clonedVal = new AttributeValue(); sourceDestinationMap.put(val, clonedVal); if (val.getN() != null) { clonedVal.setN(val.getN()); } else if (val.getS() != null) { clonedVal.setS(val.getS()); } else if (val.getB() != null) { clonedVal.setB(val.getB()); } else if (val.getNS() != null) { clonedVal.setNS(val.getNS()); } else if (val.getSS() != null) { clonedVal.setSS(val.getSS()); } else if (val.getBS() != null) { clonedVal.setBS(val.getBS()); } else if (val.getBOOL() != null) { clonedVal.setBOOL(val.getBOOL()); } else if (val.getNULL() != null) { clonedVal.setNULL(val.getNULL()); } else if (val.getL() != null) { final List<AttributeValue> list = new ArrayList<>(val.getL().size()); for (AttributeValue listItemValue : val.getL()) { if (!sourceDestinationMap.containsKey(listItemValue)) { sourceDestinationMap.put(listItemValue, clone(listItemValue, sourceDestinationMap)); } list.add(sourceDestinationMap.get(listItemValue)); } clonedVal.setL(list); } else if (val.getM() != null) { final Map<String, AttributeValue> map = new HashMap<>(val.getM().size()); for (Entry<String, AttributeValue> pair : val.getM().entrySet()) { if (!sourceDestinationMap.containsKey(pair.getValue())) { sourceDestinationMap.put(pair.getValue(), clone(pair.getValue(), sourceDestinationMap)); } map.put(pair.getKey(), sourceDestinationMap.get(pair.getValue())); } clonedVal.setM(map); } return clonedVal; }
From source file:com.clicktravel.infrastructure.persistence.aws.dynamodb.AbstractDynamoDbTemplate.java
License:Apache License
protected final <T extends Item> Collection<PropertyDescriptor> createUniqueConstraintIndexes(final T item, final ItemConfiguration itemConfiguration, final Collection<PropertyDescriptor> constraintPropertyDescriptors) { final Set<PropertyDescriptor> createdConstraintPropertyDescriptors = new HashSet<>(); ItemConstraintViolationException itemConstraintViolationException = null; for (final UniqueConstraint uniqueConstraint : itemConfiguration.uniqueConstraints()) { final String uniqueConstraintPropertyName = uniqueConstraint.propertyName(); final PropertyDescriptor uniqueConstraintPropertyDescriptor = uniqueConstraint.propertyDescriptor(); if (constraintPropertyDescriptors.contains(uniqueConstraintPropertyDescriptor)) { final AttributeValue uniqueConstraintAttributeValue = DynamoDbPropertyMarshaller.getValue(item, uniqueConstraintPropertyDescriptor); if (uniqueConstraintAttributeValue == null) { continue; }/*from w w w . j a v a 2 s . c om*/ if (uniqueConstraintAttributeValue.getS() != null) { uniqueConstraintAttributeValue.setS(uniqueConstraintAttributeValue.getS().toUpperCase()); } final Map<String, AttributeValue> attributeMap = new HashMap<>(); attributeMap.put("property", new AttributeValue(uniqueConstraintPropertyName)); attributeMap.put("value", uniqueConstraintAttributeValue); final Map<String, ExpectedAttributeValue> expectedResults = new HashMap<>(); expectedResults.put("value", new ExpectedAttributeValue(false)); final String indexTableName = databaseSchemaHolder.schemaName() + "-indexes." + itemConfiguration.tableName(); final PutItemRequest itemRequest = new PutItemRequest().withTableName(indexTableName) .withItem(attributeMap).withExpected(expectedResults); try { amazonDynamoDbClient.putItem(itemRequest); createdConstraintPropertyDescriptors.add(uniqueConstraintPropertyDescriptor); } catch (final ConditionalCheckFailedException e) { itemConstraintViolationException = new ItemConstraintViolationException( uniqueConstraintPropertyName, "Unique constraint violation on property '" + uniqueConstraintPropertyName + "' ('" + uniqueConstraintAttributeValue + "') of item " + item.getClass()); break; } catch (final AmazonServiceException e) { throw new PersistenceResourceFailureException( "Failure while attempting DynamoDb put (creating unique constraint index entry)", e); } } } if (itemConstraintViolationException != null) { try { deleteUniqueConstraintIndexes(item, itemConfiguration, createdConstraintPropertyDescriptors); } catch (final Exception e) { logger.error(e.getMessage(), e); } throw itemConstraintViolationException; } return createdConstraintPropertyDescriptors; }
From source file:com.clicktravel.infrastructure.persistence.aws.dynamodb.AbstractDynamoDbTemplate.java
License:Apache License
protected final <T extends Item> void deleteUniqueConstraintIndexes(final T item, final ItemConfiguration itemConfiguration, final Collection<PropertyDescriptor> constraintPropertyDescriptors) { if (constraintPropertyDescriptors.isEmpty()) { return;// w ww .j ava 2 s . co m } for (final UniqueConstraint uniqueConstraint : itemConfiguration.uniqueConstraints()) { final String uniqueConstraintPropertyName = uniqueConstraint.propertyName(); final PropertyDescriptor uniqueConstraintPropertyDescriptor = uniqueConstraint.propertyDescriptor(); if (constraintPropertyDescriptors.contains(uniqueConstraintPropertyDescriptor)) { final AttributeValue uniqueConstraintAttributeValue = DynamoDbPropertyMarshaller.getValue(item, uniqueConstraintPropertyDescriptor); if (uniqueConstraintAttributeValue != null) { if (uniqueConstraintAttributeValue.getS() != null) { uniqueConstraintAttributeValue.setS(uniqueConstraintAttributeValue.getS().toUpperCase()); } final Map<String, AttributeValue> key = new HashMap<>(); key.put("property", new AttributeValue(uniqueConstraintPropertyName)); key.put("value", uniqueConstraintAttributeValue); final String indexTableName = databaseSchemaHolder.schemaName() + "-indexes." + itemConfiguration.tableName(); final DeleteItemRequest itemRequest = new DeleteItemRequest().withTableName(indexTableName) .withKey(key); try { amazonDynamoDbClient.deleteItem(itemRequest); } catch (final AmazonServiceException e) { throw new PersistenceResourceFailureException( "Failed while attempting to perform DynamoDb Delete (for unique constraints)", e); } } } } }
From source file:com.dell.doradus.db.dynamodb.DDBTransaction.java
License:Apache License
private AttributeValue mapColumnValue(String storeName, DColumn col) { AttributeValue attrValue = new AttributeValue(); if (!DBService.isSystemTable(storeName)) { if (col.getRawValue().length == 0) { attrValue.setS(DynamoDBService.NULL_COLUMN_MARKER); } else {/*from w w w . j ava 2 s.co m*/ attrValue.setB(ByteBuffer.wrap(col.getRawValue())); } } else { String strValue = col.getValue(); if (strValue.length() == 0) { strValue = DynamoDBService.NULL_COLUMN_MARKER; } attrValue.setS(strValue); } return attrValue; }
From source file:com.nandanu.halomama.controller.DynamoDBRouter.java
License:Open Source License
public void incrementSeen(String userNameTwitter, String createdDate) { UpdateItemRequest upd = new UpdateItemRequest(); upd.setTableName(Constants.TABLE_NAME); AttributeValue unt = new AttributeValue(); unt.setS(userNameTwitter); AttributeValue cd = new AttributeValue(); cd.setS(createdDate);/*from w w w . j a v a2 s . com*/ upd.addKeyEntry(Constants.TAG_USERNAME, unt); upd.addKeyEntry(Constants.TAG_CREATED_DATE, cd); AttributeValue s = new AttributeValue(); s.setN("1"); AttributeValueUpdate seen = new AttributeValueUpdate(s, AttributeAction.ADD); upd.addAttributeUpdatesEntry(Constants.TAG_SEEN, seen); dDBClient.updateItem(upd); }
From source file:com.rapid7.diskstorage.dynamodb.DynamoDBDelegate.java
License:Open Source License
/** * Helper method that can clone an Attribute Value * * @param val the AttributeValue to copy * @param sourceDestinationMap used to avoid loops by keeping track of references * @return a copy of val//w w w . j av a2s.com */ public static AttributeValue clone(AttributeValue val, IdentityHashMap<AttributeValue, AttributeValue> sourceDestinationMap) { if (val == null) { return null; } if (sourceDestinationMap.containsKey(val)) { return sourceDestinationMap.get(val); } AttributeValue clonedVal = new AttributeValue(); sourceDestinationMap.put(val, clonedVal); if (val.getN() != null) { clonedVal.setN(val.getN()); } else if (val.getS() != null) { clonedVal.setS(val.getS()); } else if (val.getB() != null) { clonedVal.setB(val.getB()); } else if (val.getNS() != null) { clonedVal.setNS(val.getNS()); } else if (val.getSS() != null) { clonedVal.setSS(val.getSS()); } else if (val.getBS() != null) { clonedVal.setBS(val.getBS()); } else if (val.getBOOL() != null) { clonedVal.setBOOL(val.getBOOL()); } else if (val.getNULL() != null) { clonedVal.setNULL(val.getNULL()); } else if (val.getL() != null) { List<AttributeValue> list = new ArrayList<>(val.getL().size()); for (AttributeValue listItemValue : val.getL()) { if (!sourceDestinationMap.containsKey(listItemValue)) { sourceDestinationMap.put(listItemValue, clone(listItemValue, sourceDestinationMap)); } list.add(sourceDestinationMap.get(listItemValue)); } clonedVal.setL(list); } else if (val.getM() != null) { Map<String, AttributeValue> map = new HashMap<>(val.getM().size()); for (Entry<String, AttributeValue> pair : val.getM().entrySet()) { if (!sourceDestinationMap.containsKey(pair.getValue())) { sourceDestinationMap.put(pair.getValue(), clone(pair.getValue(), sourceDestinationMap)); } map.put(pair.getKey(), sourceDestinationMap.get(pair.getValue())); } clonedVal.setM(map); } return clonedVal; }
From source file:jp.classmethod.aws.dynamodb.DynamoDbInternalUtils.java
License:Open Source License
private static AttributeValue clone(AttributeValue val, //NOPMD IdentityHashMap<AttributeValue, AttributeValue> sourceDestinationMap, boolean filterEmptyStrings) { if (val == null) { return null; }/*from w ww. ja v a2 s . c o m*/ if (sourceDestinationMap.containsKey(val)) { return sourceDestinationMap.get(val); } AttributeValue clonedVal = new AttributeValue(); sourceDestinationMap.put(val, clonedVal); if (val.getN() != null) { clonedVal.setN(val.getN()); } else if (val.getS() != null) { clonedVal.setS(val.getS()); } else if (val.getB() != null) { clonedVal.setB(val.getB()); } else if (val.getNS() != null) { clonedVal.setNS(val.getNS()); } else if (val.getSS() != null) { clonedVal.setSS(val.getSS()); } else if (val.getBS() != null) { clonedVal.setBS(val.getBS()); } else if (val.getBOOL() != null) { clonedVal.setBOOL(val.getBOOL()); } else if (val.getNULL() != null) { clonedVal.setNULL(val.getNULL()); } else if (val.getL() != null) { List<AttributeValue> list = new ArrayList<>(val.getL().size()); for (AttributeValue listItemValue : val.getL()) { if (!sourceDestinationMap.containsKey(listItemValue)) { sourceDestinationMap.put(listItemValue, clone(listItemValue, sourceDestinationMap, filterEmptyStrings)); } AttributeValue destination = sourceDestinationMap.get(listItemValue); if (false == (filterEmptyStrings && destination.getS() != null && destination.getS().isEmpty())) { list.add(destination); } } clonedVal.setL(list); } else if (val.getM() != null) { Map<String, AttributeValue> map = new HashMap<>(val.getM().size()); for (Map.Entry<String, AttributeValue> pair : val.getM().entrySet()) { if (!sourceDestinationMap.containsKey(pair.getValue())) { sourceDestinationMap.put(pair.getValue(), clone(pair.getValue(), sourceDestinationMap, filterEmptyStrings)); } AttributeValue destination = sourceDestinationMap.get(pair.getValue()); if (false == (filterEmptyStrings && destination.getS() != null && destination.getS().isEmpty())) { map.put(pair.getKey(), destination); } } clonedVal.setM(map); } return clonedVal; }
From source file:org.apache.beam.sdk.io.aws.dynamodb.AttributeValueCoder.java
License:Apache License
@Override public AttributeValue decode(InputStream inStream) throws IOException { AttributeValue attrValue = new AttributeValue(); String type = StringUtf8Coder.of().decode(inStream); AttributeValueType attrType = AttributeValueType.valueOf(type); switch (attrType) { case s:// w w w .j ava2 s . co m attrValue.setS(StringUtf8Coder.of().decode(inStream)); break; case n: attrValue.setN(StringUtf8Coder.of().decode(inStream)); break; case bOOL: attrValue.setBOOL(BooleanCoder.of().decode(inStream)); break; case b: attrValue.setB(ByteBuffer.wrap(ByteArrayCoder.of().decode(inStream))); break; case sS: attrValue.setSS(LIST_STRING_CODER.decode(inStream)); break; case nS: attrValue.setNS(LIST_STRING_CODER.decode(inStream)); break; case bS: attrValue.setBS(convertToListByteBuffer(LIST_BYTE_CODER.decode(inStream))); break; case l: attrValue.setL(LIST_ATTRIBUTE_CODER.decode(inStream)); break; case m: attrValue.setM(MAP_ATTRIBUTE_CODER.decode(inStream)); break; case nULLValue: attrValue.setNULL(BooleanCoder.of().decode(inStream)); break; default: throw new CoderException("Unknown Type"); } return attrValue; }
From source file:org.apache.metamodel.dynamodb.DynamoDbUtils.java
License:Apache License
public static AttributeValue toAttributeValue(Object value) { if (value instanceof AttributeValue) { return (AttributeValue) value; }/* www . java 2 s . c om*/ final AttributeValue attributeValue = new AttributeValue(); if (value == null) { attributeValue.setNULL(true); } else if (value instanceof Number) { attributeValue.setN(value.toString()); } else if (value instanceof Boolean) { attributeValue.setBOOL((Boolean) value); } else if (value instanceof String) { attributeValue.setS(value.toString()); } else { // TODO: Actually there's a few more value types we should support, // see AttributeValue.setXxxx throw new UnsupportedOperationException("Unsupported value type: " + value); } return attributeValue; }