Search in sources :

Example 56 with Item

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

the class DynamoDBDynamicFaultInjection method getItem.

/*
     * Get an item from the table
     */
private static void getItem(String keyVal) {
    Map<String, AttributeValue> key = new HashMap<String, AttributeValue>();
    key.put("name", new AttributeValue(keyVal));
    GetItemRequest getItemRequest = new GetItemRequest().withTableName(TABLENAME).withKey(key);
    GetItemResult item = dynamoDBClient.getItem(getItemRequest);
    logger.info("Get Result: " + item);
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) GetItemResult(com.amazonaws.services.dynamodbv2.model.GetItemResult) HashMap(java.util.HashMap) GetItemRequest(com.amazonaws.services.dynamodbv2.model.GetItemRequest)

Example 57 with Item

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

the class DocumentAPIScan method findProductsForPriceLessThanOneHundred.

private static void findProductsForPriceLessThanOneHundred() {
    Table table = dynamoDB.getTable(tableName);
    Map<String, Object> expressionAttributeValues = new HashMap<String, Object>();
    expressionAttributeValues.put(":pr", 100);
    ItemCollection<ScanOutcome> items = // FilterExpression
    table.scan(// FilterExpression
    "Price < :pr", // ProjectionExpression
    "Id, Title, ProductCategory, Price", // ExpressionAttributeNames - not used in this example
    null, expressionAttributeValues);
    System.out.println("Scan of " + tableName + " for items with a price less than 100.");
    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) HashMap(java.util.HashMap) ScanOutcome(com.amazonaws.services.dynamodbv2.document.ScanOutcome)

Example 58 with Item

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

the class MoviesItemOps01 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";
    final Map<String, Object> infoMap = new HashMap<String, Object>();
    infoMap.put("plot", "Nothing happens at all.");
    infoMap.put("rating", 0);
    try {
        System.out.println("Adding a new item...");
        PutItemOutcome outcome = table.putItem(new Item().withPrimaryKey("year", year, "title", title).withMap("info", infoMap));
        System.out.println("PutItem succeeded:\n" + outcome.getPutItemResult());
    } catch (Exception e) {
        System.err.println("Unable to add item: " + year + " " + title);
        System.err.println(e.getMessage());
    }
}
Also used : Item(com.amazonaws.services.dynamodbv2.document.Item) PutItemOutcome(com.amazonaws.services.dynamodbv2.document.PutItemOutcome) Table(com.amazonaws.services.dynamodbv2.document.Table) HashMap(java.util.HashMap) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB)

Example 59 with Item

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

the class MoviesItemOps03 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 = :r, info.plot=:p, info.actors=:a").withValueMap(new ValueMap().withNumber(":r", 5.5).withString(":p", "Everything happens all at once.").withList(":a", Arrays.asList("Larry", "Moe", "Curly"))).withReturnValues(ReturnValue.UPDATED_NEW);
    try {
        System.out.println("Updating the item...");
        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 60 with Item

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

the class MoviesLoadData 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");
    JsonParser parser = new JsonFactory().createParser(new File("moviedata.json"));
    JsonNode rootNode = new ObjectMapper().readTree(parser);
    Iterator<JsonNode> iter = rootNode.iterator();
    ObjectNode currentNode;
    while (iter.hasNext()) {
        currentNode = (ObjectNode) iter.next();
        int year = currentNode.path("year").asInt();
        String title = currentNode.path("title").asText();
        try {
            table.putItem(new Item().withPrimaryKey("year", year, "title", title).withJSON("info", currentNode.path("info").toString()));
            System.out.println("PutItem succeeded: " + year + " " + title);
        } catch (Exception e) {
            System.err.println("Unable to add movie: " + year + " " + title);
            System.err.println(e.getMessage());
            break;
        }
    }
    parser.close();
}
Also used : Table(com.amazonaws.services.dynamodbv2.document.Table) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonFactory(com.fasterxml.jackson.core.JsonFactory) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) JsonNode(com.fasterxml.jackson.databind.JsonNode) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) Item(com.amazonaws.services.dynamodbv2.document.Item) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonParser(com.fasterxml.jackson.core.JsonParser)

Aggregations

AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)107 Item (com.amazonaws.services.dynamodbv2.document.Item)95 HashMap (java.util.HashMap)60 Table (com.amazonaws.services.dynamodbv2.document.Table)53 Test (org.testng.annotations.Test)49 QuerySpec (com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)42 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)35 AmazonServiceException (com.amazonaws.AmazonServiceException)31 ValueMap (com.amazonaws.services.dynamodbv2.document.utils.ValueMap)27 UpdateItemSpec (com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec)26 ArrayList (java.util.ArrayList)25 DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)24 List (java.util.List)23 Test (org.junit.Test)23 QueryOutcome (com.amazonaws.services.dynamodbv2.document.QueryOutcome)22 IOException (java.io.IOException)21 X509CertRecord (com.yahoo.athenz.common.server.cert.X509CertRecord)20 AmazonDynamoDBException (com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException)18 Date (java.util.Date)18 Map (java.util.Map)17