当前位置: 首页>>代码示例>>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;未经允许,请勿转载。