.build()); DeleteItemRequest deleteReq = DeleteItemRequest.builder() .tableName(table_name) .key(key_to_get)
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. */ @Override public String toString() { return ToString.builder("DeleteItemRequest").add("TableName", tableName()).add("Key", key()).add("Expected", expected()) .add("ConditionalOperator", conditionalOperatorAsString()).add("ReturnValues", returnValuesAsString()) .add("ReturnConsumedCapacity", returnConsumedCapacityAsString()) .add("ReturnItemCollectionMetrics", returnItemCollectionMetricsAsString()) .add("ConditionExpression", conditionExpression()).add("ExpressionAttributeNames", expressionAttributeNames()) .add("ExpressionAttributeValues", expressionAttributeValues()).build(); }
@Override public DeleteItemRequest build() { return new DeleteItemRequest(this); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof DeleteItemRequest)) { return false; } DeleteItemRequest other = (DeleteItemRequest) obj; return Objects.equals(tableName(), other.tableName()) && Objects.equals(key(), other.key()) && Objects.equals(expected(), other.expected()) && Objects.equals(conditionalOperatorAsString(), other.conditionalOperatorAsString()) && Objects.equals(returnValuesAsString(), other.returnValuesAsString()) && Objects.equals(returnConsumedCapacityAsString(), other.returnConsumedCapacityAsString()) && Objects.equals(returnItemCollectionMetricsAsString(), other.returnItemCollectionMetricsAsString()) && Objects.equals(conditionExpression(), other.conditionExpression()) && Objects.equals(expressionAttributeNames(), other.expressionAttributeNames()) && Objects.equals(expressionAttributeValues(), other.expressionAttributeValues()); }
@Override public int hashCode() { int hashCode = 1; hashCode = 31 * hashCode + Objects.hashCode(tableName()); hashCode = 31 * hashCode + Objects.hashCode(key()); hashCode = 31 * hashCode + Objects.hashCode(expected()); hashCode = 31 * hashCode + Objects.hashCode(conditionalOperatorAsString()); hashCode = 31 * hashCode + Objects.hashCode(returnValuesAsString()); hashCode = 31 * hashCode + Objects.hashCode(returnConsumedCapacityAsString()); hashCode = 31 * hashCode + Objects.hashCode(returnItemCollectionMetricsAsString()); hashCode = 31 * hashCode + Objects.hashCode(conditionExpression()); hashCode = 31 * hashCode + Objects.hashCode(expressionAttributeNames()); hashCode = 31 * hashCode + Objects.hashCode(expressionAttributeValues()); return hashCode; }
/** * Deletes an order. * @param orderId order id of order to delete * @return the deleted order */ public Order deleteOrder(final String orderId) { final DeleteItemResponse result; try { return Optional.ofNullable(dynamoDb.deleteItem(DeleteItemRequest.builder() .tableName(tableName) .key(Collections.singletonMap(ORDER_ID, AttributeValue.builder().s(orderId).build())) .conditionExpression("attribute_exists(orderId)") .returnValues(ReturnValue.ALL_OLD) .build())) .map(DeleteItemResponse::attributes) .map(this::convert) .orElseThrow(() -> new IllegalStateException( "Condition passed but deleted item was null")); } catch (ConditionalCheckFailedException e) { throw new UnableToDeleteException( "A competing request changed the order while processing this request"); } catch (ResourceNotFoundException e) { throw new TableDoesNotExistException("Order table " + tableName + " does not exist and was deleted after reading the order"); } }
public <T> Optional<T> getValueForField(String fieldName, Class<T> clazz) { switch (fieldName) { case "TableName": return Optional.ofNullable(clazz.cast(tableName())); case "Key": return Optional.ofNullable(clazz.cast(key())); case "Expected": return Optional.ofNullable(clazz.cast(expected())); case "ConditionalOperator": return Optional.ofNullable(clazz.cast(conditionalOperatorAsString())); case "ReturnValues": return Optional.ofNullable(clazz.cast(returnValuesAsString())); case "ReturnConsumedCapacity": return Optional.ofNullable(clazz.cast(returnConsumedCapacityAsString())); case "ReturnItemCollectionMetrics": return Optional.ofNullable(clazz.cast(returnItemCollectionMetricsAsString())); case "ConditionExpression": return Optional.ofNullable(clazz.cast(conditionExpression())); case "ExpressionAttributeNames": return Optional.ofNullable(clazz.cast(expressionAttributeNames())); case "ExpressionAttributeValues": return Optional.ofNullable(clazz.cast(expressionAttributeValues())); default: return Optional.empty(); } }
ItemCollectionSizeLimitExceededException, TransactionConflictException, RequestLimitExceededException, InternalServerErrorException, AwsServiceException, SdkClientException, DynamoDbException { return deleteItem(DeleteItemRequest.builder().applyMutation(deleteItemRequest).build());
/** * {@inheritDoc} */ public void deleteAll() throws DependencyException, InvalidStateException, ProvisionedThroughputException { List<Lease> allLeases = listLeases(); log.warn("Deleting {} items from table {}", allLeases.size(), table); final AWSExceptionManager exceptionManager = createExceptionManager(); for (final Lease lease : allLeases) { DeleteItemRequest deleteRequest = DeleteItemRequest.builder().tableName(table) .key(serializer.getDynamoHashKey(lease)).build(); try { try { dynamoDBClient.deleteItem(deleteRequest).get(); } catch (ExecutionException e) { throw exceptionManager.apply(e.getCause()); } catch (InterruptedException e) { // TODO: check the behavior throw new DependencyException(e); } } catch (DynamoDbException e) { throw convertAndRethrowExceptions("deleteAll", lease.leaseKey(), e); } } }
/** * {@inheritDoc} */ @Override public void deleteLease(@NonNull final Lease lease) throws DependencyException, InvalidStateException, ProvisionedThroughputException { log.debug("Deleting lease with leaseKey {}", lease.leaseKey()); DeleteItemRequest deleteRequest = DeleteItemRequest.builder().tableName(table) .key(serializer.getDynamoHashKey(lease)).build(); final AWSExceptionManager exceptionManager = createExceptionManager(); try { try { dynamoDBClient.deleteItem(deleteRequest).get(); } catch (ExecutionException e) { throw exceptionManager.apply(e.getCause()); } catch (InterruptedException e) { // TODO: Check if this is the correct behavior throw new DependencyException(e); } } catch (DynamoDbException e) { throw convertAndRethrowExceptions("delete", lease.leaseKey(), e); } }
return deleteItem(DeleteItemRequest.builder().applyMutation(deleteItemRequest).build());
/** * {@inheritDoc} */ @Override public void deleteLease(@NonNull final Lease lease) throws DependencyException, InvalidStateException, ProvisionedThroughputException { log.debug("Deleting lease with leaseKey {}", lease.leaseKey()); DeleteItemRequest deleteRequest = DeleteItemRequest.builder().tableName(table) .key(serializer.getDynamoHashKey(lease)).build(); final AWSExceptionManager exceptionManager = createExceptionManager(); try { try { dynamoDBClient.deleteItem(deleteRequest).get(); } catch (ExecutionException e) { throw exceptionManager.apply(e.getCause()); } catch (InterruptedException e) { // TODO: Check if this is the correct behavior throw new DependencyException(e); } } catch (DynamoDbException e) { throw convertAndRethrowExceptions("delete", lease.leaseKey(), e); } }
/** * {@inheritDoc} */ public void deleteAll() throws DependencyException, InvalidStateException, ProvisionedThroughputException { List<Lease> allLeases = listLeases(); log.warn("Deleting {} items from table {}", allLeases.size(), table); final AWSExceptionManager exceptionManager = createExceptionManager(); for (final Lease lease : allLeases) { DeleteItemRequest deleteRequest = DeleteItemRequest.builder().tableName(table) .key(serializer.getDynamoHashKey(lease)).build(); try { try { dynamoDBClient.deleteItem(deleteRequest).get(); } catch (ExecutionException e) { throw exceptionManager.apply(e.getCause()); } catch (InterruptedException e) { // TODO: check the behavior throw new DependencyException(e); } } catch (DynamoDbException e) { throw convertAndRethrowExceptions("deleteAll", lease.leaseKey(), e); } } }
final DeleteItemRequest deleteItemRequest = DeleteItemRequest.builder() .tableName(tableName) .key(key)