Search in sources :

Example 16 with ValueMap

use of com.amazonaws.services.dynamodbv2.document.utils.ValueMap in project aws-doc-sdk-examples by awsdocs.

the class DocumentAPIQuery method findRepliesUsingAFilterExpression.

private static void findRepliesUsingAFilterExpression(String forumName, String threadSubject) {
    Table table = dynamoDB.getTable(tableName);
    String replyId = forumName + "#" + threadSubject;
    QuerySpec spec = new QuerySpec().withProjectionExpression("Message, ReplyDateTime, PostedBy").withKeyConditionExpression("Id = :v_id").withFilterExpression("PostedBy = :v_postedby").withValueMap(new ValueMap().withString(":v_id", replyId).withString(":v_postedby", "User B"));
    ItemCollection<QueryOutcome> items = table.query(spec);
    System.out.println("\nfindRepliesUsingAFilterExpression results:");
    Iterator<Item> iterator = items.iterator();
    while (iterator.hasNext()) {
        System.out.println(iterator.next().toJSONPretty());
    }
}
Also used : Item(com.amazonaws.services.dynamodbv2.document.Item) Table(com.amazonaws.services.dynamodbv2.document.Table) ValueMap(com.amazonaws.services.dynamodbv2.document.utils.ValueMap) QueryOutcome(com.amazonaws.services.dynamodbv2.document.QueryOutcome) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)

Example 17 with ValueMap

use of com.amazonaws.services.dynamodbv2.document.utils.ValueMap in project aws-doc-sdk-examples by awsdocs.

the class MoviesItemOps05 method main.

public static void main(String[] args) throws Exception {
    AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:8000", "us-west-2")).build();
    DynamoDB dynamoDB = new DynamoDB(client);
    Table table = dynamoDB.getTable("Movies");
    int year = 2015;
    String title = "The Big New Movie";
    UpdateItemSpec updateItemSpec = new UpdateItemSpec().withPrimaryKey(new PrimaryKey("year", year, "title", title)).withUpdateExpression("remove info.actors[0]").withConditionExpression("size(info.actors) > :num").withValueMap(new ValueMap().withNumber(":num", 3)).withReturnValues(ReturnValue.UPDATED_NEW);
    // Conditional update (we expect this to fail)
    try {
        System.out.println("Attempting a conditional update...");
        UpdateItemOutcome outcome = table.updateItem(updateItemSpec);
        System.out.println("UpdateItem succeeded:\n" + outcome.getItem().toJSONPretty());
    } catch (Exception e) {
        System.err.println("Unable to update item: " + year + " " + title);
        System.err.println(e.getMessage());
    }
}
Also used : Table(com.amazonaws.services.dynamodbv2.document.Table) UpdateItemSpec(com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec) ValueMap(com.amazonaws.services.dynamodbv2.document.utils.ValueMap) UpdateItemOutcome(com.amazonaws.services.dynamodbv2.document.UpdateItemOutcome) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) PrimaryKey(com.amazonaws.services.dynamodbv2.document.PrimaryKey) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB)

Example 18 with ValueMap

use of com.amazonaws.services.dynamodbv2.document.utils.ValueMap in project aws-doc-sdk-examples by awsdocs.

the class MoviesScan method main.

public static void main(String[] args) throws Exception {
    AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:8000", "us-west-2")).build();
    DynamoDB dynamoDB = new DynamoDB(client);
    Table table = dynamoDB.getTable("Movies");
    ScanSpec scanSpec = new ScanSpec().withProjectionExpression("#yr, title, info.rating").withFilterExpression("#yr between :start_yr and :end_yr").withNameMap(new NameMap().with("#yr", "year")).withValueMap(new ValueMap().withNumber(":start_yr", 1950).withNumber(":end_yr", 1959));
    try {
        ItemCollection<ScanOutcome> items = table.scan(scanSpec);
        Iterator<Item> iter = items.iterator();
        while (iter.hasNext()) {
            Item item = iter.next();
            System.out.println(item.toString());
        }
    } catch (Exception e) {
        System.err.println("Unable to scan the table:");
        System.err.println(e.getMessage());
    }
}
Also used : Item(com.amazonaws.services.dynamodbv2.document.Item) Table(com.amazonaws.services.dynamodbv2.document.Table) ScanOutcome(com.amazonaws.services.dynamodbv2.document.ScanOutcome) ValueMap(com.amazonaws.services.dynamodbv2.document.utils.ValueMap) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) NameMap(com.amazonaws.services.dynamodbv2.document.utils.NameMap) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) ScanSpec(com.amazonaws.services.dynamodbv2.document.spec.ScanSpec)

