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());
}
}
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;
}
}
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();
}
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);
}
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"));
}
Aggregations