Search in sources :

Example 1 with DeleteItemSpec

use of com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec in project aws-doc-sdk-examples by awsdocs.

the class MoviesItemOps06 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";
    DeleteItemSpec deleteItemSpec = new DeleteItemSpec().withPrimaryKey(new PrimaryKey("year", year, "title", title)).withConditionExpression("info.rating <= :val").withValueMap(new ValueMap().withNumber(":val", 5.0));
    try {
        System.out.println("Attempting a conditional delete...");
        table.deleteItem(deleteItemSpec);
        System.out.println("DeleteItem succeeded");
    } catch (Exception e) {
        System.err.println("Unable to delete item: " + year + " " + title);
        System.err.println(e.getMessage());
    }
}
Also used : DeleteItemSpec(com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec) Table(com.amazonaws.services.dynamodbv2.document.Table) ValueMap(com.amazonaws.services.dynamodbv2.document.utils.ValueMap) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) PrimaryKey(com.amazonaws.services.dynamodbv2.document.PrimaryKey) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB)

Example 2 with DeleteItemSpec

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

the class DynamoDBCertRecordStoreConnection method deleteX509CertRecord.

@Override
public boolean deleteX509CertRecord(String provider, String instanceId, String service) {
    final String primaryKey = getPrimaryKey(provider, instanceId, service);
    try {
        DeleteItemSpec deleteItemSpec = new DeleteItemSpec().withPrimaryKey(KEY_PRIMARY, primaryKey);
        deleteItemRetryDynamoDBCommand.run(() -> 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) ConditionalCheckFailedException(com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException)

Example 3 with DeleteItemSpec

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

the class DynamoDBCertRecordStoreConnectionTest method testDeleteX509Record.

@Test
public void testDeleteX509Record() {
    DeleteItemSpec deleteItemSpec = new DeleteItemSpec().withPrimaryKey("primaryKey", "athenz.provider:cn:1234");
    Mockito.doReturn(deleteOutcome).when(table).deleteItem(deleteItemSpec);
    DynamoDBCertRecordStoreConnection dbConn = getDBConnection();
    boolean requestSuccess = dbConn.deleteX509CertRecord("athenz.provider", "12345", "cn");
    assertTrue(requestSuccess);
    dbConn.close();
}
Also used : DeleteItemSpec(com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec) Test(org.testng.annotations.Test)

Example 4 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 5 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