Package com.amazonaws.services.dynamodbv2.document

Examples of com.amazonaws.services.dynamodbv2.document.GetItemOutcome


    @Test
    public void howToGetItemOutcomes() {
        Table table = dynamo.getTable(TABLE_NAME);
        for (int i=1; i <= 10; i++) {
            GetItemOutcome outcome = table.getItemOutcome(
                HASH_KEY_NAME, "foo", RANGE_KEY_NAME, i);
            Item item = outcome.getItem();
            System.out.println("========== item " + i + " ==========");
            System.out.println(item);
            byte[] binary = item.getBinary("binary");
            System.out.println("binary: " + Arrays.toString(binary));
            Set<byte[]> binarySet = item.getBinarySet("binarySet");
            for (byte[] ba: binarySet) {
                System.out.println("binary set element: " + Arrays.toString(ba));
            }
            boolean bTrue = item.getBoolean("booleanTrue");
            System.out.println("booleanTrue: " + bTrue);
            int intval = item.getInt("intAttr");
            System.out.println("intAttr: " + intval);
            List<Object> listval = item.getList("listAtr");
            System.out.println("listAtr: " + listval);
            Map<String,Object> mapval = item.getMap("mapAttr");
            System.out.println("mapAttr: " + mapval);
            Object nullval = item.get("nullAttr");
            System.out.println("nullAttr: " + nullval);
            BigDecimal numval = item.getNumber("numberAttr");
            System.out.println("numberAttr: " + numval);
            String strval = item.getString("stringAttr");
            System.out.println("stringAttr: " + strval);
            Set<String> strset = item.getStringSet("stringSetAttr");
            System.out.println("stringSetAttr: " + strset);
            // "Outcome" allows access to the low level result
            System.out.println("low level result: " + outcome.getGetItemResult());
        }
    }
View Full Code Here


    @Test
    public void howToUseProjectionExpression() {
        Table table = dynamo.getTable(TABLE_NAME);
        for (int i=1; i <= 10; i++) {
            GetItemOutcome outcome = table.getItemOutcome(
                HASH_KEY_NAME, "foo", RANGE_KEY_NAME, i,
                // Here is the projection expression to select 3 attributes
                // to be returned.
                // This expression requires attribute name substitution for
                // "binary" which is a reserved word in DynamoDB
                "#binary, intAttr, stringAttr",
                new NameMap().with("#binary", "binary"));
            Item item = outcome.getItem();
            System.out.println("========== item " + i + " ==========");
            System.out.println(item);
            byte[] binary = item.getBinary("binary");
            System.out.println("binary: " + Arrays.toString(binary));
            int intval = item.getInt("intAttr");
            System.out.println("intAttr: " + intval);
            Set<String> strset = item.getStringSet("stringSetAttr");
            System.out.println("stringSetAttr: " + strset);
            // "Outcome" allows access to the low level result
            System.out.println("low level result: " + outcome.getGetItemResult());
        }
    }
View Full Code Here

    @Test
    public void howToUseGetItemSpec() {
        Table table = dynamo.getTable(TABLE_NAME);
        for (int i=1; i <= 10; i++) {
            GetItemOutcome outcome = table.getItemOutcome(new GetItemSpec()
                .withPrimaryKey(HASH_KEY_NAME, "foo", RANGE_KEY_NAME, i)
                .withProjectionExpression("#binary, intAttr, stringAttr")
                .withNameMap(new NameMap().with("#binary", "binary")));
            Item item = outcome.getItem();
            System.out.println("========== item " + i + " ==========");
            System.out.println(item);
            byte[] binary = item.getBinary("binary");
            System.out.println("binary: " + Arrays.toString(binary));
            int intval = item.getInt("intAttr");
            System.out.println("intAttr: " + intval);
            Set<String> strset = item.getStringSet("stringSetAttr");
            System.out.println("stringSetAttr: " + strset);
            // "Outcome" allows access to the low level result
            System.out.println("low level result: " + outcome.getGetItemResult());
        }
    }
View Full Code Here

    }

    @Test
    public void getNonExistentItem() {
        Table table = dynamo.getTable(TABLE_NAME);
        GetItemOutcome outcome = table.getItemOutcome(
            HASH_KEY_NAME, "bar", RANGE_KEY_NAME, 99);
        Item item = outcome.getItem();
        Assert.assertNull(item);
        // "Outcome" allows access to the low level result
        System.out.println("low level result: " + outcome.getGetItemResult());
    }
