當前位置: 首頁>>代碼示例>>Java>>正文


Java AmazonDynamoDB.deleteItem方法代碼示例

本文整理匯總了Java中com.amazonaws.services.dynamodbv2.AmazonDynamoDB.deleteItem方法的典型用法代碼示例。如果您正苦於以下問題:Java AmazonDynamoDB.deleteItem方法的具體用法?Java AmazonDynamoDB.deleteItem怎麽用?Java AmazonDynamoDB.deleteItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.amazonaws.services.dynamodbv2.AmazonDynamoDB的用法示例。


在下文中一共展示了AmazonDynamoDB.deleteItem方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入方法依賴的package包/類
public static void main(String[] args)
{
    final String USAGE = "\n" +
        "Usage:\n" +
        "    DeleteItem <table> <name>\n\n" +
        "Where:\n" +
        "    table - the table to delete the item from.\n" +
        "    name  - the item to delete from the table,\n" +
        "            using the primary key \"Name\"\n\n" +
        "Example:\n" +
        "    DeleteItem HelloTable World\n\n" +
        "**Warning** This program will actually delete the item\n" +
        "            that you specify!\n";

    if (args.length < 2) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String table_name = args[0];
    String name = args[1];

    System.out.format("Deleting item \"%s\" from %s\n", name, table_name);

    HashMap<String,AttributeValue> key_to_get =
        new HashMap<String,AttributeValue>();

    key_to_get.put("Name", new AttributeValue(name));

    final AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();

    try {
        ddb.deleteItem(table_name, key_to_get);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }

    System.out.println("Done!");
}
 
開發者ID:awsdocs,項目名稱:aws-doc-sdk-examples,代碼行數:41,代碼來源:DeleteItem.java

示例2: remove

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入方法依賴的package包/類
@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();
        }
    }
}
 
開發者ID:jcabi,項目名稱:jcabi-dynamo,代碼行數:40,代碼來源:AwsIterator.java

示例3: delete

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入方法依賴的package包/類
@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();
    }
}
 
開發者ID:jcabi,項目名稱:jcabi-dynamo,代碼行數:34,代碼來源:AwsTable.java


注:本文中的com.amazonaws.services.dynamodbv2.AmazonDynamoDB.deleteItem方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。