com.amazonaws.services.dynamodbv2.model.DeleteItemResult Java Examples

The following examples show how to use com.amazonaws.services.dynamodbv2.model.DeleteItemResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DynamoDbDelegate.java    From dynamodb-janusgraph-storage-backend with Apache License 2.0 6 votes vote down vote up
DeleteItemResult deleteItem(final DeleteItemRequest request) throws BackendException {
    setUserAgent(request);
    DeleteItemResult result;
    final int wcu = estimateCapacityUnits(DELETE_ITEM, request.getTableName());
    timedWriteThrottle(DELETE_ITEM, request.getTableName(), wcu);

    final Timer.Context apiTimerContext = getTimerContext(DELETE_ITEM, request.getTableName());
    try {
        result = client.deleteItem(request);
    } catch (Exception e) {
        throw processDynamoDbApiException(e, DELETE_ITEM, request.getTableName());
    } finally {
        apiTimerContext.stop();
    }
    meterConsumedCapacity(DELETE_ITEM, result.getConsumedCapacity());

    return result;
}
 
Example #2
Source File: AmazonDynamoDBStubTest.java    From aws-java-sdk-stubs with Apache License 2.0 6 votes vote down vote up
@Test
public void test_deleteItem_WithAllParameters() throws Exception {
  createTable();
  putItem(TEST_ATTRIBUTE, TEST_ATTRIBUTE_VALUE);

  Map<String, AttributeValue> key = new HashMap<String, AttributeValue>();
  key.put(TEST_ATTRIBUTE, new AttributeValue()
    .withS(TEST_ATTRIBUTE_VALUE));
  String returnValues = "";

  DeleteItemResult deleteResult = dynamoDb.deleteItem(TEST_TABLE_NAME, key, returnValues);
  AttributeValue attributeValue = deleteResult.getAttributes().get(TEST_ATTRIBUTE);

  GetItemResult getResult = getItem(TEST_ATTRIBUTE, TEST_ATTRIBUTE_VALUE);

  assertThat(attributeValue.getS(), equalTo(TEST_ATTRIBUTE_VALUE));
  assertThat(getResult, nullValue());
}
 
Example #3
Source File: DynamoDBManager.java    From dynamodb-geo with Apache License 2.0 6 votes vote down vote up
public DeletePointResult deletePoint(DeletePointRequest deletePointRequest) {
	long geohash = S2Manager.generateGeohash(deletePointRequest.getGeoPoint());
	long hashKey = S2Manager.generateHashKey(geohash, config.getHashKeyLength());

	DeleteItemRequest deleteItemRequest = deletePointRequest.getDeleteItemRequest();

	deleteItemRequest.setTableName(config.getTableName());

	AttributeValue hashKeyValue = new AttributeValue().withN(String.valueOf(hashKey));
	deleteItemRequest.getKey().put(config.getHashKeyAttributeName(), hashKeyValue);
	deleteItemRequest.getKey().put(config.getRangeKeyAttributeName(), deletePointRequest.getRangeKeyValue());

	DeleteItemResult deleteItemResult = config.getDynamoDBClient().deleteItem(deleteItemRequest);
	DeletePointResult deletePointResult = new DeletePointResult(deleteItemResult);

	return deletePointResult;
}
 
Example #4
Source File: TransactionDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 5 votes vote down vote up
@Override
public DeleteItemResult deleteItem(String tableName,
        Map<String, AttributeValue> key, String returnValues)
        throws AmazonServiceException, AmazonClientException {
    return deleteItem(new DeleteItemRequest()
            .withTableName(tableName)
            .withKey(key)
            .withReturnValues(returnValues));
}
 
Example #5
Source File: TransactionDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 5 votes vote down vote up
@Override
public DeleteItemResult deleteItem(String tableName,
        Map<String, AttributeValue> key) throws AmazonServiceException,
        AmazonClientException {
    return deleteItem(new DeleteItemRequest()
            .withTableName(tableName)
            .withKey(key));
}
 
