Search in sources :

Example 16 with DynamoDbEnhancedClient

use of software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient in project aws-doc-sdk-examples by awsdocs.

the class EnhancedGetItem method main.

public static void main(String[] args) {
    Region region = Region.US_EAST_1;
    DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();
    DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(ddb).build();
    String result = getItem(enhancedClient);
    System.out.println(result);
    ddb.close();
}
Also used : DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) Region(software.amazon.awssdk.regions.Region) DynamoDbEnhancedClient(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient)

Example 17 with DynamoDbEnhancedClient

use of software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient in project aws-doc-sdk-examples by awsdocs.

the class EnhancedPutItem method main.

public static void main(String[] args) {
    Region region = Region.US_EAST_1;
    DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();
    DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(ddb).build();
    putRecord(enhancedClient);
    ddb.close();
}
Also used : DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) Region(software.amazon.awssdk.regions.Region) DynamoDbEnhancedClient(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient)

Example 18 with DynamoDbEnhancedClient

use of software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient in project aws-doc-sdk-examples by awsdocs.

the class EnhancedModifyItem method main.

public static void main(String[] args) {
    String usage = "Usage:\n" + "    <key> <email> \n\n" + "Where:\n" + "    key - the name of the key in the table (id120).\n" + "    email - the value of the modified email column.\n";
    if (args.length != 2) {
        System.out.println(usage);
        System.exit(1);
    }
    String key = args[0];
    String email = args[1];
    Region region = Region.US_EAST_1;
    DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();
    DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(ddb).build();
    String updatedValue = modifyItem(enhancedClient, key, email);
    System.out.println("The updated name value is " + updatedValue);
    ddb.close();
}
Also used : DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) Region(software.amazon.awssdk.regions.Region) DynamoDbEnhancedClient(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient)

Example 19 with DynamoDbEnhancedClient

use of software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient in project aws-doc-sdk-examples by awsdocs.

the class EnhancedQueryRecords method main.

public static void main(String[] args) {
    Region region = Region.US_EAST_1;
    DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();
    DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(ddb).build();
    String result = queryTable(enhancedClient);
    System.out.println(result);
    ddb.close();
}
Also used : DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) Region(software.amazon.awssdk.regions.Region) DynamoDbEnhancedClient(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient)

Example 20 with DynamoDbEnhancedClient

use of software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient in project aws-doc-sdk-examples by awsdocs.

the class DynamoDBService method persistItem.

// Persist the PPE Items into the Gear table.
public void persistItem(List<ArrayList<GearItem>> gearList) {
    DynamoDbClient ddb = getClient();
    try {
        DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(ddb).build();
        DynamoDbTable<Gear> gearTable = enhancedClient.table("Gear", TableSchema.fromBean(Gear.class));
        Gear gearRecord;
        // Create an Instant.
        // current date and time
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime timeVal = now.toLocalDate().atStartOfDay();
        Instant instant = timeVal.toInstant(ZoneOffset.UTC);
        // Persist the data into a DynamoDB table.
        for (Object o : gearList) {
            // Need to get the WorkItem from each list.
            List innerList = (List) o;
            for (Object value : innerList) {
                gearRecord = new Gear();
                UUID uuid = UUID.randomUUID();
                GearItem gearItem = (GearItem) value;
                gearRecord.setId(uuid.toString());
                gearRecord.setKey(gearItem.getKey());
                gearRecord.setDate(instant.toString());
                gearRecord.setItem(gearItem.getName());
                gearRecord.setCoverDescription(gearItem.getBodyCoverDescription());
                gearRecord.setItemDescription(gearItem.getItemDescription());
                gearRecord.setConfidence(gearItem.getConfidence());
                // Put PPE data into a DynamoDB table.
                gearTable.putItem(gearRecord);
            }
        }
    } catch (DynamoDbException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) DynamoDbException(software.amazon.awssdk.services.dynamodb.model.DynamoDbException) Instant(java.time.Instant) List(java.util.List) ArrayList(java.util.ArrayList) UUID(java.util.UUID) DynamoDbEnhancedClient(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient)

Aggregations

DynamoDbEnhancedClient (software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient)21 DynamoDbClient (software.amazon.awssdk.services.dynamodb.DynamoDbClient)14 Region (software.amazon.awssdk.regions.Region)12 DynamoDbException (software.amazon.awssdk.services.dynamodb.model.DynamoDbException)8 Instant (java.time.Instant)3 LocalDateTime (java.time.LocalDateTime)3 Expression (software.amazon.awssdk.enhanced.dynamodb.Expression)3 ScanEnhancedRequest (software.amazon.awssdk.enhanced.dynamodb.model.ScanEnhancedRequest)3 LocalDate (java.time.LocalDate)2 QueryConditional (software.amazon.awssdk.enhanced.dynamodb.model.QueryConditional)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonParser (com.fasterxml.jackson.core.JsonParser)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 File (java.io.File)1 ZoneOffset (java.time.ZoneOffset)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1