Search in sources :

Example 6 with DeleteItemSpec

use of com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec in project athenz by yahoo.

the class DynamoDBSSHRecordStoreConnection method deleteSSHCertRecord.

@Override
public boolean deleteSSHCertRecord(String instanceId, String service) {
    final String primaryKey = getPrimaryKey(instanceId, service);
    try {
        DeleteItemSpec deleteItemSpec = new DeleteItemSpec().withPrimaryKey(KEY_PRIMARY, primaryKey);
        table.deleteItem(deleteItemSpec);
        return true;
    } catch (Exception ex) {
        LOGGER.error("DynamoDB Delete Error for {}: {}/{}", primaryKey, ex.getClass(), ex.getMessage());
        return false;
    }
}
Also used : DeleteItemSpec(com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec)

Example 7 with DeleteItemSpec

use of com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec in project spring-integration-aws by spring-projects.

the class DynamoDbMetaDataStore method remove.

@Override
public String remove(String key) {
    Assert.hasText(key, "'key' must not be empty.");
    awaitForActive();
    Item item = this.table.deleteItem(new DeleteItemSpec().withPrimaryKey(KEY, key).withReturnValues(ReturnValue.ALL_OLD)).getItem();
    return getValueIfAny(item);
}
Also used : Item(com.amazonaws.services.dynamodbv2.document.Item) DeleteItemSpec(com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec)

Example 8 with DeleteItemSpec

use of com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec in project thunder by RohanNagar.

the class UsersDao method delete.

/**
 * Delete a PilotUser in the data store.
 *
 * @param email The email of the user to delete.
 * @return The PilotUser object that was deleted or {@code null} if the delete failed.
 * @throws DatabaseException If the user is not found or if the database is down.
 */
public PilotUser delete(String email) {
    checkNotNull(email);
    // Get the item that will be deleted to return it
    Item item;
    try {
        item = table.getItem("email", email);
    } catch (AmazonClientException e) {
        LOG.error("The database is currently unresponsive.", e);
        throw new DatabaseException("The database is currently unavailable.", DatabaseError.DATABASE_DOWN);
    }
    DeleteItemSpec deleteItemSpec = new DeleteItemSpec().withPrimaryKey("email", email).withExpected(new Expected("email").exists());
    try {
        table.deleteItem(deleteItemSpec);
    } catch (ConditionalCheckFailedException e) {
        LOG.warn("The email {} was not found in the database.", email, e);
        throw new DatabaseException("The user to delete was not found.", DatabaseError.USER_NOT_FOUND);
    } catch (AmazonClientException e) {
        LOG.error("The database is currently unresponsive.", e);
        throw new DatabaseException("The database is currently unavailable.", DatabaseError.DATABASE_DOWN);
    }
    return fromJson(mapper, item.getJSON("document"));
}
Also used : Item(com.amazonaws.services.dynamodbv2.document.Item) DeleteItemSpec(com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec) Expected(com.amazonaws.services.dynamodbv2.document.Expected) AmazonClientException(com.amazonaws.AmazonClientException) ConditionalCheckFailedException(com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException)

Aggregations

DeleteItemSpec (com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec)8 Item (com.amazonaws.services.dynamodbv2.document.Item)2 Table (com.amazonaws.services.dynamodbv2.document.Table)2 ValueMap (com.amazonaws.services.dynamodbv2.document.utils.ValueMap)2 ConditionalCheckFailedException (com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException)2 Test (org.testng.annotations.Test)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)1 DeleteItemOutcome (com.amazonaws.services.dynamodbv2.document.DeleteItemOutcome)1 DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)1 Expected (com.amazonaws.services.dynamodbv2.document.Expected)1 PrimaryKey (com.amazonaws.services.dynamodbv2.document.PrimaryKey)1 NameMap (com.amazonaws.services.dynamodbv2.document.utils.NameMap)1 IOException (java.io.IOException)1