Package com.amazonaws.services.dynamodb.model

Examples of com.amazonaws.services.dynamodb.model.ExpectedAttributeValue


                    inMemoryUpdates.add(new ValueUpdate(method, newVersionValue, object));

                    if ( config.getSaveBehavior() != SaveBehavior.CLOBBER ) {
                        // Add an expect clause to make sure that the item
                        // doesn't already exist, since it's supposed to be new
                        ExpectedAttributeValue expected = new ExpectedAttributeValue();
                        expected.setExists(false);
                        expectedValues.put(attributeName, expected);
                    }
                } else {
                    AttributeValue currentValue = getSimpleAttributeValue(method, getterResult);
                    if ( currentValue != null ) {
                        updateValues.put(attributeName,
                                new AttributeValueUpdate().withValue(currentValue).withAction("PUT"));
                    } else {
                        throw new DynamoDBMappingException("Null value for non-generated key for method " + method);
                    }
                }
            }
        } else {
            /*
             * If we don't have the required keys by this point, it's an error
             */
            if ( hashKeyElement == null ) {
                throw new DynamoDBMappingException("No value provided for hash key for object " + object);
            }
            if ( rangeKeyGetter != null && rangeKeyElement == null ) {
                throw new DynamoDBMappingException("No value provided for range key for object " + object);
            }
        }

        // Look at every getter and construct an update object for it
        for ( Method method : reflector.getRelevantGetters(clazz) ) {

            // Skip any key methods, since they are handled separately
            if ( method.equals(hashKeyGetter) || method.equals(rangeKeyGetter) )
                continue;

            nonKeyAttributePresent = true;

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

            /*
             * If this is a versioned field, update it
             */
            if ( reflector.isVersionAttributeGetter(method) ) {
                if ( config.getSaveBehavior() != SaveBehavior.CLOBBER ) {
                    // First establish the expected (current) value for the
                    // 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);
View Full Code Here


        Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>();
        Map<String, ExpectedAttributeValue> expectedValues = new HashMap<String, ExpectedAttributeValue>();

        String hashKeyAttributeName = reflector.getAttributeName(hashKeyGetter);
        attributes.put(hashKeyAttributeName, objectKey.getHashKeyElement());
        expectedValues.put(hashKeyAttributeName, new ExpectedAttributeValue().withExists(false));

        if (rangeKeyGetter != null) {
            String rangeKeyAttributeName = reflector.getAttributeName(rangeKeyGetter);
            attributes.put(rangeKeyAttributeName, objectKey.getRangeKeyElement());
            expectedValues.put(rangeKeyAttributeName, new ExpectedAttributeValue().withExists(false));
        }

        db.putItem(applyUserAgent(new PutItemRequest().withTableName(tableName).withItem(attributes)
                .withExpected(expectedValues)));
    }
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

        AttributeValue attributeValue = new AttributeValue("test value");
        attributeMap.put("name", attributeValue);
        exchange.getIn().setHeader(DdbConstants.ITEM, attributeMap);

        Map<String, ExpectedAttributeValue> expectedAttributeValueMap = new HashMap<String, ExpectedAttributeValue>();
        expectedAttributeValueMap.put("name", new ExpectedAttributeValue(attributeValue));
        exchange.getIn().setHeader(DdbConstants.UPDATE_CONDITION, expectedAttributeValueMap);

        command.execute();

        assertEquals("DOMAIN1", ddbClient.putItemRequest.getTableName());
View Full Code Here

        exchange.getIn().setHeader(DdbConstants.KEY, key);


        Map<String, ExpectedAttributeValue> updateCondition = new HashMap<String, ExpectedAttributeValue>();
        updateCondition
                .put("name", new ExpectedAttributeValue(new AttributeValue("expected value")));
        exchange.getIn().setHeader(DdbConstants.UPDATE_CONDITION, updateCondition);
        exchange.getIn().setHeader(DdbConstants.RETURN_VALUES, "ALL_OLD");

        command.execute();
View Full Code Here

        attributeMap.put("name", attributeValue);
        exchange.getIn().setHeader(DdbConstants.UPDATE_VALUES, attributeMap);

        Map<String, ExpectedAttributeValue> expectedAttributeValueMap = new HashMap<String, ExpectedAttributeValue>();
        expectedAttributeValueMap
                .put("name", new ExpectedAttributeValue(new AttributeValue("expected value")));
        exchange.getIn().setHeader(DdbConstants.UPDATE_CONDITION, expectedAttributeValueMap);
        exchange.getIn().setHeader(DdbConstants.RETURN_VALUES, "ALL_OLD");

        command.execute();
View Full Code Here

                    inMemoryUpdates.add(new ValueUpdate(method, newVersionValue, object));

                    if ( config.getSaveBehavior() != SaveBehavior.CLOBBER ) {
                        // Add an expect clause to make sure that the item
                        // doesn't already exist, since it's supposed to be new
                        ExpectedAttributeValue expected = new ExpectedAttributeValue();
                        expected.setExists(false);
                        expectedValues.put(attributeName, expected);
                    }
                } else {
                    AttributeValue currentValue = getSimpleAttributeValue(method, getterResult);
                    if ( currentValue != null ) {
                        updateValues.put(attributeName,
                                new AttributeValueUpdate().withValue(currentValue).withAction("PUT"));
                    } else {
                        throw new DynamoDBMappingException("Null value for non-generated key for method " + method);
                    }
                }
            }
        } else {
            /*
             * If we don't have the required keys by this point, it's an error
             */
            if ( hashKeyElement == null ) {
                throw new DynamoDBMappingException("No value provided for hash key for object " + object);
            }
            if ( rangeKeyGetter != null && rangeKeyElement == null ) {
                throw new DynamoDBMappingException("No value provided for range key for object " + object);
            }
        }

        // Look at every getter and construct an update object for it
        for ( Method method : reflector.getRelevantGetters(clazz) ) {

            // Skip any key methods, since they are handled separately
            if ( method.equals(hashKeyGetter) || method.equals(rangeKeyGetter) )
                continue;
           
            nonKeyAttributePresent = true;

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

            /*
             * If this is a versioned field, update it
             */
            if ( reflector.isVersionAttributeGetter(method) ) {
                if ( config.getSaveBehavior() != SaveBehavior.CLOBBER ) {
                    // First establish the expected (current) value for the
                    // 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);
View Full Code Here

        Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>();
        Map<String, ExpectedAttributeValue> expectedValues = new HashMap<String, ExpectedAttributeValue>();

        String hashKeyAttributeName = reflector.getAttributeName(hashKeyGetter);
        attributes.put(hashKeyAttributeName, objectKey.getHashKeyElement());
        expectedValues.put(hashKeyAttributeName, new ExpectedAttributeValue().withExists(false));
       
        if (rangeKeyGetter != null) {
            String rangeKeyAttributeName = reflector.getAttributeName(rangeKeyGetter);
            attributes.put(rangeKeyAttributeName, objectKey.getRangeKeyElement());
            expectedValues.put(rangeKeyAttributeName, new ExpectedAttributeValue().withExists(false));
        }
       
        db.putItem(applyUserAgent(new PutItemRequest().withTableName(tableName).withItem(attributes)
                .withExpected(expectedValues)));
    }
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

                    inMemoryUpdates.add(new ValueUpdate(method, newVersionValue));

                    if ( config.getSaveBehavior() != SaveBehavior.CLOBBER ) {
                        // Add an expect clause to make sure that the item
                        // doesn't already exist, since it's supposed to be new
                        ExpectedAttributeValue expected = new ExpectedAttributeValue();
                        expected.setExists(false);
                        expectedValues.put(attributeName, expected);
                    }
                } else {
                    AttributeValue currentValue = getSimpleAttributeValue(method, getterResult);
                    if ( currentValue != null ) {
                        updateValues.put(attributeName,
                                new AttributeValueUpdate().withValue(currentValue).withAction("PUT"));
                    } else {
                        throw new DynamoDBMappingException("Null value for non-generated key for method " + method);
                    }
                }
            }
        } else {
            /*
             * If we don't have the required keys by this point, it's an error
             */
            if ( hashKeyElement == null ) {
                throw new DynamoDBMappingException("No value provided for hash key for object " + object);
            }
            if ( rangeKeyGetter != null && rangeKeyElement == null ) {
                throw new DynamoDBMappingException("No value provided for range key for object " + object);
            }
        }

        // Look at every getter and construct an update object for it
        for ( Method method : reflector.getRelevantGetters(clazz) ) {

            // Skip any key methods, since they are handled separately
            if ( method.equals(hashKeyGetter) || method.equals(rangeKeyGetter) )
                continue;
           
            nonKeyAttributePresent = true;

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

            /*
             * If this is a versioned field, update it
             */
            if ( reflector.isVersionAttributeGetter(method) ) {
                if ( config.getSaveBehavior() != SaveBehavior.CLOBBER ) {
                    // First establish the expected (current) value for the
                    // 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);
View Full Code Here

TOP

Related Classes of com.amazonaws.services.dynamodb.model.ExpectedAttributeValue

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.