Example #6
Source File: TransactionDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 5 votes vote down vote up
@Override
public DeleteItemResult deleteItem(DeleteItemRequest request)
        throws AmazonServiceException, AmazonClientException {
    Map<String, ExpectedAttributeValue> expectedValues = request.getExpected();
    checkExpectedValues(request.getTableName(), request.getKey(), expectedValues);

    // conditional checks are handled by the above call
    request.setExpected(null);
    return txn.deleteItem(request);
}
 
Example #7
Source File: LowLevelItemCRUDExample.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
private static void deleteItem() {
    try {

        HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>();
        key.put("Id", new AttributeValue().withN("120"));

        Map<String, AttributeValue> expressionAttributeValues = new HashMap<String, AttributeValue>();
        expressionAttributeValues.put(":val", new AttributeValue().withBOOL(false));

        ReturnValue returnValues = ReturnValue.ALL_OLD;

        DeleteItemRequest deleteItemRequest = new DeleteItemRequest().withTableName(tableName).withKey(key)
            .withConditionExpression("InPublication = :val")
            .withExpressionAttributeValues(expressionAttributeValues).withReturnValues(returnValues);

        DeleteItemResult result = client.deleteItem(deleteItemRequest);

        // Check the response.
        System.out.println("Printing item that was deleted...");
        printItem(result.getAttributes());

    }
    catch (AmazonServiceException ase) {
        System.err.println("Failed to get item after deletion " + tableName);
    }

}
 
Example #8
Source File: LowLevelItemCRUDExample.java    From aws-dynamodb-examples with Apache License 2.0 5 votes vote down vote up
private static void deleteItem() {
    try {
        
        HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>();
        key.put("Id", new AttributeValue().withN("120"));

        Map<String, AttributeValue> expressionAttributeValues = new HashMap<String, AttributeValue>();
        expressionAttributeValues.put(":val", new AttributeValue().withBOOL(false)); 
 
        ReturnValue returnValues = ReturnValue.ALL_OLD;

        DeleteItemRequest deleteItemRequest = new DeleteItemRequest()
            .withTableName(tableName)
            .withKey(key)
            .withConditionExpression("InPublication = :val")
            .withExpressionAttributeValues(expressionAttributeValues)
            .withReturnValues(returnValues);

        DeleteItemResult result = client.deleteItem(deleteItemRequest);
        
        // Check the response.
        System.out.println("Printing item that was deleted...");
        printItem(result.getAttributes());            

                                
    } catch (AmazonServiceException ase) {
        System.err.println("Failed to get item after deletion " + tableName);
    } 
    
}
 
Example #9
Source File: Transaction.java    From dynamodb-transactions with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a DeleteItem request to the transaction
 * 
 * @param request
 * @throws DuplicateRequestException if the item in the request is already involved in this transaction
 * @throws ItemNotLockedException when another transaction is confirmed to have the lock on the item in the request
 * @throws TransactionCompletedException when the transaction has already completed
 * @throws TransactionNotFoundException if the transaction does not exist
 * @throws TransactionException on unexpected errors or unresolvable OCC contention
 */
public DeleteItemResult deleteItem(DeleteItemRequest request) 
    throws DuplicateRequestException, ItemNotLockedException, 
        TransactionCompletedException, TransactionNotFoundException, TransactionException {
    
    DeleteItem wrappedRequest = new DeleteItem();
    wrappedRequest.setRequest(request);
    Map<String, AttributeValue> item = driveRequest(wrappedRequest);
    stripSpecialAttributes(item);
    return new DeleteItemResult().withAttributes(item);
}
 
Example #10
Source File: DeletePointResult.java    From dynamodb-geo with Apache License 2.0 4 votes vote down vote up
public DeleteItemResult getDeleteItemResult() {
	return deleteItemResult;
}
 
Example #11
Source File: ThreadLocalDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 4 votes vote down vote up
@Override
public DeleteItemResult deleteItem(String tableName, Map<String, AttributeValue> key, String returnValues) throws AmazonServiceException, AmazonClientException {
    return getBackend().deleteItem(tableName, key, returnValues);
}
 
