Examples of GetItemSpec


Examples of com.amazonaws.services.dynamodbv2.document.spec.GetItemSpec

                        .withInt("day", 30))
                .withList("children", "SJB", "ASB", "CGB", "BGB", "GTB")
            );
        table.putItem(item);
        // Retrieve the entire document and the entire document only
        Item documentItem = table.getItem(new GetItemSpec()
            .withPrimaryKey(HASH_KEY_NAME, "B_PutItemJsonTest", RANGE_KEY_NAME, 1)
            .withAttributesToGet("document"));
        System.out.println(documentItem.get("document"));
        // Output: {last_name=Bar, children=[SJB, ASB, CGB, BGB, GTB], first_name=Jeff, current_city=Tokyo, next_haircut={month=10, year=2014, day=30}}
        // Retrieve part of a document. Perhaps I need the next_haircut and nothing else
        Item partialDocItem = table.getItem(new GetItemSpec()
            .withPrimaryKey(HASH_KEY_NAME, "B_PutItemJsonTest", RANGE_KEY_NAME, 1)
            .withProjectionExpression("document.next_haircut"))
            ;
        System.out.println(partialDocItem);
        // Output: { Item: {document={next_haircut={month=10, year=2014, day=30}}} }
View Full Code Here

Examples of com.amazonaws.services.dynamodbv2.document.spec.GetItemSpec

            .withPrimaryKey(HASH_KEY_NAME, "howToPutItems_withJSONDoc", RANGE_KEY_NAME, 1)
            // Store JSON document
            .withJSON("document", json);
        table.putItem(item);
        // Retrieve the entire document and the entire document only
        Item documentItem = table.getItem(new GetItemSpec()
            .withPrimaryKey(HASH_KEY_NAME, "howToPutItems_withJSONDoc", RANGE_KEY_NAME, 1)
            .withAttributesToGet("document"));
        System.out.println(documentItem.getJSON("document"));
        // Output: {"last_name":"Barr","children":["SJB","ASB","CGB","BGB","GTB"],"first_name":"Jeff","person_id":123,"current_city":"Tokyo","next_haircut":{"month":10,"year":2014,"day":30}}
        System.out.println(documentItem.getJSONPretty("document"));
        // Output:
//        {
//            "last_name" : "Barr",
//            "children" : [ "SJB", "ASB", "CGB", "BGB", "GTB" ],
//            "first_name" : "Jeff",
//            "person_id" : 123,
//            "current_city" : "Tokyo",
//            "next_haircut" : {
//              "month" : 10,
//              "year" : 2014,
//              "day" : 30
//            }
//        }        // Retrieve part of a document. Perhaps I need the next_haircut and nothing else
        Item partialDocItem = table.getItem(new GetItemSpec()
            .withPrimaryKey(HASH_KEY_NAME, "howToPutItems_withJSONDoc", RANGE_KEY_NAME, 1)
            .withProjectionExpression("document.next_haircut"))
            ;
        System.out.println(partialDocItem);
        // Output: { Item: {document={next_haircut={month=10, year=2014, day=30}}} }
View Full Code Here

Examples of com.amazonaws.services.dynamodbv2.document.spec.GetItemSpec

        Item item = Item.fromJSON(json)
             // We don't even need to set the primary key if it's already included in the JSON document
            .withPrimaryKey(HASH_KEY_NAME, "howToPut_TopLevelJSON", RANGE_KEY_NAME, 1);
        table.putItem(item);
        // Retrieve the entire document and the entire document only
        Item documentItem = table.getItem(new GetItemSpec()
            .withPrimaryKey(HASH_KEY_NAME, "howToPut_TopLevelJSON", RANGE_KEY_NAME, 1));
        System.out.println(documentItem.toJSON());
        // Output: {"first_name":"Jeff","myRangeKey":1,"person_id":123,"current_city":"Tokyo","next_haircut":{"month":10,"year":2014,"day":30},"last_name":"Barr","children":["SJB","ASB","CGB","BGB","GTB"],"myHashKey":"howToPut_TopLevelJSON"}
        System.out.println(documentItem.toJSONPretty());
        // Output:
//        {
//            "first_name" : "Jeff",
//            "myRangeKey" : 1,
//            "person_id" : 123,
//            "current_city" : "Tokyo",
//            "next_haircut" : {
//              "month" : 10,
//              "year" : 2014,
//              "day" : 30
//            },
//            "last_name" : "Barr",
//            "children" : [ "SJB", "ASB", "CGB", "BGB", "GTB" ],
//            "myHashKey" : "howToPut_TopLevelJSON"
//          }
        // Retrieve part of a document. Perhaps I need the next_haircut and nothing else
        Item partialDocItem = table.getItem(new GetItemSpec()
            .withPrimaryKey(HASH_KEY_NAME, "howToPut_TopLevelJSON", RANGE_KEY_NAME, 1)
            .withProjectionExpression("next_haircut"))
            ;
        System.out.println(partialDocItem);
        // Output: { Item: {next_haircut={month=10, year=2014, day=30}} }
View Full Code Here

Examples of com.amazonaws.services.dynamodbv2.document.spec.GetItemSpec

    @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 + " ==========");
View Full Code Here

Examples of com.amazonaws.services.dynamodbv2.document.spec.GetItemSpec

        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

Examples of com.amazonaws.services.dynamodbv2.document.spec.GetItemSpec

    }

    @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

Examples of com.amazonaws.services.dynamodbv2.document.spec.GetItemSpec

            "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);
View Full Code Here

Examples of com.amazonaws.services.dynamodbv2.document.spec.GetItemSpec

    }

    @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

Examples of com.amazonaws.services.dynamodbv2.document.spec.GetItemSpec

    @Test
    public void howToUseGetItemSpec() {
        Table table = dynamo.getTable(TABLE_NAME);
        for (int i=1; i <= 10; i++) {
            Item item = table.getItem(new GetItemSpec()
                .withPrimaryKey(HASH_KEY_NAME, "foo", RANGE_KEY_NAME, i)
                .withProjectionExpression("#binary, intAttr, stringAttr")
                .withNameMap(new NameMap().with("#binary", "binary")));
            System.out.println("========== item " + i + " ==========");
            System.out.println(item);
View Full Code Here

Examples of com.amazonaws.services.dynamodbv2.document.spec.GetItemSpec

        super(client, table);
    }

    @Override
    public GetItemOutcome getItemOutcome(KeyAttribute... primaryKeyComponents) {
        return doLoadItem(new GetItemSpec()
                   .withPrimaryKey(primaryKeyComponents));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.