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