Example usage for com.amazonaws.services.dynamodbv2.model AttributeValue getBS

List of usage examples for com.amazonaws.services.dynamodbv2.model AttributeValue getBS

Introduction

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

Prototype


public java.util.List<java.nio.ByteBuffer> getBS() 

Source Link

Document

An attribute of type Binary Set.

Usage

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/*from w  w w .j a  va2s.c om*/
 */
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  a  2 s  .  co  m*/

    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.github.sdmcraft.slingdynamo.demo.App.java

License:Open Source License

/**
 * Prints the item.//from w  w w.ja  v  a  2  s  .  c  o m
 *
 * @param attributeList the attribute list
 */
private static void printItem(Map<String, AttributeValue> attributeList) {
    for (Map.Entry<String, AttributeValue> item : attributeList.entrySet()) {
        String attributeName = item.getKey();
        AttributeValue value = item.getValue();
        System.out.println(attributeName + " " + ((value.getS() == null) ? "" : ("S=[" + value.getS() + "]"))
                + ((value.getN() == null) ? "" : ("N=[" + value.getN() + "]"))
                + ((value.getB() == null) ? "" : ("B=[" + value.getB() + "]"))
                + ((value.getSS() == null) ? "" : ("SS=[" + value.getSS() + "]"))
                + ((value.getNS() == null) ? "" : ("NS=[" + value.getNS() + "]"))
                + ((value.getBS() == null) ? "" : ("BS=[" + value.getBS() + "] \n")));
    }
}

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 .  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: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  w w  .ja  v a 2 s  .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());
        }/*w w  w . j  av  a  2 s .  c o m*/
        connectAttributes.put(attributeName, attributeValueStruct);
    }
    return connectAttributes;
}

From source file:io.apptik.json.aws.DynamoDb2Item.java

License:Apache License

@Override
protected JsonElement to(AttributeValue value) {
    //the output JASON care only for one type of attribute.
    JsonElement el = new JsonString("");
    try {//from  w ww.ja  v  a 2 s  .  com
        if (value.getS() != null) {
            el = JsonElement.wrap(value.getS());
        } else if (value.getN() != null) {
            el = JsonElement.wrap(value.getN());
        } else if (value.getSS() != null) {
            el = JsonElement.wrap(value.getSS());
        } else if (value.getNS() != null) {
            el = JsonElement.wrap(value.getNS());
        } else if (value.getB() != null) {
            el = JsonElement.wrap(value.getB());
        } else if (value.getN() != null) {
            el = JsonElement.wrap(value.getBS());
        }

    } catch (JsonException e) {
        e.printStackTrace();
    }
    return el;
}

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 ww  w. ja  v a 2  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: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  www .j  av  a 2 s.  co m*/
 *
 * <ul>
 * <li>String</li>
 * <li>Set&lt;String></li>
 * <li>Number (including any subtypes and primitive types)</li>
 * <li>Set&lt;Number></li>
 * <li>byte[]</li>
 * <li>Set&lt;byte[]></li>
 * <li>ByteBuffer</li>
 * <li>Set&lt;ByteBuffer></li>
 * <li>Boolean or boolean</li>
 * <li>null</li>
 * <li>Map&lt;String,T>, where T can be any type on this list but must not
 * induce any circular reference</li>
 * <li>List&lt;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  ava  2 s . c o  m
        throw new CoderException("Unknown Type");
    }
}