Example 19 with ValueMap

use of com.amazonaws.services.dynamodbv2.document.utils.ValueMap in project aws-doc-sdk-examples by awsdocs.

the class MoviesItemOps04 method main.

public static void main(String[] args) throws Exception {
    AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:8000", "us-west-2")).build();
    DynamoDB dynamoDB = new DynamoDB(client);
    Table table = dynamoDB.getTable("Movies");
    int year = 2015;
    String title = "The Big New Movie";
    UpdateItemSpec updateItemSpec = new UpdateItemSpec().withPrimaryKey("year", year, "title", title).withUpdateExpression("set info.rating = info.rating + :val").withValueMap(new ValueMap().withNumber(":val", 1)).withReturnValues(ReturnValue.UPDATED_NEW);
    try {
        System.out.println("Incrementing an atomic counter...");
        UpdateItemOutcome outcome = table.updateItem(updateItemSpec);
        System.out.println("UpdateItem succeeded:\n" + outcome.getItem().toJSONPretty());
    } catch (Exception e) {
        System.err.println("Unable to update item: " + year + " " + title);
        System.err.println(e.getMessage());
    }
}
Also used : Table(com.amazonaws.services.dynamodbv2.document.Table) UpdateItemSpec(com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec) ValueMap(com.amazonaws.services.dynamodbv2.document.utils.ValueMap) UpdateItemOutcome(com.amazonaws.services.dynamodbv2.document.UpdateItemOutcome) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB)

Example 20 with ValueMap

use of com.amazonaws.services.dynamodbv2.document.utils.ValueMap in project aws-doc-sdk-examples by awsdocs.

the class DocumentAPIItemCRUDExample method deleteItem.

private static void deleteItem() {
    Table table = dynamoDB.getTable(tableName);
    try {
        DeleteItemSpec deleteItemSpec = new DeleteItemSpec().withPrimaryKey("Id", 120).withConditionExpression("#ip = :val").withNameMap(new NameMap().with("#ip", "InPublication")).withValueMap(new ValueMap().withBoolean(":val", false)).withReturnValues(ReturnValue.ALL_OLD);
        DeleteItemOutcome outcome = table.deleteItem(deleteItemSpec);
        // Check the response.
        System.out.println("Printing item that was deleted...");
        System.out.println(outcome.getItem().toJSONPretty());
    } catch (Exception e) {
        System.err.println("Error deleting item in " + tableName);
        System.err.println(e.getMessage());
    }
}
Also used : DeleteItemOutcome(com.amazonaws.services.dynamodbv2.document.DeleteItemOutcome) DeleteItemSpec(com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec) Table(com.amazonaws.services.dynamodbv2.document.Table) ValueMap(com.amazonaws.services.dynamodbv2.document.utils.ValueMap) NameMap(com.amazonaws.services.dynamodbv2.document.utils.NameMap) IOException(java.io.IOException)

Aggregations

Table (com.amazonaws.services.dynamodbv2.document.Table)19 ValueMap (com.amazonaws.services.dynamodbv2.document.utils.ValueMap)19 QuerySpec (com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)12 Item (com.amazonaws.services.dynamodbv2.document.Item)11 QueryOutcome (com.amazonaws.services.dynamodbv2.document.QueryOutcome)10 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)6 DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)6 UpdateItemOutcome (com.amazonaws.services.dynamodbv2.document.UpdateItemOutcome)6 UpdateItemSpec (com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec)6 NameMap (com.amazonaws.services.dynamodbv2.document.utils.NameMap)5 IOException (java.io.IOException)4 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 Index (com.amazonaws.services.dynamodbv2.document.Index)2 PrimaryKey (com.amazonaws.services.dynamodbv2.document.PrimaryKey)2 DeleteItemSpec (com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec)2 ConditionalCheckFailedException (com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException)2 HashMap (java.util.HashMap)2 DeleteItemOutcome (com.amazonaws.services.dynamodbv2.document.DeleteItemOutcome)1 ItemCollection (com.amazonaws.services.dynamodbv2.document.ItemCollection)1