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());
}
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();
}
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();
}
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.");
}
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++;
}
}
Aggregations