Search in sources :

Example 76 with DynamoDB

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();
        }
    }
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) DeleteItemRequest(com.amazonaws.services.dynamodbv2.model.DeleteItemRequest) ArrayList(java.util.ArrayList) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) ToString(lombok.ToString) DeleteItemResult(com.amazonaws.services.dynamodbv2.model.DeleteItemResult) Map(java.util.Map)

Example 77 with DynamoDB

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);
}
Also used : AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB)

Example 78 with DynamoDB

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);
}
Also used : AmazonDaxClientBuilder(com.amazon.dax.client.dynamodbv2.AmazonDaxClientBuilder) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB)

Example 79 with DynamoDB

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();
    }
}
Also used : Table(com.amazonaws.services.dynamodbv2.document.Table)

Example 80 with DynamoDB

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();
    }
}
Also used : DynamoDBMapper(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper)

Aggregations

DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)38 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)32 Table (com.amazonaws.services.dynamodbv2.document.Table)25 Item (com.amazonaws.services.dynamodbv2.document.Item)19 Test (org.junit.Test)18 AmazonServiceException (com.amazonaws.AmazonServiceException)16 HashMap (java.util.HashMap)15 TestRunner (org.apache.nifi.util.TestRunner)15 AmazonClientException (com.amazonaws.AmazonClientException)14 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)14 MockFlowFile (org.apache.nifi.util.MockFlowFile)14 ArrayList (java.util.ArrayList)11 Map (java.util.Map)11 TableWriteItems (com.amazonaws.services.dynamodbv2.document.TableWriteItems)10 KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)10 IOException (java.io.IOException)10 TableKeysAndAttributes (com.amazonaws.services.dynamodbv2.document.TableKeysAndAttributes)9 AttributeDefinition (com.amazonaws.services.dynamodbv2.model.AttributeDefinition)9 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)9 List (java.util.List)9