List of usage examples for com.amazonaws.services.dynamodbv2.model AttributeValue getNULL
public Boolean getNULL()
An attribute of type Null.
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/*ww w . j a v a2 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.amazon.janusgraph.diskstorage.dynamodb.DynamoDbDelegate.java
License:Open Source License
/**Calculate attribute value size*/ private static int calculateAttributeSizeInBytes(final AttributeValue value) { int attrValSize = 0; if (value == null) { return attrValSize; }//from w ww . j a v a2s. c om if (value.getB() != null) { final ByteBuffer b = value.getB(); attrValSize += b.remaining(); } else if (value.getS() != null) { final String s = value.getS(); attrValSize += s.getBytes(UTF8).length; } else if (value.getN() != null) { attrValSize += MAX_NUMBER_OF_BYTES_FOR_NUMBER; } else if (value.getBS() != null) { final List<ByteBuffer> bs = value.getBS(); for (ByteBuffer b : bs) { if (b != null) { attrValSize += b.remaining(); } } } else if (value.getSS() != null) { final List<String> ss = value.getSS(); for (String s : ss) { if (s != null) { attrValSize += s.getBytes(UTF8).length; } } } else if (value.getNS() != null) { final List<String> ns = value.getNS(); for (String n : ns) { if (n != null) { attrValSize += MAX_NUMBER_OF_BYTES_FOR_NUMBER; } } } else if (value.getBOOL() != null) { attrValSize += 1; } else if (value.getNULL() != null) { attrValSize += 1; } else if (value.getM() != null) { for (Map.Entry<String, AttributeValue> entry : value.getM().entrySet()) { attrValSize += entry.getKey().getBytes(UTF8).length; attrValSize += calculateAttributeSizeInBytes(entry.getValue()); attrValSize += BASE_LOGICAL_SIZE_OF_NESTED_TYPES; } attrValSize += LOGICAL_SIZE_OF_EMPTY_DOCUMENT; } else if (value.getL() != null) { final List<AttributeValue> list = value.getL(); for (Integer i = 0; i < list.size(); i++) { attrValSize += calculateAttributeSizeInBytes(list.get(i)); attrValSize += BASE_LOGICAL_SIZE_OF_NESTED_TYPES; } attrValSize += LOGICAL_SIZE_OF_EMPTY_DOCUMENT; } return attrValSize; }
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 ww w . 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:com.rapid7.diskstorage.dynamodb.DynamoDBDelegate.java
License:Open Source License
/**Calculate attribute value size*/ private static int calculateAttributeSizeInBytes(AttributeValue value) { int attrValSize = 0; if (value == null) { return attrValSize; }/*from w ww . j a v a 2s . c o m*/ if (value.getB() != null) { ByteBuffer b = value.getB(); attrValSize += b.remaining(); } else if (value.getS() != null) { String s = value.getS(); attrValSize += s.getBytes(UTF8).length; } else if (value.getN() != null) { attrValSize += MAX_NUMBER_OF_BYTES_FOR_NUMBER; } else if (value.getBS() != null) { List<ByteBuffer> bs = value.getBS(); for (ByteBuffer b : bs) { if (b != null) { attrValSize += b.remaining(); } } } else if (value.getSS() != null) { List<String> ss = value.getSS(); for (String s : ss) { if (s != null) { attrValSize += s.getBytes(UTF8).length; } } } else if (value.getNS() != null) { List<String> ns = value.getNS(); for (String n : ns) { if (n != null) { attrValSize += MAX_NUMBER_OF_BYTES_FOR_NUMBER; } } } else if (value.getBOOL() != null) { attrValSize += 1; } else if (value.getNULL() != null) { attrValSize += 1; } else if (value.getM() != null) { for (Map.Entry<String, AttributeValue> entry : value.getM().entrySet()) { attrValSize += entry.getKey().getBytes(UTF8).length; attrValSize += calculateAttributeSizeInBytes(entry.getValue()); attrValSize += BASE_LOGICAL_SIZE_OF_NESTED_TYPES; } attrValSize += LOGICAL_SIZE_OF_EMPTY_DOCUMENT; } else if (value.getL() != null) { List<AttributeValue> list = value.getL(); for (Integer i = 0; i < list.size(); i++) { attrValSize += calculateAttributeSizeInBytes(list.get(i)); attrValSize += BASE_LOGICAL_SIZE_OF_NESTED_TYPES; } attrValSize += LOGICAL_SIZE_OF_EMPTY_DOCUMENT; } return attrValSize; }
From source file:dynamok.source.RecordMapper.java
License:Apache License
public static Map<String, Struct> toConnect(Map<String, AttributeValue> attributes) { Map<String, Struct> connectAttributes = new HashMap<>(attributes.size()); for (Map.Entry<String, AttributeValue> attribute : attributes.entrySet()) { final String attributeName = attribute.getKey(); final AttributeValue attributeValue = attribute.getValue(); final Struct attributeValueStruct = new Struct(AV_SCHEMA); if (attributeValue.getS() != null) { attributeValueStruct.put("S", attributeValue.getS()); } else if (attributeValue.getN() != null) { attributeValueStruct.put("N", attributeValue.getN()); } else if (attributeValue.getB() != null) { attributeValueStruct.put("B", attributeValue.getB()); } else if (attributeValue.getSS() != null) { attributeValueStruct.put("SS", attributeValue.getSS()); } else if (attributeValue.getNS() != null) { attributeValueStruct.put("NS", attributeValue.getNS()); } else if (attributeValue.getBS() != null) { attributeValueStruct.put("BS", attributeValue.getBS()); } else if (attributeValue.getNULL() != null) { attributeValueStruct.put("NULL", attributeValue.getNULL()); } else if (attributeValue.getBOOL() != null) { attributeValueStruct.put("BOOL", attributeValue.getBOOL()); }//from w w w . ja v a 2 s .c om connectAttributes.put(attributeName, attributeValueStruct); } return connectAttributes; }
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; }/* ww w . ja v a 2s . 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:jp.classmethod.aws.dynamodb.DynamoDbInternalUtils.java
License:Open Source License
/** * Copied from DynamoDB Document SDK InternalUtils.java * * Converts a low-level <code>AttributeValue</code> into a simple value, * which can be one of the followings:/*from w w w .j a va 2 s . c o m*/ * * <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> * * @throws IllegalArgumentException * if an empty <code>AttributeValue</code> value is specified */ @SuppressWarnings("unchecked") private static <T> T toSimpleValue(AttributeValue value) { //NOPMD if (value == null) { return null; } if (Boolean.FALSE.equals(value.getNULL())) { throw new UnsupportedOperationException("False-NULL is not supported in DynamoDB"); } final T t; if (Boolean.TRUE.equals(value.getNULL())) { t = null; } else if (value.getBOOL() != null) { t = (T) value.getBOOL(); } else if (value.getS() != null) { t = (T) value.getS(); } else if (value.getN() != null) { t = (T) new BigDecimal(value.getN()); } else if (value.getB() != null) { t = (T) copyAllBytesFrom(value.getB()); } else if (value.getSS() != null) { t = (T) new LinkedHashSet<>(value.getSS()); } else if (value.getNS() != null) { Set<BigDecimal> set = new LinkedHashSet<>(value.getNS().size()); set.addAll(value.getNS().stream().map(BigDecimal::new).collect(Collectors.toList())); t = (T) set; } else if (value.getBS() != null) { Set<byte[]> set = new LinkedHashSet<>(value.getBS().size()); set.addAll(value.getBS().stream().map(BinaryUtils::copyAllBytesFrom).collect(Collectors.toList())); t = (T) set; } else if (value.getL() != null) { t = (T) toSimpleList(value.getL()); } else if (value.getM() != null) { t = (T) toSimpleMapValue(value.getM()); } else { throw new IllegalArgumentException("Attribute value must not be empty: " + value); } return t; }
From source file:org.apache.beam.sdk.io.aws.dynamodb.AttributeValueCoder.java
License:Apache License
@Override public void encode(AttributeValue value, OutputStream outStream) throws IOException { if (value.getS() != null) { StringUtf8Coder.of().encode(AttributeValueType.s.toString(), outStream); StringUtf8Coder.of().encode(value.getS(), outStream); } else if (value.getN() != null) { StringUtf8Coder.of().encode(AttributeValueType.n.toString(), outStream); StringUtf8Coder.of().encode(value.getN(), outStream); } else if (value.getBOOL() != null) { StringUtf8Coder.of().encode(AttributeValueType.bOOL.toString(), outStream); BooleanCoder.of().encode(value.getBOOL(), outStream); } else if (value.getB() != null) { StringUtf8Coder.of().encode(AttributeValueType.b.toString(), outStream); ByteArrayCoder.of().encode(convertToByteArray(value.getB()), outStream); } else if (value.getSS() != null) { StringUtf8Coder.of().encode(AttributeValueType.sS.toString(), outStream); LIST_STRING_CODER.encode(value.getSS(), outStream); } else if (value.getNS() != null) { StringUtf8Coder.of().encode(AttributeValueType.nS.toString(), outStream); LIST_STRING_CODER.encode(value.getNS(), outStream); } else if (value.getBS() != null) { StringUtf8Coder.of().encode(AttributeValueType.bS.toString(), outStream); LIST_BYTE_CODER.encode(convertToListByteArray(value.getBS()), outStream); } else if (value.getL() != null) { StringUtf8Coder.of().encode(AttributeValueType.l.toString(), outStream); LIST_ATTRIBUTE_CODER.encode(value.getL(), outStream); } else if (value.getM() != null) { StringUtf8Coder.of().encode(AttributeValueType.m.toString(), outStream); MAP_ATTRIBUTE_CODER.encode(value.getM(), outStream); } else if (value.getNULL() != null) { StringUtf8Coder.of().encode(AttributeValueType.nULLValue.toString(), outStream); BooleanCoder.of().encode(value.getNULL(), outStream); } else {//from w w w . j av a 2s . co m throw new CoderException("Unknown Type"); } }
From source file:org.xmlsh.aws.util.AWSDDBCommand.java
License:BSD License
protected void writeAttributeValue(AttributeValue avalue) throws XMLStreamException, IOException { if (avalue.getS() != null) { attribute(AttrType.S);// ww w. j a v a2 s. c o m characters(avalue.getS()); } else if (avalue.getN() != null) { attribute(AttrType.N); characters(avalue.getN()); } else if (avalue.getB() != null) { attribute(AttrType.B); binary(avalue.getB().array()); } else if (avalue.getSS() != null) { attribute(AttrType.SS); for (String s : avalue.getSS()) { startElement("value"); characters(s); endElement(); } } else if (avalue.getNS() != null) { attribute(AttrType.NS); for (String s : avalue.getNS()) { startElement("value"); characters(s); endElement(); } } else if (avalue.getBS() != null) { attribute(AttrType.BS); for (ByteBuffer s : avalue.getBS()) { startElement("value"); binary(s.array()); endElement(); } } else if (avalue.getL() != null) { attribute(AttrType.L); for (AttributeValue av : avalue.getL()) { startElement("value"); writeAttributeValue(av); endElement(); } } else if (avalue.getM() != null) { attribute(AttrType.M); for (Entry<String, AttributeValue> e : avalue.getM().entrySet()) { writeAttribute(e.getKey(), e.getValue()); } } else if (avalue.isBOOL() != null) { attribute(AttrType.BOOL); characters(avalue.getBOOL().booleanValue() ? "true" : "false"); } else if (avalue.isNULL() != null) { attribute(AttrType.NULL); characters(avalue.getNULL().booleanValue() ? "true" : "false"); } }