View Full Code Here

        Table table = dynamo.getTable(TABLE_NAME);
        // Add a set of phone numbers to the attribute "phone"
        final String phoneNumber1 = "123-456-7890";
        table.updateItem(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK,
            new AttributeUpdate("phone").put(new FluentHashSet<String>(phoneNumber1)));
        GetItemOutcome outcome = table.getItemOutcome(new GetItemSpec()
            .withPrimaryKey(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK)
            .withConsistentRead(true)
        );
        Item item = outcome.getItem();
        Set<String> phoneNumbers = item.getStringSet("phone");
        assertTrue(1 == phoneNumbers.size());
        System.out.println(phoneNumbers);

        // Add a 2nd phone number to the set
        final String phoneNumber2 = "987-654-3210";
        table.updateItem(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK,
            new AttributeUpdate("phone").addElements(phoneNumber2));
        outcome = table.getItemOutcome(new GetItemSpec()
            .withPrimaryKey(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK)
            .withConsistentRead(true));
        item = outcome.getItem();
        phoneNumbers = item.getStringSet("phone");
        System.out.println(phoneNumbers);
        assertTrue(2== phoneNumbers.size());

        // removes the 2nd phone number from the set
        table.updateItem(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK,
            new AttributeUpdate("phone").removeElements(phoneNumber2));
        outcome = table.getItemOutcome(new GetItemSpec()
            .withPrimaryKey(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK)
            .withConsistentRead(true));
        item = outcome.getItem();
        phoneNumbers = item.getStringSet("phone");
        System.out.println(phoneNumbers);
        assertTrue(1 == phoneNumbers.size());

        // deletes the phone attribute
        table.updateItem(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK,
                new AttributeUpdate("phone").delete());
        outcome = table.getItemOutcome(new GetItemSpec()
            .withPrimaryKey(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK)
            .withConsistentRead(true));
        item = outcome.getItem();
        phoneNumbers = item.getStringSet("phone");
        assertNull(phoneNumbers);
    }
View Full Code Here

    }

    @Test
    public void howToAddNumerically() {
        Table table = dynamo.getTable(TABLE_NAME);
        GetItemOutcome outcome = table.getItemOutcome(new GetItemSpec()
            .withPrimaryKey(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK)
            .withConsistentRead(true)
        );
        Item item = outcome.getItem();
        final int oldZipCode = item.getInt("zipcode");

        // Increments the zip code attribute
        table.updateItem(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK,
                new AttributeUpdate("zipcode").addNumeric(1));
        outcome = table.getItemOutcome(new GetItemSpec()
            .withPrimaryKey(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK)
            .withConsistentRead(true));
        item = outcome.getItem();
        int newZipCode = item.getInt("zipcode");
        assertEquals(oldZipCode + 1, newZipCode);

        // Decrements the zip code attribute
        table.updateItem(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK,
                new AttributeUpdate("zipcode").addNumeric(-1));
        outcome = table.getItemOutcome(new GetItemSpec()
            .withPrimaryKey(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK)
            .withConsistentRead(true));
        item = outcome.getItem();
        newZipCode = item.getInt("zipcode");
        assertEquals(oldZipCode, newZipCode);
    }
View Full Code Here

            "set #phoneAttributeName = :phoneAtributeValue",
            new NameMap().with("#phoneAttributeName", "phone"),
            new ValueMap().withStringSet(":phoneAtributeValue",
                "123-456-7890", "987-654-3210")
            );
        GetItemOutcome outcome = table.getItemOutcome(new GetItemSpec()
            .withPrimaryKey(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK)
            .withConsistentRead(true));
        Item item = outcome.getItem();
        Set<String> phoneNumbers = item.getStringSet("phone");
        assertTrue(phoneNumbers.size() == 2);
        System.out.println(phoneNumbers);
    }
View Full Code Here

    }

    @Test
    public void howToUseConditionExpression() {
        Table table = dynamo.getTable(TABLE_NAME);
        GetItemOutcome outcome = table.getItemOutcome(new GetItemSpec()
            .withPrimaryKey(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK)
            .withConsistentRead(true));
        Item item = outcome.getItem();
        System.out.println(item);
        table.updateItem(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK,
            // update expression (list_append: concatenate two lists.)
            "set phone = list_append(:a, :b)",
            // condition expression
            "zipcode = :zipcode",
            null,
            new ValueMap()
                 .withInt(":zipcode", 98104)
                 .withList(":a", "phone-1", "phone-2")
                 .withList(":b", "phone-3", "phone-4")
         );
        outcome = table.getItemOutcome(new GetItemSpec()
            .withPrimaryKey(HASH_KEY, FIRST_CUSTOMER_ID, RANGE_KEY, ADDRESS_TYPE_WORK)
            .withConsistentRead(true));
        item = outcome.getItem();
        System.out.println(item);
    }
View Full Code Here

                .withConsistentRead(spec.isConsistentRead())
                .withProjectionExpression(spec.getProjectionExpression())
                .withExpressionAttributeNames(spec.getNameMap());

        GetItemResult result = getClient().getItem(req);
        return new GetItemOutcome(result);
    }
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

TOP

Related Classes of com.amazonaws.services.dynamodbv2.document.GetItemOutcome

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.