com.amazonaws.services.dynamodbv2.model.DeleteItemRequest Java Examples
The following examples show how to use
com.amazonaws.services.dynamodbv2.model.DeleteItemRequest.
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: SingleUpdateWithCleanupWorker.java From dynamodb-janusgraph-storage-backend with Apache License 2.0 | 6 votes |
@Override public Void call() throws BackendException { final UpdateItem updateBackoff = new UpdateItem(updateItemRequest, dynamoDbDelegate); final UpdateItemResult result = updateBackoff.runWithBackoff(); final Map<String, AttributeValue> item = result.getAttributes(); if (item == null) { // bail return null; } // If the record has no Titan columns left after deletions occur, then just delete the record if (item.containsKey(Constants.JANUSGRAPH_HASH_KEY) && item.size() == ATTRIBUTES_IN_EMPTY_SINGLE_ITEM) { final DeleteItem deleteBackoff = new DeleteItem(new DeleteItemRequest().withTableName(updateItemRequest.getTableName()) .withKey(updateItemRequest.getKey()), dynamoDbDelegate); deleteBackoff.runWithBackoff(); } // void return null; }
Example #2
Source File: DynamoDBManager.java From dynamodb-geo with Apache License 2.0 | 6 votes |
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 #3
Source File: TransactionsIntegrationTest.java From dynamodb-transactions with Apache License 2.0 | 6 votes |
@Test public void getItemWithDelete() { Transaction t1 = manager.newTransaction(); Map<String, AttributeValue> getResult1 = t1.getItem(new GetItemRequest().withTableName(INTEG_HASH_TABLE_NAME).withKey(key0)).getItem(); assertEquals(getResult1, item0); assertItemLocked(INTEG_HASH_TABLE_NAME, key0, item0, t1.getId(), false, false); t1.deleteItem(new DeleteItemRequest().withTableName(INTEG_HASH_TABLE_NAME).withKey(key0)); assertItemLocked(INTEG_HASH_TABLE_NAME, key0, item0, t1.getId(), false, false); Map<String, AttributeValue> getResult2 = t1.getItem(new GetItemRequest().withTableName(INTEG_HASH_TABLE_NAME).withKey(key0)).getItem(); assertNull(getResult2); assertItemLocked(INTEG_HASH_TABLE_NAME, key0, item0, t1.getId(), false, false); t1.commit(); }
Example #4
Source File: TransactionsIntegrationTest.java From dynamodb-transactions with Apache License 2.0 | 6 votes |
@Test public void getItemUncommittedDeleted() { Transaction t1 = manager.newTransaction(); t1.deleteItem(new DeleteItemRequest() .withTableName(INTEG_HASH_TABLE_NAME) .withKey(key0)); assertItemLocked(INTEG_HASH_TABLE_NAME, key0, item0, t1.getId(), false, false); Map<String, AttributeValue> item = manager.getItem(new GetItemRequest() .withTableName(INTEG_HASH_TABLE_NAME) .withKey(key0), IsolationLevel.UNCOMMITTED).getItem(); assertNoSpecialAttributes(item); assertEquals(item0, item); assertItemLocked(INTEG_HASH_TABLE_NAME, key0, item0, t1.getId(), false, false); t1.rollback(); }
Example #5
Source File: TransactionsIntegrationTest.java From dynamodb-transactions with Apache License 2.0 | 6 votes |
@Test public void getItemCommittedDeleted() { Transaction t1 = manager.newTransaction(); t1.deleteItem(new DeleteItemRequest() .withTableName(INTEG_HASH_TABLE_NAME) .withKey(key0)); assertItemLocked(INTEG_HASH_TABLE_NAME, key0, item0, t1.getId(), false, false); Map<String, AttributeValue> item = manager.getItem(new GetItemRequest() .withTableName(INTEG_HASH_TABLE_NAME) .withKey(key0), IsolationLevel.COMMITTED).getItem(); assertNoSpecialAttributes(item); assertEquals(item0, item); assertItemLocked(INTEG_HASH_TABLE_NAME, key0, item0, t1.getId(), false, false); t1.rollback(); }
Example #6
Source File: TransactionsIntegrationTest.java From dynamodb-transactions with Apache License 2.0 | 6 votes |
@Test public void deleteItemAllOldNotExists() { Transaction t1 = manager.newTransaction(); Map<String, AttributeValue> key1 = newKey(INTEG_HASH_TABLE_NAME); Map<String, AttributeValue> result1 = t1.deleteItem(new DeleteItemRequest() .withTableName(INTEG_HASH_TABLE_NAME) .withKey(key1) .withReturnValues(ReturnValue.ALL_OLD)).getAttributes(); assertItemLocked(INTEG_HASH_TABLE_NAME, key1, key1, t1.getId(), true, false); assertNull(result1); t1.commit(); assertItemNotLocked(INTEG_HASH_TABLE_NAME, key1, false); }
Example #7
Source File: DynamoDBReplicationEmitterTestsBase.java From dynamodb-cross-region-library with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") @Test public void removeTest() throws Exception { // Set up the buffer and do sanity checks buffer.clear(); buffer.consumeRecord(ITEM1_REMOVE, ITEM1_REMOVE.getDynamodb().getSizeBytes().intValue(), ITEM1_REMOVE.getDynamodb().getSequenceNumber()); assertEquals(ITEM1_REMOVE.getDynamodb().getSequenceNumber(), buffer.getFirstSequenceNumber()); assertEquals(ITEM1_REMOVE.getDynamodb().getSequenceNumber(), buffer.getLastSequenceNumber()); List<Record> buffered = buffer.getRecords(); assertEquals(1, buffered.size()); assertTrue(buffered.contains(ITEM1_REMOVE)); // Emit record resetAll(DYNAMODB); DYNAMODB.deleteItemAsync(anyObject(DeleteItemRequest.class), anyObject(AsyncHandler.class)); expectLastCall().andAnswer(SUCCESS_ANSWER); expectNew(AmazonDynamoDBAsyncClient.class, new Class<?>[] {AWSCredentialsProvider.class, ClientConfiguration.class, ExecutorService.class}, anyObject(AWSCredentialsProvider.class), anyObject(ClientConfiguration.class), anyObject(ExecutorService.class)).andReturn(DYNAMODB); DYNAMODB.setEndpoint(EasyMock.anyString()); EasyMock.expectLastCall().anyTimes(); replayAll(DYNAMODB); IEmitter<Record> instance = createEmitterInstance(); assertTrue(instance.emit(new UnmodifiableBuffer<Record>(buffer)).isEmpty()); verifyAll(); }
Example #8
Source File: DynamoDBReplicationEmitter.java From dynamodb-cross-region-library with Apache License 2.0 | 6 votes |
/** * Creates a DynamoDB write request based on the DynamoDB Stream record. * * @param record * The DynamoDB Stream record containing information about the update to a DynamoDB table * @return A DynamoDB request based on the DynamoDB Stream record */ private AmazonWebServiceRequest createRequest(final Record record) { final String eventName = record.getEventName(); final AmazonWebServiceRequest request; if (eventName.equalsIgnoreCase(OperationType.INSERT.toString()) || eventName.equalsIgnoreCase(OperationType.MODIFY.toString())) { // For INSERT or MODIFY: Put the new image in the DynamoDB table PutItemRequest putItemRequest = new PutItemRequest(); putItemRequest.setItem(record.getDynamodb().getNewImage()); putItemRequest.setTableName(getTableName()); request = putItemRequest; } else if (eventName.equalsIgnoreCase(OperationType.REMOVE.toString())) { // For REMOVE: Delete the item from the DynamoDB table DeleteItemRequest deleteItemRequest = new DeleteItemRequest(); deleteItemRequest.setKey(record.getDynamodb().getKeys()); deleteItemRequest.setTableName(getTableName()); request = deleteItemRequest; } else { // This should only happen if DynamoDB Streams adds/changes its operation types log.warn("Unsupported operation type detected: " + eventName + ". Record: " + record); request = null; } if (null != request) { request.getRequestClientOptions().appendUserAgent(USER_AGENT); } return request; }
Example #9
Source File: DynamoDbStore.java From dynamodb-janusgraph-storage-backend with Apache License 2.0 | 6 votes |
private Collection<MutateWorker> createWorkersForDeletions(final StaticBuffer hashKey, final List<StaticBuffer> deletions, final DynamoDbStoreTransaction txh) { final List<MutateWorker> workers = new LinkedList<>(); for (StaticBuffer rangeKey : deletions) { final Map<String, AttributeValue> keys = new ItemBuilder().hashKey(hashKey) .rangeKey(rangeKey) .build(); final Expression updateExpression = new MultiUpdateExpressionBuilder(this, txh).hashKey(hashKey) .rangeKey(rangeKey) .build(); final DeleteItemRequest request = super.createDeleteItemRequest().withKey(keys) .withConditionExpression(updateExpression.getConditionExpression()) .withExpressionAttributeValues(updateExpression.getAttributeValues()); workers.add(new DeleteItemWorker(request, client.getDelegate())); } return workers; }
Example #10
Source File: DynamoDbDelegate.java From dynamodb-janusgraph-storage-backend with Apache License 2.0 | 6 votes |
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 #11
Source File: Transaction.java From dynamodb-transactions with Apache License 2.0 | 5 votes |
/** * 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 #12
Source File: Transaction.java From dynamodb-transactions with Apache License 2.0 | 5 votes |
/** * Releases the lock for the item. If the item was inserted only to acquire the lock (if the item didn't exist before * for a DeleteItem or LockItem), it will be deleted now. * * Otherwise, all of the attributes uses for the transaction (tx id, transient flag, applied flag) will be removed. * * Conditions on our transaction id owning the item * * To be used once the transaction has committed only. * @param request */ protected void unlockItemAfterCommit(Request request) { try { Map<String, ExpectedAttributeValue> expected = new HashMap<String, ExpectedAttributeValue>(); expected.put(AttributeName.TXID.toString(), new ExpectedAttributeValue().withValue(new AttributeValue(txId))); if(request instanceof PutItem || request instanceof UpdateItem) { Map<String, AttributeValueUpdate> updates = new HashMap<String, AttributeValueUpdate>(); updates.put(AttributeName.TXID.toString(), new AttributeValueUpdate().withAction(AttributeAction.DELETE)); updates.put(AttributeName.TRANSIENT.toString(), new AttributeValueUpdate().withAction(AttributeAction.DELETE)); updates.put(AttributeName.APPLIED.toString(), new AttributeValueUpdate().withAction(AttributeAction.DELETE)); updates.put(AttributeName.DATE.toString(), new AttributeValueUpdate().withAction(AttributeAction.DELETE)); UpdateItemRequest update = new UpdateItemRequest() .withTableName(request.getTableName()) .withKey(request.getKey(txManager)) .withAttributeUpdates(updates) .withExpected(expected); txManager.getClient().updateItem(update); } else if(request instanceof DeleteItem) { DeleteItemRequest delete = new DeleteItemRequest() .withTableName(request.getTableName()) .withKey(request.getKey(txManager)) .withExpected(expected); txManager.getClient().deleteItem(delete); } else if(request instanceof GetItem) { releaseReadLock(request.getTableName(), request.getKey(txManager)); } else { throw new TransactionAssertionException(txId, "Unknown request type: " + request.getClass()); } } catch (ConditionalCheckFailedException e) { // ignore, unlock already happened // TODO if we really want to be paranoid we could condition on applied = 1, and then here // we would have to read the item again and make sure that applied was 1 if we owned the lock (and assert otherwise) } }
Example #13
Source File: Transaction.java From dynamodb-transactions with Apache License 2.0 | 5 votes |
protected static void releaseReadLock(String txId, TransactionManager txManager, String tableName, Map<String, AttributeValue> key) { Map<String, ExpectedAttributeValue> expected = new HashMap<String, ExpectedAttributeValue>(); expected.put(AttributeName.TXID.toString(), new ExpectedAttributeValue().withValue(new AttributeValue(txId))); expected.put(AttributeName.TRANSIENT.toString(), new ExpectedAttributeValue().withExists(false)); expected.put(AttributeName.APPLIED.toString(), new ExpectedAttributeValue().withExists(false)); try { Map<String, AttributeValueUpdate> updates = new HashMap<String, AttributeValueUpdate>(1); updates.put(AttributeName.TXID.toString(), new AttributeValueUpdate().withAction(AttributeAction.DELETE)); updates.put(AttributeName.DATE.toString(), new AttributeValueUpdate().withAction(AttributeAction.DELETE)); UpdateItemRequest update = new UpdateItemRequest() .withTableName(tableName) .withAttributeUpdates(updates) .withKey(key) .withExpected(expected); txManager.getClient().updateItem(update); } catch (ConditionalCheckFailedException e) { try { expected.put(AttributeName.TRANSIENT.toString(), new ExpectedAttributeValue().withValue(new AttributeValue().withS(BOOLEAN_TRUE_ATTR_VAL))); DeleteItemRequest delete = new DeleteItemRequest() .withTableName(tableName) .withKey(key) .withExpected(expected); txManager.getClient().deleteItem(delete); } catch (ConditionalCheckFailedException e1) { // Ignore, means it was definitely rolled back // Re-read to ensure that it wasn't applied Map<String, AttributeValue> item = getItem(txManager, tableName, key); txAssert(! (item != null && txId.equals(getOwner(item)) && item.containsKey(AttributeName.APPLIED.toString())), "Item should not have been applied. Unable to release lock", "item", item); } } }
Example #14
Source File: StreamsRecordProcessor.java From dynamo-cassandra-proxy with Apache License 2.0 | 5 votes |
@Override public void processRecords(ProcessRecordsInput processRecordsInput) { for (Record record : processRecordsInput.getRecords()) { String data = new String(record.getData().array(), Charset.forName("UTF-8")); System.out.println(data); if (record instanceof RecordAdapter) { com.amazonaws.services.dynamodbv2.model.Record streamRecord = ((RecordAdapter) record) .getInternalObject(); switch (streamRecord.getEventName()) { case "INSERT": case "MODIFY": Map<String, AttributeValue> items = streamRecord.getDynamodb().getNewImage(); PutItemRequest putItemRequest = new PutItemRequest().withTableName(tableName).withItem(items); dynamoDBClient.putItem(putItemRequest); break; case "REMOVE": Map<String, AttributeValue> keys = streamRecord.getDynamodb().getKeys(); DeleteItemRequest deleteItemRequest = new DeleteItemRequest().withTableName(tableName).withKey(keys); dynamoDBClient.deleteItem(deleteItemRequest); } } checkpointCounter += 1; if (checkpointCounter % 10 == 0) { try { processRecordsInput.getCheckpointer().checkpoint(); } catch (Exception e) { e.printStackTrace(); } } } }
Example #15
Source File: TransactionItem.java From dynamodb-transactions with Apache License 2.0 | 5 votes |
/** * Deletes the old version of the item. Item images are immutable - it's just create + delete, so there is no need for * concurrent modification checks. * * @param rid */ public void deleteItemImage(int rid) { txAssert(rid > 0, txId, "Expected rid > 0"); Map<String, AttributeValue> key = new HashMap<String, AttributeValue>(1); key.put(AttributeName.IMAGE_ID.toString(), new AttributeValue(txId + "#" + rid)); txManager.getClient().deleteItem(new DeleteItemRequest() .withTableName(txManager.getItemImageTableName()) .withKey(key)); }
Example #16
Source File: TransactionsIntegrationTest.java From dynamodb-transactions with Apache License 2.0 | 5 votes |
@Test public void deleteItemAllOldExists() { Transaction t1 = manager.newTransaction(); Map<String, AttributeValue> result1 = t1.deleteItem(new DeleteItemRequest() .withTableName(INTEG_HASH_TABLE_NAME) .withKey(key0) .withReturnValues(ReturnValue.ALL_OLD)).getAttributes(); assertItemLocked(INTEG_HASH_TABLE_NAME, key0, item0, t1.getId(), false, false); assertEquals(item0, result1); t1.commit(); assertItemNotLocked(INTEG_HASH_TABLE_NAME, key0, false); }
Example #17
Source File: TransactionItem.java From dynamodb-transactions with Apache License 2.0 | 5 votes |
/** * Deletes the tx item, only if it was in the "finalized" state. * * @throws ConditionalCheckFailedException if the item does not exist or is not finalized */ public void delete() throws ConditionalCheckFailedException { Map<String, ExpectedAttributeValue> expected = new HashMap<String, ExpectedAttributeValue>(1); expected.put(AttributeName.FINALIZED.toString(), new ExpectedAttributeValue().withValue(new AttributeValue(Transaction.BOOLEAN_TRUE_ATTR_VAL))); DeleteItemRequest completeRequest = new DeleteItemRequest() .withTableName(txManager.getTransactionTableName()) .withKey(txKey) .withExpected(expected); txManager.getClient().deleteItem(completeRequest); }
Example #18
Source File: TransactionDynamoDBFacade.java From dynamodb-transactions with Apache License 2.0 | 5 votes |
@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 #19
Source File: TransactionDynamoDBFacade.java From dynamodb-transactions with Apache License 2.0 | 5 votes |
@Override public DeleteItemResult deleteItem(String tableName, Map<String, AttributeValue> key) throws AmazonServiceException, AmazonClientException { return deleteItem(new DeleteItemRequest() .withTableName(tableName) .withKey(key)); }
Example #20
Source File: TransactionDynamoDBFacade.java From dynamodb-transactions with Apache License 2.0 | 5 votes |
@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 #21
Source File: RequestTest.java From dynamodb-transactions with Apache License 2.0 | 5 votes |
@Test public void validDelete() { DeleteItem r = new DeleteItem(); Map<String, AttributeValue> item = new HashMap<String, AttributeValue>(); item.put(HASH_ATTR_NAME, new AttributeValue("a")); r.setRequest(new DeleteItemRequest() .withTableName(TABLE_NAME) .withKey(item)); r.validate("1", new MockTransactionManager(HASH_SCHEMA)); }
Example #22
Source File: TransactionsIntegrationTest.java From dynamodb-transactions with Apache License 2.0 | 5 votes |
@Test public void lockItem() { Map<String, AttributeValue> key1 = newKey(INTEG_HASH_TABLE_NAME); Transaction t1 = manager.newTransaction(); Transaction t2 = manager.newTransaction(); DeleteItemRequest deleteRequest = new DeleteItemRequest() .withTableName(INTEG_HASH_TABLE_NAME) .withKey(key1); GetItemRequest lockRequest = new GetItemRequest() .withTableName(INTEG_HASH_TABLE_NAME) .withKey(key1); Map<String, AttributeValue> getResult = t1.getItem(lockRequest).getItem(); assertItemLocked(INTEG_HASH_TABLE_NAME, key1, t1.getId(), true, false); // we're not applying locks assertNull(getResult); Map<String, AttributeValue> deleteResult = t2.deleteItem(deleteRequest).getAttributes(); assertItemLocked(INTEG_HASH_TABLE_NAME, key1, t2.getId(), true, false); // we're not applying deletes either assertNull(deleteResult); // return values is null in the request t2.commit(); try { t1.commit(); fail(); } catch (TransactionRolledBackException e) { } t1.delete(Long.MAX_VALUE); t2.delete(Long.MAX_VALUE); assertItemNotLocked(INTEG_HASH_TABLE_NAME, key1, false); }
Example #23
Source File: TransactionsIntegrationTest.java From dynamodb-transactions with Apache License 2.0 | 5 votes |
@Test public void phantomItemFromDelete() { Map<String, AttributeValue> key1 = newKey(INTEG_HASH_TABLE_NAME); Transaction transaction = manager.newTransaction(); DeleteItemRequest deleteRequest = new DeleteItemRequest() .withTableName(INTEG_HASH_TABLE_NAME) .withKey(key1); transaction.deleteItem(deleteRequest); assertItemLocked(INTEG_HASH_TABLE_NAME, key1, transaction.getId(), true, false); transaction.rollback(); assertItemNotLocked(INTEG_HASH_TABLE_NAME, key1, false); transaction.delete(Long.MAX_VALUE); }
Example #24
Source File: TransactionsIntegrationTest.java From dynamodb-transactions with Apache License 2.0 | 5 votes |
@After public void teardown() { dynamodb.reset(); Transaction t = manager.newTransaction(); t.deleteItem(new DeleteItemRequest().withTableName(INTEG_HASH_TABLE_NAME).withKey(key0)); t.commit(); assertItemNotLocked(INTEG_HASH_TABLE_NAME, key0, false); }
Example #25
Source File: MapperTransactionsIntegrationTest.java From dynamodb-transactions with Apache License 2.0 | 5 votes |
@After public void teardown() { Transaction t = manager.newTransaction(); t.deleteItem(new DeleteItemRequest().withTableName(INTEG_HASH_TABLE_NAME).withKey(key0)); t.commit(); assertItemNotLocked(INTEG_HASH_TABLE_NAME, key0, false); }
Example #26
Source File: RequestTest.java From dynamodb-transactions with Apache License 2.0 | 5 votes |
private void invalidRequestTest(DeleteItemRequest request, String expectedExceptionMessage) { DeleteItem r = new DeleteItem(); r.setRequest(request); try { r.validate("1", new MockTransactionManager(HASH_SCHEMA)); fail(); } catch (InvalidRequestException e) { assertTrue(e.getMessage().contains(expectedExceptionMessage)); } }
Example #27
Source File: DeletePointRequest.java From dynamodb-geo with Apache License 2.0 | 5 votes |
public DeletePointRequest(GeoPoint geoPoint, AttributeValue rangeKeyValue) { deleteItemRequest = new DeleteItemRequest(); deleteItemRequest.setKey(new HashMap<String, AttributeValue>()); this.geoPoint = geoPoint; this.rangeKeyValue = rangeKeyValue; }
Example #28
Source File: LowLevelItemCRUDExample.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
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 #29
Source File: LowLevelItemBinaryExample.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static void deleteItem(String threadId, String replyDateTime) { HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>(); key.put("Id", new AttributeValue().withS(threadId)); key.put("ReplyDateTime", new AttributeValue().withS(replyDateTime)); DeleteItemRequest deleteReplyRequest = new DeleteItemRequest().withTableName(tableName).withKey(key); client.deleteItem(deleteReplyRequest); }
Example #30
Source File: StreamsAdapterDemoHelper.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static void deleteItem(AmazonDynamoDB dynamoDBClient, String tableName, String id) { java.util.Map<String, AttributeValue> key = new HashMap<String, AttributeValue>(); key.put("Id", new AttributeValue().withN(id)); DeleteItemRequest deleteItemRequest = new DeleteItemRequest().withTableName(tableName).withKey(key); dynamoDBClient.deleteItem(deleteItemRequest); }