Search in sources :

Example 21 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)

Example 22 with DynamoDbEnhancedClient

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

the class DynamoDBEnhanced method injectDynamoItem.

// Uses the Enhanced Client to inject a new post into a DynamoDB table
public void injectDynamoItem(Greeting item) {
    Region region = Region.US_EAST_1;
    DynamoDbClient ddb = DynamoDbClient.builder().region(region).credentialsProvider(EnvironmentVariableCredentialsProvider.create()).build();
    try {
        DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(ddb).build();
        // Create a DynamoDbTable object
        DynamoDbTable<GreetingItems> mappedTable = enhancedClient.table("Greeting", TableSchema.fromBean(GreetingItems.class));
        GreetingItems gi = new GreetingItems();
        gi.setName(item.getName());
        gi.setMessage(item.getBody());
        gi.setTitle(item.getTitle());
        gi.setId(item.getId());
        PutItemEnhancedRequest enReq = PutItemEnhancedRequest.builder(GreetingItems.class).item(gi).build();
        mappedTable.putItem(enReq);
    } catch (Exception e) {
        e.getStackTrace();
    }
}
Also used : DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) Region(software.amazon.awssdk.regions.Region) PutItemEnhancedRequest(software.amazon.awssdk.enhanced.dynamodb.model.PutItemEnhancedRequest) DynamoDbEnhancedClient(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient)

Example 23 with DynamoDbEnhancedClient

use of software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient in project aws-sdk-java-v2 by aws.

the class BatchGetItemOperationTest method setupMappedTables.

@Before
public void setupMappedTables() {
    DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(mockDynamoDbClient).extensions().build();
    fakeItemMappedTable = enhancedClient.table(TABLE_NAME, FakeItem.getTableSchema());
    fakeItemWithSortMappedTable = enhancedClient.table(TABLE_NAME_2, FakeItemWithSort.getTableSchema());
}
Also used : DynamoDbEnhancedClient(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient) Before(org.junit.Before)

Example 24 with DynamoDbEnhancedClient

use of software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient in project aws-sdk-java-v2 by aws.

the class EmptyStringTest method initializeTable.

@Before
public void initializeTable() {
    DynamoDbEnhancedClient dynamoDbEnhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(mockDynamoDbClient).build();
    this.dynamoDbTable = dynamoDbEnhancedClient.table(TABLE_NAME, TABLE_SCHEMA);
}
Also used : DynamoDbEnhancedClient(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient) Before(org.junit.Before)

Example 25 with DynamoDbEnhancedClient

use of software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient in project aws-sdk-java-v2 by aws.

the class EmptyBinaryTest method initializeTable.

@Before
public void initializeTable() {
    DynamoDbEnhancedClient dynamoDbEnhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(mockDynamoDbClient).build();
    this.dynamoDbTable = dynamoDbEnhancedClient.table(TABLE_NAME, TABLE_SCHEMA);
}
Also used : DynamoDbEnhancedClient(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient) Before(org.junit.Before)

Aggregations

DynamoDbEnhancedClient (software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient)25 DynamoDbClient (software.amazon.awssdk.services.dynamodb.DynamoDbClient)14 Region (software.amazon.awssdk.regions.Region)12 DynamoDbException (software.amazon.awssdk.services.dynamodb.model.DynamoDbException)8 Before (org.junit.Before)4 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