Example #12
Source File: ThreadLocalDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 4 votes vote down vote up
@Override
public DeleteItemResult deleteItem(String tableName, Map<String, AttributeValue> key) throws AmazonServiceException, AmazonClientException {
    return getBackend().deleteItem(tableName, key);
}
 
Example #13
Source File: ThreadLocalDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 4 votes vote down vote up
@Override
public DeleteItemResult deleteItem(DeleteItemRequest request) throws AmazonServiceException, AmazonClientException {
    return getBackend().deleteItem(request);
}
 
Example #14
Source File: TransactionManagerDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 4 votes vote down vote up
@Override
public DeleteItemResult deleteItem(String tableName,
        Map<String, AttributeValue> key, String returnValues)
        throws AmazonServiceException, AmazonClientException {
    throw new UnsupportedOperationException("Use the underlying client instance instead");
}
 
Example #15
Source File: TransactionManagerDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 4 votes vote down vote up
@Override
public DeleteItemResult deleteItem(String tableName,
        Map<String, AttributeValue> key) throws AmazonServiceException,
        AmazonClientException {
    throw new UnsupportedOperationException("Use the underlying client instance instead");
}
 
Example #16
Source File: TransactionManagerDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 4 votes vote down vote up
@Override
public DeleteItemResult deleteItem(DeleteItemRequest request)
        throws AmazonServiceException, AmazonClientException {
    throw new UnsupportedOperationException("Use the underlying client instance instead");
}
 
Example #17
Source File: DynamoDSETranslatorJSONBlob.java    From dynamo-cassandra-proxy with Apache License 2.0 4 votes vote down vote up
@Override
public DynamoDBResponse deleteItem(DeleteItemRequest dir) {
    logger.debug("delete item into JSON table");
    String tableName = dir.getTableName();
    TableDef tableDef = cassandraManager.getTableDef(tableName);

    PreparedStatement deleteStatement = tableDef.getDeleteStatement();

    AttributeDefinition partitionKeyAttr = tableDef.getPartitionKey();
    Optional<AttributeDefinition> maybeCusteringKeyAttr = tableDef.getClusteringKey();

    Map<String, AttributeValue> keys = dir.getKey();

    Object partitionKeyValue = getAttributeObject(
            ScalarAttributeType.fromValue(partitionKeyAttr.getAttributeType()),
            keys.get(partitionKeyAttr.getAttributeName())
    );

    BoundStatement boundStatement;

    if (maybeCusteringKeyAttr.isPresent())
    {
        Object clusteringKeyValue = getAttributeObject(
                ScalarAttributeType.fromValue(maybeCusteringKeyAttr.get().getAttributeType()),
                keys.get(maybeCusteringKeyAttr.get().getAttributeName())
        );

        boundStatement = deleteStatement.bind(partitionKeyValue, clusteringKeyValue);
    }
    else
    {
        boundStatement = deleteStatement.bind(partitionKeyValue);
    }

    ResultSet result = session().execute(boundStatement);

    if (result.wasApplied()){
        DeleteItemResult dres = new DeleteItemResult();
        return new DynamoDBResponse(dres, 200);
    }
    else return null;

}
 
Example #18
Source File: DeletePointResult.java    From dynamodb-geo with Apache License 2.0 4 votes vote down vote up
public DeletePointResult(DeleteItemResult deleteItemResult) {
	this.deleteItemResult = deleteItemResult;
}
 
