Package com.amazonaws.services.dynamodbv2.model

Examples of com.amazonaws.services.dynamodbv2.model.AttributeValue


                if ( reflector.isVersionAttributeGetter(method) ) {
                    Object getterResult = safeInvoke(method, object);
                    String attributeName = reflector.getAttributeName(method);

                    ExpectedAttributeValue expected = new ExpectedAttributeValue();
                    AttributeValue currentValue = getSimpleAttributeValue(method, getterResult);
                    expected.setExists(currentValue != null);
                    if ( currentValue != null )
                        expected.setValue(currentValue);
                    expectedValues.put(attributeName, expected);
                    break;
View Full Code Here


            // Look at every getter and construct a value object for it
            for ( Method method : reflector.getRelevantGetters(clazz) ) {
                Object getterResult = safeInvoke(method, toWrite);
                String attributeName = reflector.getAttributeName(method);

                AttributeValue currentValue = null;
                if ( getterResult == null && reflector.isAssignableKey(method) ) {
                    currentValue = getAutoGeneratedKeyAttributeValue(method, getterResult);
                    inMemoryUpdates.add(new ValueUpdate(method, currentValue, toWrite));
                } else {
                    currentValue = getSimpleAttributeValue(method, getterResult);
View Full Code Here

    private <T> Map<String, AttributeValue> getKey(T keyObject, Class<T> clazz) {
        Map<String, AttributeValue> key = new HashMap<String, AttributeValue>();
        for (Method keyGetter : reflector.getPrimaryKeyGetters(clazz)) {
            Object getterResult = safeInvoke(keyGetter, keyObject);
            AttributeValue keyAttributeValue = getSimpleAttributeValue(keyGetter, getterResult);
            if (keyAttributeValue == null) {
                throw new DynamoDBMappingException("Null key found for " + keyGetter);
            }
            key.put(reflector.getAttributeName(keyGetter), keyAttributeValue);
        }
View Full Code Here

                if ( reflector.isVersionAttributeGetter(method) ) {
                    Object getterResult = safeInvoke(method, object);
                    String attributeName = reflector.getAttributeName(method);

                    ExpectedAttributeValue expected = new ExpectedAttributeValue();
                    AttributeValue currentValue = getSimpleAttributeValue(method, getterResult);
                    expected.setExists(currentValue != null);
                    if ( currentValue != null )
                        expected.setValue(currentValue);
                    expectedValues.put(attributeName, expected);
                    break;
View Full Code Here

            // Look at every getter and construct a value object for it
            for ( Method method : reflector.getRelevantGetters(clazz) ) {
                Object getterResult = safeInvoke(method, toWrite);
                String attributeName = reflector.getAttributeName(method);

                AttributeValue currentValue = null;
                if ( getterResult == null && reflector.isAssignableKey(method) ) {
                    currentValue = getAutoGeneratedKeyAttributeValue(method, getterResult);
                    inMemoryUpdates.add(new ValueUpdate(method, currentValue, toWrite));
                } else {
                    currentValue = getSimpleAttributeValue(method, getterResult);
View Full Code Here

                if ( getterResult == null && reflector.isAssignableKey(method) ) {
                    onAutoGenerateAssignableKey(method, attributeName);
                }

                else {
                    AttributeValue newAttributeValue = getSimpleAttributeValue(method, getterResult);
                    if ( newAttributeValue == null ) {
                        throw new DynamoDBMappingException("Null or empty value for key: " + method);
                    }

                    onKeyAttributeValue(attributeName, newAttributeValue);
                }
            }

            /*
             * Next construct an update for every non-key property
             */
            for ( Method method : reflector.getRelevantGetters(clazz) ) {

                // Skip any key methods, since they are handled separately
                if ( keyGetters.contains(method) )
                    continue;

                Object getterResult = safeInvoke(method, object);
                String attributeName = reflector.getAttributeName(method);

                /*
                 * If this is a versioned field, update it
                 */
                if ( reflector.isVersionAttributeGetter(method) ) {
                    onVersionAttribute(method, getterResult, attributeName);
                    nonKeyAttributePresent = true;
                }

                /*
                 * Otherwise apply the update value for this attribute.
                 */
                else  {
                    AttributeValue currentValue = getSimpleAttributeValue(method, getterResult);
                    if ( currentValue != null ) {
                        onNonKeyAttribute(attributeName, currentValue);
                        nonKeyAttributePresent = true;
                    } else {
                        onNullNonKeyAttribute(attributeName);
View Full Code Here

        protected List<ValueUpdate> getInMemoryUpdates() {
            return inMemoryUpdates;
        }

        private void onAutoGenerateAssignableKey(Method method, String attributeName) {
            AttributeValue newVersionValue = getAutoGeneratedKeyAttributeValue(method, null);

            updateValues.put(attributeName,
                    new AttributeValueUpdate().withAction("PUT").withValue(newVersionValue));
            inMemoryUpdates.add(new ValueUpdate(method, newVersionValue, object));
View Full Code Here

                // update call
                ExpectedAttributeValue expected = new ExpectedAttributeValue();

                // For new objects, insist that the value doesn't exist.
                // For existing ones, insist it has the old value.
                AttributeValue currentValue = getSimpleAttributeValue(method, getterResult);
                expected.setExists(currentValue != null);
                if ( currentValue != null ) {
                    expected.setValue(currentValue);
                }
                expectedValues.put(attributeName, expected);
            }

            AttributeValue newVersionValue = getVersionAttributeValue(method, getterResult);
            updateValues
                    .put(attributeName, new AttributeValueUpdate().withAction("PUT").withValue(newVersionValue));
            inMemoryUpdates.add(new ValueUpdate(method, newVersionValue, object));
        }
View Full Code Here

        String stringValue = marshaller.marshall(getterReturnResult);

        if(stringValue == null) {
            return null;
        } else {
            return new AttributeValue().withS(stringValue);
        }
    }
View Full Code Here

                    public AttributeValue marshall(Object obj) {
                        List<String> timestamps = new LinkedList<String>();
                        for ( Object o : (Set<?>) obj ) {
                            timestamps.add(new DateUtils().formatIso8601Date((Date) o));
                        }
                        return new AttributeValue().withSS(timestamps);
                    }
                };
            } else if ( Calendar.class.isAssignableFrom(returnType) ) {
                marshaller = new ArgumentMarshaller() {

                    @Override
                    public AttributeValue marshall(Object obj) {
                        List<String> timestamps = new LinkedList<String>();
                        for ( Object o : (Set<?>) obj ) {
                            timestamps.add(new DateUtils().formatIso8601Date(((Calendar) o).getTime()));
                        }
                        return new AttributeValue().withSS(timestamps);
                    }
                };
            } else if ( boolean.class.isAssignableFrom(returnType)
                    || Boolean.class.isAssignableFrom(returnType) ) {
                marshaller = new ArgumentMarshaller() {

                    @Override
                    public AttributeValue marshall(Object obj) {
                        List<String> booleanAttributes = new ArrayList<String>();
                        for ( Object b : (Set<?>) obj ) {
                            if ( b == null || !(Boolean) b ) {
                                booleanAttributes.add("0");
                            } else {
                                booleanAttributes.add("1");
                            }
                        }
                        return new AttributeValue().withNS(booleanAttributes);
                    }
                };
            } else if ( returnType.isPrimitive() || Number.class.isAssignableFrom(returnType) ) {
                marshaller = new ArgumentMarshaller() {

                    @Override
                    public AttributeValue marshall(Object obj) {
                        List<String> attributes = new ArrayList<String>();
                        for ( Object o : (Set<?>) obj ) {
                            attributes.add(String.valueOf(o));
                        }
                        return new AttributeValue().withNS(attributes);
                    }
                };
            } else if (ByteBuffer.class.isAssignableFrom(returnType)) {
                 marshaller = new ArgumentMarshaller() {

                     @Override
                     public AttributeValue marshall(Object obj) {
                         List<ByteBuffer> attributes = new ArrayList<ByteBuffer>();
                         for ( Object o : (Set<?>) obj ) {
                             attributes.add((ByteBuffer) o);
                         }
                         return new AttributeValue().withBS(attributes);
                     }
                 };
            } else if (byte[].class.isAssignableFrom(returnType)) {
                 marshaller = new ArgumentMarshaller() {

                     @Override
                     public AttributeValue marshall(Object obj) {
                         List<ByteBuffer> attributes = new ArrayList<ByteBuffer>();
                         for ( Object o : (Set<?>) obj ) {
                             attributes.add(ByteBuffer.wrap((byte[])o));
                         }
                         return new AttributeValue().withBS(attributes);
                     }
                 };
            } else {
                // subclass may extend the behavior by overriding the
                // defaultCollectionArgumentMarshaller method
                marshaller = defaultCollectionArgumentMarshaller(returnType);
            }
        } else if ( Collection.class.isAssignableFrom(returnType) ) {
            throw new DynamoDBMappingException("Non-set collections aren't supported: "
                    + (getter.getDeclaringClass() + "." + getter.getName()));
        } else { // Non-set return type
            if ( Date.class.isAssignableFrom(returnType) ) {
                marshaller = new ArgumentMarshaller() {

                    @Override
                    public AttributeValue marshall(Object obj) {
                        return new AttributeValue().withS(new DateUtils().formatIso8601Date((Date) obj));
                    }
                };
            } else if ( Calendar.class.isAssignableFrom(returnType) ) {
                marshaller = new ArgumentMarshaller() {

                    @Override
                    public AttributeValue marshall(Object obj) {
                        return new AttributeValue().withS(new DateUtils()
                                .formatIso8601Date(((Calendar) obj).getTime()));
                    }
                };
            } else if ( boolean.class.isAssignableFrom(returnType)
                    || Boolean.class.isAssignableFrom(returnType) ) {
                marshaller = new ArgumentMarshaller() {

                    @Override
                    public AttributeValue marshall(Object obj) {
                        if ( obj == null || !(Boolean) obj ) {
                            return new AttributeValue().withN("0");
                        } else {
                            return new AttributeValue().withN("1");
                        }
                    }
                };
            } else if ( returnType.isPrimitive() || Number.class.isAssignableFrom(returnType) ) {
                marshaller = new ArgumentMarshaller() {

                    @Override
                    public AttributeValue marshall(Object obj) {
                        return new AttributeValue().withN(String.valueOf(obj));
                    }
                };
            } else if ( returnType == String.class ) {
                marshaller = new ArgumentMarshaller() {

                    @Override
                    public AttributeValue marshall(Object obj) {
                        if ( ((String) obj).length() == 0 )
                            return null;
                        return new AttributeValue().withS(String.valueOf(obj));
                    }
                };
            } else if ( returnType == ByteBuffer.class ) {
                marshaller = new ArgumentMarshaller() {

                    @Override
                    public AttributeValue marshall(Object obj) {
                        return new AttributeValue().withB((ByteBuffer)obj);
                    }
                };
            } else if ( returnType == byte[].class) {
                 marshaller = new ArgumentMarshaller() {

                     @Override
                     public AttributeValue marshall(Object obj) {
                         return new AttributeValue().withB(ByteBuffer.wrap((byte[])obj));
                     }
                 };
            } else {
                marshaller = defaultArgumentMarshaller(returnType, getter);
            }
View Full Code Here

TOP

Related Classes of com.amazonaws.services.dynamodbv2.model.AttributeValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.