use of com.amazonaws.services.dynamodbv2.document.DynamoDB in project jcabi-dynamo by jcabi.
the class AwsIterator method remove.
@Override
@SuppressWarnings("PMD.UseConcurrentHashMap")
public void remove() {
synchronized (this.dosage) {
final AmazonDynamoDB aws = this.credentials.aws();
try {
final Dosage prev = this.dosage.get();
final List<Map<String, AttributeValue>> items = new ArrayList<Map<String, AttributeValue>>(prev.items());
final Map<String, AttributeValue> item = items.remove(this.position);
final long start = System.currentTimeMillis();
final DeleteItemResult res = aws.deleteItem(new DeleteItemRequest().withTableName(this.name).withKey(new Attributes(item).only(this.keys)).withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL).withExpected(new Attributes(item).only(this.keys).asKeys()));
this.dosage.set(new AwsIterator.Fixed(prev, items));
--this.position;
Logger.info(this, "#remove(): item #%d removed from DynamoDB, %s, in %[ms]s", this.position, new PrintableConsumedCapacity(res.getConsumedCapacity()).print(), System.currentTimeMillis() - start);
} finally {
aws.shutdown();
}
}
}
use of com.amazonaws.services.dynamodbv2.document.DynamoDB in project aws-doc-sdk-examples by awsdocs.
the class TryDaxHelper method getDynamoDBClient.
DynamoDB getDynamoDBClient() {
System.out.println("Creating a DynamoDB client");
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().withRegion(region).build();
return new DynamoDB(client);
}
use of com.amazonaws.services.dynamodbv2.document.DynamoDB in project aws-doc-sdk-examples by awsdocs.
the class TryDaxHelper method getDaxClient.
DynamoDB getDaxClient(String daxEndpoint) {
System.out.println("Creating a DAX client with cluster endpoint " + daxEndpoint);
AmazonDaxClientBuilder daxClientBuilder = AmazonDaxClientBuilder.standard();
daxClientBuilder.withRegion(region).withEndpointConfiguration(daxEndpoint);
AmazonDynamoDB client = daxClientBuilder.build();
return new DynamoDB(client);
}
use of com.amazonaws.services.dynamodbv2.document.DynamoDB in project aws-doc-sdk-examples by awsdocs.
the class TryDaxHelper method deleteTable.
void deleteTable(String tableName, DynamoDB client) {
Table table = client.getTable(tableName);
try {
System.out.println("\nAttempting to delete table; please wait...");
table.delete();
table.waitForDelete();
System.out.println("Successfully deleted table.");
} catch (Exception e) {
System.err.println("Unable to delete table: ");
e.printStackTrace();
}
}
use of com.amazonaws.services.dynamodbv2.document.DynamoDB in project aws-doc-sdk-examples by awsdocs.
the class DynamoDBMapperQueryScanExample method main.
public static void main(String[] args) throws Exception {
try {
DynamoDBMapper mapper = new DynamoDBMapper(client);
// Get a book - Id=101
GetBook(mapper, 101);
// Sample forum and thread to test queries.
String forumName = "Amazon DynamoDB";
String threadSubject = "DynamoDB Thread 1";
// Sample queries.
FindRepliesInLast15Days(mapper, forumName, threadSubject);
FindRepliesPostedWithinTimePeriod(mapper, forumName, threadSubject);
// Scan a table and find book items priced less than specified
// value.
FindBooksPricedLessThanSpecifiedValue(mapper, "20");
// Scan a table with multiple threads and find bicycle items with a
// specified bicycle type
int numberOfThreads = 16;
FindBicyclesOfSpecificTypeWithMultipleThreads(mapper, numberOfThreads, "Road");
System.out.println("Example complete!");
} catch (Throwable t) {
System.err.println("Error running the DynamoDBMapperQueryScanExample: " + t);
t.printStackTrace();
}
}
Aggregations