Package com.amazonaws.services.dynamodbv2.document

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


        new B_PutItemTest().howToPutItems();
    }

    @Test
    public void simpleQuery() {
        Table table = dynamo.getTable(TABLE_NAME);
        ItemCollection<?> col = table.query(HASH_KEY_NAME, "foo",
            new RangeKeyCondition(RANGE_KEY_NAME).between(1, 10));
        int count = 0;
        for (Item item: col) {
            System.out.println(item);
            count++;
View Full Code Here


        Assert.assertTrue(count == 10);
    }

    @Test
    public void howToUseQueryFilters() {
        Table table = dynamo.getTable(TABLE_NAME);
        ItemCollection<QueryOutcome> col = table.query(HASH_KEY_NAME, "foo",
            new RangeKeyCondition(RANGE_KEY_NAME).between(1, 10),
            new QueryFilter("intAttr").gt(1238));
        int count = 0;
        QueryOutcome lastOutcome = null;
        for (Item item: col) {
View Full Code Here

        Assert.assertTrue(count < 10);
    }

    @Test
    public void howToUseFilterExpression() {
        Table table = dynamo.getTable(TABLE_NAME);
        ItemCollection<QueryOutcome> col = table.query(
            HASH_KEY_NAME, "foo",
            new RangeKeyCondition(RANGE_KEY_NAME).between(1, 10),
            // filter expression
            "intAttr > :intAttr",
            // no attribute name substitution
View Full Code Here

        Assert.assertTrue(count < 10);
    }

    @Test
    public void howToUseFilterExpression_AttrNameSubstitution() {
        Table table = dynamo.getTable(TABLE_NAME);
        ItemCollection<?> col = table.query(
            HASH_KEY_NAME, "foo",
            new RangeKeyCondition(RANGE_KEY_NAME).between(1, 10),
            // filter expression with name substitution
            "#intAttr > :intAttr",
            // attribute name substitution
View Full Code Here

        Assert.assertTrue(count < 10);
    }

    @Test
    public void howToUseProjectionExpression() {
        Table table = dynamo.getTable(TABLE_NAME);
        ItemCollection<?> col = table.query(
            HASH_KEY_NAME, "foo",
            new RangeKeyCondition(RANGE_KEY_NAME).between(1, 10),
            // filter expression
            "#intAttr > :intAttr",
            // projection expression
View Full Code Here

import com.amazonaws.services.dynamodbv2.document.utils.ValueMap;

public class B_PutItemJsonTest extends AbstractQuickStart {
    @Test
    public void howToPutItems() {
        Table table = dynamo.getTable(TABLE_NAME);
        Item item = new Item()
            .withPrimaryKey(HASH_KEY_NAME, "B_PutItemJsonTest", RANGE_KEY_NAME, 1)
            // Store document as a map
            .withMap("document", new ValueMap()
                .withString("last_name", "Bar")
                .withString("first_name", "Jeff")
                .withString("current_city", "Tokyo")
                .withMap("next_haircut",
                    new ValueMap()
                        .withInt("year", 2014)
                        .withInt("month", 10)
                        .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}}} }
        // I can update part of a document. Here's how I would change my current_city back to Seattle:
        table.updateItem(new UpdateItemSpec()
            .withPrimaryKey(HASH_KEY_NAME, "B_PutItemJsonTest", RANGE_KEY_NAME, 1)
            .withUpdateExpression("SET document.current_city = :city")
            .withValueMap(new ValueMap().withString(":city", "Seattle"))
        );
        // Retrieve the entire item
        Item itemUpdated = table.getItem(HASH_KEY_NAME, "B_PutItemJsonTest", RANGE_KEY_NAME, 1);
        System.out.println(itemUpdated);
        // Output: { Item: {document={last_name=Bar, children=[SJB, ASB, CGB, BGB, GTB], first_name=Jeff, current_city=Seattle, next_haircut={month=10, year=2014, day=30}}, myRangeKey=1, myHashKey=B_PutItemJsonTest} }
    }
View Full Code Here

        new B_PutItemTest().howToPutItems();
    }

    @Test
    public void howToGetItems() {
        Table table = dynamo.getTable(TABLE_NAME);
        for (int i=1; i <= 10; i++) {
            Item item = table.getItem(
                HASH_KEY_NAME, "foo", RANGE_KEY_NAME, i);
            System.out.println("========== item " + i + " ==========");
            System.out.println(item);
            byte[] binary = item.getBinary("binary");
            System.out.println("binary: " + Arrays.toString(binary));
View Full Code Here

        }
    }

    @Test
    public void howToUseProjectionExpression() {
        Table table = dynamo.getTable(TABLE_NAME);
        for (int i=1; i <= 10; i++) {
            Item item = table.getItem(
                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
View Full Code Here

        }
    }

    @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

        }
    }

    @Test
    public void getNonExistentItem() {
        Table table = dynamo.getTable(TABLE_NAME);
        Item item  = table.getItem(
            HASH_KEY_NAME, "bar", RANGE_KEY_NAME, 99);
        Assert.assertNull(item);
    }
View Full Code Here

TOP

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

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.