List of usage examples for com.amazonaws.services.dynamodbv2.model AttributeValue setN
public void setN(String n)
An attribute of type Number.
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 . ja va2s .co 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.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);//w w w .j av a 2s .com AttributeValue cd = new AttributeValue(); cd.setS(createdDate); 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//from w ww . j a v a 2 s .co m */ 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 w w. java2s . 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://from www . ja va 2s . 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; }//from www . j a v a 2s.c o m 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; }