Example #19
Source File: DynamoDBReplicationEmitter.java    From dynamodb-cross-region-library with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public List<Record> emit(final UnmodifiableBuffer<Record> buffer) {
    if (isShutdown) {
        if (buffer.getRecords().isEmpty()) {
            // This is OK, but not expected
            log.warn("Record processor called emit after calling shutdown. Continuing becuase buffer is empty.");
            return Collections.emptyList();
        } else {
            throw new IllegalStateException("Cannot emit records after emitter has been shutdown.");
        }
    }
    // Asynchronously process all writes, but block on the results.
    List<Record> records = buffer.getRecords();
    // Stores records that failed with a non-retryable exception
    final List<Record> failedRecords = Collections.synchronizedList(new ArrayList<Record>());
    // Queue of records to submit
    final BlockingQueue<Record> toSubmit = new LinkedBlockingQueue<Record>(records);
    // Used to detect when all requests have either succeeded or resulted in a non-retryable exception
    final CountDownLatch doneSignal = new CountDownLatch(records.size());
    final AtomicInteger retryCount = new AtomicInteger();
    boolean interrupted = false;
    try {
        while (doneSignal.getCount() > 0) {
            Record recordToSubmit = null;
            try {
                recordToSubmit = toSubmit.poll(WAIT_TIME_MS, TimeUnit.MILLISECONDS);
            } catch (InterruptedException e) {
                interrupted = true;
            }
            final Record record = recordToSubmit;
            if (null == record) {
                continue; // Check if all records have completed and if not try to poll again
            }
            // Generate the request based on the record
            AmazonWebServiceRequest request = createRequest(record);
            if (request == null) { // Should only happen if DynamoDB Streams API updates to support different operations
                                   // than {INSERT, MODIFY, REMOVE}.
                continue;
            }
            // Submit the write request based on its type
            if (request instanceof PutItemRequest) { // PUT
                getDynamodb().putItemAsync((PutItemRequest) request,
                    (AsyncHandler<PutItemRequest, PutItemResult>) getHandler(toSubmit, failedRecords, retryCount, doneSignal, record));
            } else if (request instanceof DeleteItemRequest) { // DELETE
                getDynamodb().deleteItemAsync((DeleteItemRequest) request,
                    (AsyncHandler<DeleteItemRequest, DeleteItemResult>) getHandler(toSubmit, failedRecords, retryCount, doneSignal, record));
            } else if (request instanceof UpdateItemRequest) { // UPDATE
                getDynamodb().updateItemAsync((UpdateItemRequest) request,
                    (AsyncHandler<UpdateItemRequest, UpdateItemResult>) getHandler(toSubmit, failedRecords, retryCount, doneSignal, record));
            } else { // Should only happen if DynamoDB allows a new operation other than {PutItem, DeleteItem,
                     // UpdateItem} for single item writes.
                log.warn("Unsupported DynamoDB request: " + request);
            }
        }
    } finally {
        if (interrupted) {
            Thread.currentThread().interrupt();
        }
    }
    emitCloudWatchMetrics(records, failedRecords, retryCount);
    if (!records.isEmpty()) {
        log.debug("Successfully emitted " + (records.size() - failedRecords.size()) + " records ending with sequence number "
            + buffer.getLastSequenceNumber());
    } else {
        log.debug("No records to emit");
    }
    return failedRecords;
}
 
Example #20
Source File: ExponentialBackoff.java    From dynamodb-janusgraph-storage-backend with Apache License 2.0 4 votes vote down vote up
@Override
protected DeleteItemResult call() throws BackendException {
    return delegate.deleteItem(request);
}
 
Example #21
Source File: V1TestDynamoDbDeleteItemClient.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public DeleteItemResult deleteItem(DeleteItemRequest request) {
    bh.consume(request);
    return DELETE_ITEM_RESULT;
}
 
Example #22
Source File: PostgresDynamoDB.java    From podyn with Apache License 2.0 4 votes vote down vote up
@Override
public DeleteItemResult deleteItem(String tableName, Map<String, AttributeValue> key, String returnValues) {
	
	throw new UnsupportedOperationException();
}
 
Example #23
Source File: PostgresDynamoDB.java    From podyn with Apache License 2.0 4 votes vote down vote up
@Override
public DeleteItemResult deleteItem(String tableName, Map<String, AttributeValue> key) {
	
	throw new UnsupportedOperationException();
}
 
Example #24
Source File: PostgresDynamoDB.java    From podyn with Apache License 2.0 4 votes vote down vote up
@Override
public DeleteItemResult deleteItem(DeleteItemRequest deleteItemRequest) {
	
	return null;
}