Search in sources :

Example 11 with DynamoDbEnhancedClient

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

the class BatchWriteItemOperationTest method setupMappedTables.

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

Example 12 with DynamoDbEnhancedClient

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

the class EnhancedScanRecords 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();
    scan(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 13 with DynamoDbEnhancedClient

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

the class EnhancedTableSchema 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 14 with DynamoDbEnhancedClient

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

the class Scenario method putRecord.

public static void putRecord(DynamoDbClient ddb) {
    try {
        // Create a DynamoDbEnhancedClient.
        DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(ddb).build();
        // Create a DynamoDbTable object.
        DynamoDbTable<Movies> table = enhancedClient.table("Movies", TableSchema.fromBean(Movies.class));
        // Populate the Table.
        Movies record = new Movies();
        record.setYear(2020);
        record.setTitle("My Movie2");
        record.setInfo("no info");
        // Put the data into a DynamoDB table.
        table.putItem(record);
    } catch (DynamoDbException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
    System.out.println("Added a new issue to the table.");
}
Also used : DynamoDbException(software.amazon.awssdk.services.dynamodb.model.DynamoDbException) DynamoDbEnhancedClient(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient)

Example 15 with DynamoDbEnhancedClient

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

the class Scenario method loadData.

// snippet-end:[dynamodb.java2.scenario.scan.main]
// snippet-start:[dynamodb.java2.scenario.populate_table.main]
// Load data into the table.
public static void loadData(DynamoDbClient ddb, String tableName, String fileName) throws IOException {
    DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(ddb).build();
    DynamoDbTable<Movies> mappedTable = enhancedClient.table("Movies", TableSchema.fromBean(Movies.class));
    JsonParser parser = new JsonFactory().createParser(new File(fileName));
    com.fasterxml.jackson.databind.JsonNode rootNode = new ObjectMapper().readTree(parser);
    Iterator<JsonNode> iter = rootNode.iterator();
    ObjectNode currentNode;
    int t = 0;
    while (iter.hasNext()) {
        // Only add 200 Movies to the table.
        if (t == 200)
            break;
        currentNode = (ObjectNode) iter.next();
        int year = currentNode.path("year").asInt();
        String title = currentNode.path("title").asText();
        String info = currentNode.path("info").toString();
        Movies movies = new Movies();
        movies.setYear(year);
        movies.setTitle(title);
        movies.setInfo(info);
        // Put the data into the Amazon DynamoDB Movie table.
        mappedTable.putItem(movies);
        t++;
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) File(java.io.File) DynamoDbEnhancedClient(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonParser(com.fasterxml.jackson.core.JsonParser)

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