use of software.amazon.awssdk.services.dynamodb.DynamoDbClient in project cas by apereo.
the class DynamoDbTableUtils method getRecordsByKeys.
/**
* Gets records by keys.
*
* @param <T> the type parameter
* @param dynamoDbClient the dynamo db client
* @param tableName the table name
* @param queries the queries
* @param itemMapper the item mapper
* @return the records by keys
*/
public static <T> Stream<T> getRecordsByKeys(final DynamoDbClient dynamoDbClient, final String tableName, final List<DynamoDbQueryBuilder> queries, final Function<Map<String, AttributeValue>, T> itemMapper) {
try {
val scanFilter = queries.stream().map(query -> {
val cond = Condition.builder().comparisonOperator(query.getOperator()).attributeValueList(query.getAttributeValue()).build();
return Pair.of(query.getKey(), cond);
}).collect(Collectors.toMap(Pair::getKey, Pair::getValue));
val scanRequest = ScanRequest.builder().tableName(tableName).scanFilter(scanFilter).build();
LOGGER.debug("Submitting request [{}] to get record with keys [{}]", scanRequest, queries);
val items = dynamoDbClient.scan(scanRequest).items();
return items.stream().map(itemMapper);
} catch (final Exception e) {
LoggingUtils.error(LOGGER, e);
}
return Stream.empty();
}
use of software.amazon.awssdk.services.dynamodb.DynamoDbClient 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.services.dynamodb.DynamoDbClient 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.services.dynamodb.DynamoDbClient in project aws-doc-sdk-examples by awsdocs.
the class PutItem method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " <tableName> <key> <keyVal> <albumtitle> <albumtitleval> <awards> <awardsval> <Songtitle> <songtitleval>\n\n" + "Where:\n" + " tableName - the Amazon DynamoDB table in which an item is placed (for example, Music3).\n" + " key - the key used in the Amazon DynamoDB table (for example, Artist).\n" + " keyval - the key value that represents the item to get (for example, Famous Band).\n" + " albumTitle - album title (for example, AlbumTitle).\n" + " AlbumTitleValue - the name of the album (for example, Songs About Life ).\n" + " Awards - the awards column (for example, Awards).\n" + " AwardVal - the value of the awards (for example, 10).\n" + " SongTitle - the song title (for example, SongTitle).\n" + " SongTitleVal - the value of the song title (for example, Happy Day).\n" + "**Warning** This program will place an item that you specify into a table!\n";
if (args.length != 9) {
System.out.println(USAGE);
System.exit(1);
}
String tableName = args[0];
String key = args[1];
String keyVal = args[2];
String albumTitle = args[3];
String albumTitleValue = args[4];
String awards = args[5];
String awardVal = args[6];
String songTitle = args[7];
String songTitleVal = args[8];
Region region = Region.US_WEST_2;
DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();
putItemInTable(ddb, tableName, key, keyVal, albumTitle, albumTitleValue, awards, awardVal, songTitle, songTitleVal);
System.out.println("Done!");
ddb.close();
}
use of software.amazon.awssdk.services.dynamodb.DynamoDbClient in project aws-doc-sdk-examples by awsdocs.
the class Query method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " Query <tableName> <partitionKeyName> <partitionKeyVal>\n\n" + "Where:\n" + " tableName - the Amazon DynamoDB table to put the item in (for example, Music3).\n" + " partitionKeyName - the partition key name of the Amazon DynamoDB table (for example, Artist).\n" + " partitionKeyVal - value of the partition key that should match (for example, Famous Band).\n\n" + "Example:\n";
if (args.length != 3) {
System.out.println(USAGE);
System.exit(1);
}
String tableName = args[0];
String partitionKeyName = args[1];
String partitionKeyVal = args[2];
// For more information about an alias, see:
// https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeNames.html
String partitionAlias = "#a";
System.out.format("Querying %s", tableName);
System.out.println("");
Region region = Region.US_EAST_1;
DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();
int count = queryTable(ddb, tableName, partitionKeyName, partitionKeyVal, partitionAlias);
System.out.println("There were " + count + "record(s) returned");
ddb.close();
}
Aggregations