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; }
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; }
@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; }
@Override public <T extends Message> boolean delete(T item, Modifier... modifiers) throws DataStoreException { DynamoClassMapping<T> tableInfo = getClassMapping(item); log.debug("Delete {}", item); for (Modifier modifier : modifiers) { throw new UnsupportedOperationException(); } DeleteItemRequest request = new DeleteItemRequest(); request.setTableName(tableInfo.getDynamoTableName()); request.setKey(tableInfo.buildCompleteKey(item)); request.setConditionExpression("attribute_exists(hash_key)"); try { DeleteItemResult response = dynamoDB.deleteItem(request); return true; } catch (ConditionalCheckFailedException e) { return false; } }
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; }
/** * Delete. * * @param ticketId the ticket id * @return the boolean */ public boolean delete(final String ticketId) { final TicketDefinition metadata = this.ticketCatalog.find(ticketId); if (metadata != null) { final DeleteItemRequest del = new DeleteItemRequest() .withTableName(metadata.getProperties().getStorageName()) .withKey(Collections.singletonMap(ColumnNames.ID.getName(), new AttributeValue(ticketId))); LOGGER.debug("Submitting delete request [{}] for ticket [{}]", del, ticketId); final DeleteItemResult res = amazonDynamoDBClient.deleteItem(del); LOGGER.debug("Delete request came back with result [{}]", res); return res != null; } return false; }
/** * Delete boolean. * * @param service the service * @return the boolean */ public boolean delete(final RegisteredService service) { final DeleteItemRequest del = new DeleteItemRequest() .withTableName(TABLE_NAME) .withKey(Collections.singletonMap(ColumnNames.ID.getName(), new AttributeValue(String.valueOf(service.getId())))); LOGGER.debug("Submitting delete request [{}] for service [{}]", del, service); final DeleteItemResult res = amazonDynamoDBClient.deleteItem(del); LOGGER.debug("Delete request came back with result [{}]", res); return res != null; }
public CompletableFuture<DeleteItemResult> deleteItem(final DeleteItemRequest deleteItemRequest) { return asyncExecutor.execute(new Callable<DeleteItemResult>() { @Override public DeleteItemResult call() throws Exception { return dbExecutor.deleteItem(deleteItemRequest); } }); }
@Override public void execute() { DeleteItemResult result = ddbClient.deleteItem(new DeleteItemRequest() .withTableName(determineTableName()) .withKey(determineKey()) .withReturnValues(determineReturnValues()) .withExpected(determineUpdateCondition())); addAttributesToResult(result.getAttributes()); }
public static void deleteItem(AmazonDynamoDBClient client, 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); client.deleteItem(deleteItemRequest); }
/** * Deletes the specified username from the identity table. * * @param username * Unique user identifier * @throws DataAccessException */ public void deleteUser(String username) throws DataAccessException { HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>(); key.put(ATTRIBUTE_USERNAME, new AttributeValue().withS(username)); DeleteItemRequest deleteItemRequest = new DeleteItemRequest() .withTableName(USER_TABLE) .withKey(key); try { ddb.deleteItem(deleteItemRequest); } catch (AmazonClientException e) { throw new DataAccessException("Failed to delete user: " + username, e); } }
/** * Deletes the specified UID from the identity table. * * @param uid * Unique device identifier */ public void deleteDevice(String uid) throws DataAccessException { HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>(); key.put(ATTRIBUTE_UID, new AttributeValue().withS(uid)); DeleteItemRequest deleteItemRequest = new DeleteItemRequest() .withTableName(DEVICE_TABLE) .withKey(key); try { ddb.deleteItem(deleteItemRequest); } catch (AmazonClientException e) { throw new DataAccessException("Failed to delete device: " + uid, e); } }
@Override public DeleteItemResult deleteItem(String tableName, HashMap<String, AttributeValue> primaryKey) { DeleteItemRequest deleteItemRequest = new DeleteItemRequest() .withTableName(tableName) .withKey(primaryKey); DeleteItemResult deleteItemResult = dynamoDBClient.deleteItem(deleteItemRequest); LOG.info("Successful by deleting item in " + tableName); return deleteItemResult; }
private void deleteRow(String key, String appid) { if (StringUtils.isBlank(key) || StringUtils.isBlank(appid)) { return; } try { DeleteItemRequest delItemRequest = new DeleteItemRequest(getTableNameForAppid(appid), Collections.singletonMap(Config._KEY, new AttributeValue(getKeyForAppid(key, appid)))); client().deleteItem(delItemRequest); } catch (Exception e) { logger.error("Could not delete row from DB - appid={}, key={}", appid, key, e); } }
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); } }
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); }
/** * Deletes the specified username from the user table. */ public void deleteUser(String username, String table) { HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>(); key.put("username", new AttributeValue().withS(username)); DeleteItemRequest deleteItemRequest = new DeleteItemRequest() .withTableName(table) .withKey(key); ddb.deleteItem(deleteItemRequest); }
@Override @SuppressWarnings("PMD.UseConcurrentHashMap") public void remove() { synchronized (this.dosage) { final AmazonDynamoDB aws = this.credentials.aws(); try { final Dosage prev = this.dosage.get(); final List<Map<String, AttributeValue>> items = new ArrayList<Map<String, AttributeValue>>(prev.items()); final Map<String, AttributeValue> item = items.remove(this.position); final long start = System.currentTimeMillis(); final DeleteItemResult res = aws.deleteItem( new DeleteItemRequest() .withTableName(this.name) .withKey(new Attributes(item).only(this.keys)) .withReturnConsumedCapacity( ReturnConsumedCapacity.TOTAL ) .withExpected( new Attributes(item).only(this.keys).asKeys() ) ); this.dosage.set(new AwsIterator.Fixed(prev, items)); --this.position; Logger.info( this, "#remove(): item #%d removed from DynamoDB, %s, in %[ms]s", this.position, new PrintableConsumedCapacity( res.getConsumedCapacity() ).print(), System.currentTimeMillis() - start ); } finally { aws.shutdown(); } } }
@Override public void delete(final Map<String, AttributeValue> attributes) throws IOException { final AmazonDynamoDB aws = this.credentials.aws(); try { final DeleteItemRequest request = new DeleteItemRequest(); request.setTableName(this.self); request.setKey(attributes); request.setReturnValues(ReturnValue.NONE); request.setReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL); final DeleteItemResult result = aws.deleteItem(request); final long start = System.currentTimeMillis(); Logger.info( this, "#delete('%[text]s'): deleted item in '%s', %s, in %[ms]s", attributes, this.self, new PrintableConsumedCapacity( result.getConsumedCapacity() ).print(), System.currentTimeMillis() - start ); } catch (final AmazonClientException ex) { throw new IOException( String.format( "failed to delete at \"%s\" by keys %s", this.self, attributes ), ex ); } finally { aws.shutdown(); } }
public DeletePointRequest(GeoPoint geoPoint, AttributeValue rangeKeyValue) { deleteItemRequest = new DeleteItemRequest(); deleteItemRequest.setKey(new HashMap<String, AttributeValue>()); this.geoPoint = geoPoint; this.rangeKeyValue = rangeKeyValue; }
public DeleteItemResult deleteItem(final DeleteItemRequest deleteItemRequest) { return dynamoDB.deleteItem(deleteItemRequest); }
@Override public DeleteItemResult deleteItem(DeleteItemRequest deleteItemRequest) { this.deleteItemRequest = deleteItemRequest; return new DeleteItemResult().withAttributes(getAttributes()); }
protected DeleteItemRequest createDeleteItemRequest() { return new DeleteItemRequest() .withTableName(tableName) .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL); }
public DeleteItem(final DeleteItemRequest request, final DynamoDbDelegate delegate) { super(request, delegate, DELETE_ITEM_RETRIES); }
public void removeState(final String streamName, final String applicationName, final String namespace, final String shardId) throws Exception { DeleteItemRequest req = new DeleteItemRequest().withTableName(TABLE_NAME).withKey( getKey(streamName, applicationName, namespace, shardId)); dynamoClient.deleteItem(req); }
/** * AwsTable can delete an item. * @throws Exception If some problem inside */ @Test public void deletesItemFromDynamo() throws Exception { final Credentials credentials = Mockito.mock(Credentials.class); final AmazonDynamoDB aws = Mockito.mock(AmazonDynamoDB.class); Mockito.doReturn(aws).when(credentials).aws(); Mockito.doReturn( new DeleteItemResult().withConsumedCapacity( new ConsumedCapacity().withCapacityUnits(1.0d) ) ).when(aws).deleteItem(Mockito.any(DeleteItemRequest.class)); Mockito.doReturn( new DescribeTableResult().withTable( new TableDescription().withKeySchema( new KeySchemaElement().withAttributeName(AwsTableTest.KEY) ) ) ).when(aws).describeTable(Mockito.any(DescribeTableRequest.class)); final String attr = "attribute-2"; final AttributeValue value = new AttributeValue("value-2"); final String name = "table-name-2"; final Table table = new AwsTable( credentials, Mockito.mock(Region.class), name ); table.delete(new Attributes().with(attr, value)); Mockito.verify(aws).deleteItem( DeleteItemRequest.class.cast( MockitoHamcrest.argThat( Matchers.allOf( Matchers.hasProperty( AwsTableTest.TABLE_NAME, Matchers.equalTo(name) ), Matchers.hasProperty( AwsTableTest.KEY, Matchers.hasEntry( Matchers.equalTo(attr), Matchers.equalTo(value) ) ) ) ) ) ); }
public <T extends Message> List<T> reindex(T instance) throws DataStoreException { DynamoClassMapping<T> tableInfo = getClassMapping(instance); log.debug("reindex {}", instance.getClass().getSimpleName()); ScanRequest scanRequest = new ScanRequest(); scanRequest.setTableName(tableInfo.getDynamoTableName()); // TODO: Filter expressions on prefix? ScanResult scanResponse = dynamoDB.scan(scanRequest); Map<String, AttributeValue> lastEvaluatedKey = scanResponse.getLastEvaluatedKey(); if (lastEvaluatedKey != null) { throw new UnsupportedOperationException("Multiple page results not implemented"); } List<T> items = Lists.newArrayList(); List<Map<String, AttributeValue>> responseItems = scanResponse.getItems(); for (Map<String, AttributeValue> itemData : responseItems) { if (!tableInfo.matchesType(itemData)) { continue; } T item = tableInfo.mapFromDb(itemData); Map<String, AttributeValue> newItemData = tableInfo.mapToDb(item); if (DynamoDbHelpers.areEqual(itemData, newItemData)) { log.debug("No change for item: {}", itemData); continue; } PutItemRequest putRequest = new PutItemRequest(); putRequest.setTableName(tableInfo.getDynamoTableName()); putRequest.setItem(itemData); dynamoDB.putItem(putRequest); Map<String, AttributeValue> oldKey = extractKey(itemData); Map<String, AttributeValue> newKey = extractKey(newItemData); if (!DynamoDbHelpers.areEqual(oldKey, newKey)) { DeleteItemRequest deleteItemRequest = new DeleteItemRequest(); deleteItemRequest.setTableName(tableInfo.getDynamoTableName()); deleteItemRequest.setKey(oldKey); dynamoDB.deleteItem(deleteItemRequest); } } return items; }
public DeleteItemRequest getDeleteItemRequest() { return deleteItemRequest; }