use of com.amazonaws.services.dynamodbv2.document.DynamoDB in project aws-doc-sdk-examples by awsdocs.
the class LowLevelBatchGet method retrieveMultipleItemsBatchGet.
private static void retrieveMultipleItemsBatchGet() {
try {
Map<String, KeysAndAttributes> requestItems = new HashMap<String, KeysAndAttributes>();
List<Map<String, AttributeValue>> tableKeys = new ArrayList<Map<String, AttributeValue>>();
Map<String, AttributeValue> key = new HashMap<String, AttributeValue>();
key.put("Name", new AttributeValue().withS("Amazon S3"));
tableKeys.add(key);
key = new HashMap<String, AttributeValue>();
key.put("Name", new AttributeValue().withS("Amazon DynamoDB"));
tableKeys.add(key);
requestItems.put(table1Name, new KeysAndAttributes().withKeys(tableKeys));
tableKeys = new ArrayList<Map<String, AttributeValue>>();
key = new HashMap<String, AttributeValue>();
key.put("ForumName", new AttributeValue().withS("Amazon DynamoDB"));
key.put("Subject", new AttributeValue().withS("DynamoDB Thread 1"));
tableKeys.add(key);
key = new HashMap<String, AttributeValue>();
key.put("ForumName", new AttributeValue().withS("Amazon DynamoDB"));
key.put("Subject", new AttributeValue().withS("DynamoDB Thread 2"));
tableKeys.add(key);
key = new HashMap<String, AttributeValue>();
key.put("ForumName", new AttributeValue().withS("Amazon S3"));
key.put("Subject", new AttributeValue().withS("S3 Thread 1"));
tableKeys.add(key);
requestItems.put(table2Name, new KeysAndAttributes().withKeys(tableKeys));
BatchGetItemResult result;
BatchGetItemRequest batchGetItemRequest = new BatchGetItemRequest();
do {
System.out.println("Making the request.");
batchGetItemRequest.withRequestItems(requestItems);
result = client.batchGetItem(batchGetItemRequest);
List<Map<String, AttributeValue>> table1Results = result.getResponses().get(table1Name);
if (table1Results != null) {
System.out.println("Items in table " + table1Name);
for (Map<String, AttributeValue> item : table1Results) {
printItem(item);
}
}
List<Map<String, AttributeValue>> table2Results = result.getResponses().get(table2Name);
if (table2Results != null) {
System.out.println("\nItems in table " + table2Name);
for (Map<String, AttributeValue> item : table2Results) {
printItem(item);
}
}
// throughput or reach the limit on response size.
for (Map.Entry<String, KeysAndAttributes> pair : result.getUnprocessedKeys().entrySet()) {
System.out.println("Unprocessed key pair: " + pair.getKey() + ", " + pair.getValue());
}
requestItems = result.getUnprocessedKeys();
} while (result.getUnprocessedKeys().size() > 0);
} catch (AmazonServiceException ase) {
System.err.println("Failed to retrieve items.");
}
}
use of com.amazonaws.services.dynamodbv2.document.DynamoDB in project aws-doc-sdk-examples by awsdocs.
the class MoviesItemOps04 method main.
public static void main(String[] args) throws Exception {
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:8000", "us-west-2")).build();
DynamoDB dynamoDB = new DynamoDB(client);
Table table = dynamoDB.getTable("Movies");
int year = 2015;
String title = "The Big New Movie";
UpdateItemSpec updateItemSpec = new UpdateItemSpec().withPrimaryKey("year", year, "title", title).withUpdateExpression("set info.rating = info.rating + :val").withValueMap(new ValueMap().withNumber(":val", 1)).withReturnValues(ReturnValue.UPDATED_NEW);
try {
System.out.println("Incrementing an atomic counter...");
UpdateItemOutcome outcome = table.updateItem(updateItemSpec);
System.out.println("UpdateItem succeeded:\n" + outcome.getItem().toJSONPretty());
} catch (Exception e) {
System.err.println("Unable to update item: " + year + " " + title);
System.err.println(e.getMessage());
}
}
use of com.amazonaws.services.dynamodbv2.document.DynamoDB in project aws-doc-sdk-examples by awsdocs.
the class DynamoDBLocalFixture method main.
public static void main(String[] args) throws Exception {
AmazonDynamoDB dynamodb = null;
try {
// Create an in-memory and in-process instance of DynamoDB Local
// that skips HTTP
dynamodb = DynamoDBEmbedded.create();
// use the DynamoDB API with DynamoDBEmbedded
listTables(dynamodb.listTables(), "DynamoDB Embedded");
} finally {
// Shutdown the thread pools in DynamoDB Local / Embedded
if (dynamodb != null) {
dynamodb.shutdown();
}
}
// Create an in-memory and in-process instance of DynamoDB Local that
// runs over HTTP
final String[] localArgs = { "-inMemory" };
DynamoDBProxyServer server = null;
try {
server = ServerRunner.createServerFromCommandLineArgs(localArgs);
server.start();
dynamodb = new AmazonDynamoDBClient();
dynamodb.setEndpoint("http://localhost:8000");
// use the DynamoDB API over HTTP
listTables(dynamodb.listTables(), "DynamoDB Local over HTTP");
} finally {
// Stop the DynamoDB Local endpoint
if (server != null) {
server.stop();
}
}
}
use of com.amazonaws.services.dynamodbv2.document.DynamoDB in project beam by apache.
the class DynamoDBIOIT method runRead.
/**
* Read test dataset from DynamoDB.
*/
private void runRead() {
int rows = env.options().getNumberOfRows();
PCollection<Map<String, AttributeValue>> records = pipelineRead.apply("Read from DynamoDB", DynamoDBIO.read().withAwsClientsProvider(clientProvider()).withScanRequestFn(in -> buildScanRequest()).items()).apply("Flatten result", Flatten.iterables());
PAssert.thatSingleton(records.apply("Count All", Count.globally())).isEqualTo((long) rows);
PCollection<String> consolidatedHashcode = records.apply(MapElements.into(strings()).via(record -> record.get(COL_NAME).getS())).apply("Hash records", Combine.globally(new HashingFn()).withoutDefaults());
PAssert.that(consolidatedHashcode).containsInAnyOrder(getExpectedHashForRowCount(rows));
pipelineRead.run().waitUntilFinish();
}
use of com.amazonaws.services.dynamodbv2.document.DynamoDB in project athenz by yahoo.
the class DynamoDBSSHRecordStoreConnectionTest method testDeleteSSHRecord.
@Test
public void testDeleteSSHRecord() {
DeleteItemSpec deleteItemSpec = new DeleteItemSpec().withPrimaryKey("primaryKey", "cn:1234");
Mockito.doReturn(deleteOutcome).when(table).deleteItem(deleteItemSpec);
DynamoDBSSHRecordStoreConnection dbConn = new DynamoDBSSHRecordStoreConnection(dynamoDB, tableName);
boolean requestSuccess = dbConn.deleteSSHCertRecord("12345", "cn");
assertTrue(requestSuccess);
dbConn.close();
}
Aggregations