List of usage examples for com.amazonaws.services.dynamodbv2.model AttributeValue setNS
public void setNS(java.util.Collection<String> nS)
An attribute of type Number Set.
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 w w . j ava 2s. com */ 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.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 a v a 2s . c o 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 www. j a va 2s. c om*/ 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:jp.classmethod.aws.dynamodb.DynamoDbInternalUtils.java
License:Open Source License
/** * Copied from DynamoDB Document SDK InternalUtils.java * * Converts a simple value into the low-level <code><AttributeValue/code> * representation./*from w ww .j a v a 2 s. com*/ * * @param value * the given value which can be one of the followings: * <ul> * <li>String</li> * <li>Set<String></li> * <li>Number (including any subtypes and primitive types)</li> * <li>Set<Number></li> * <li>byte[]</li> * <li>Set<byte[]></li> * <li>ByteBuffer</li> * <li>Set<ByteBuffer></li> * <li>Boolean or boolean</li> * <li>null</li> * <li>Map<String,T>, where T can be any type on this list but must not * induce any circular reference</li> * <li>List<T>, where T can be any type on this list but must not induce * any circular reference</li> * </ul> * @return a non-null low level representation of the input object value * * @throws UnsupportedOperationException * if the input object type is not supported */ public static AttributeValue toAttributeValue(Object value) { //NOPMD AttributeValue result = new AttributeValue(); if (value == null) { return result.withNULL(Boolean.TRUE); } else if (value instanceof Boolean) { return result.withBOOL((Boolean) value); } else if (value instanceof String) { return result.withS((String) value); } else if (value instanceof BigDecimal || value instanceof Number) { return result.withN(value instanceof Number ? value.toString() : ((BigDecimal) value).toPlainString()); } else if (value instanceof byte[]) { return result.withB(ByteBuffer.wrap((byte[]) value)); } else if (value instanceof ByteBuffer) { return result.withB((ByteBuffer) value); } else if (value instanceof Set) { // default to an empty string set if there is no element @SuppressWarnings("unchecked") Set<Object> set = (Set<Object>) value; if (set.isEmpty()) { result.setSS(new LinkedHashSet<>()); return result; } Object element = set.iterator().next(); if (element instanceof String) { @SuppressWarnings("unchecked") Set<String> ss = (Set<String>) value; result.setSS(new ArrayList<>(ss)); } else if (element instanceof Number) { @SuppressWarnings("unchecked") Set<Number> in = (Set<Number>) value; List<String> out = new ArrayList<>(set.size()); for (Number n : in) { BigDecimal bd = toBigDecimal(n); out.add(bd.toPlainString()); } result.setNS(out); } else if (element instanceof byte[]) { @SuppressWarnings("unchecked") Set<byte[]> in = (Set<byte[]>) value; List<ByteBuffer> out = new ArrayList<>(set.size()); for (byte[] buf : in) { out.add(ByteBuffer.wrap(buf)); } result.setBS(out); } else if (element instanceof ByteBuffer) { @SuppressWarnings("unchecked") Set<ByteBuffer> bs = (Set<ByteBuffer>) value; result.setBS(bs); } else { throw new UnsupportedOperationException("element type: " + element.getClass()); } } else if (value instanceof List) { @SuppressWarnings("unchecked") List<Object> in = (List<Object>) value; List<AttributeValue> out = new ArrayList<>(); for (Object v : in) { out.add(toAttributeValue(v)); } result.setL(out); } else if (value instanceof Map) { @SuppressWarnings("unchecked") Map<String, Object> in = (Map<String, Object>) value; if (false == in.isEmpty()) { for (Map.Entry<String, Object> e : in.entrySet()) { result.addMEntry(e.getKey(), toAttributeValue(e.getValue())); } } else { // empty map result.setM(new LinkedHashMap<>()); } } else { throw new UnsupportedOperationException("value type: " + value.getClass()); } return result; }
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 w ww . j a va2 s.c o 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; }