Example usage for com.amazonaws.services.simpledb AmazonSimpleDB batchDeleteAttributes

List of usage examples for com.amazonaws.services.simpledb AmazonSimpleDB batchDeleteAttributes

Introduction

In this page you can find the example usage for com.amazonaws.services.simpledb AmazonSimpleDB batchDeleteAttributes.

Prototype

BatchDeleteAttributesResult batchDeleteAttributes(BatchDeleteAttributesRequest batchDeleteAttributesRequest);

Source Link

Document

Performs multiple DeleteAttributes operations in a single call, which reduces round trips and latencies.

Usage

From source file:SimpleDBPerformanceSample.java

License:Apache License

public static void main(String[] args) throws Exception {

    AmazonSimpleDB sdb = new AmazonSimpleDBClient(
            new PropertiesCredentials(SimpleDBSample.class.getResourceAsStream("AwsCredentials.properties")));
    // ?[WGh|Cgw//from www.  j a v  a2 s.c om
    sdb.setEndpoint(args[0]);

    int roopCount = 100;
    long insertTimeSum = 0;
    long selectTimeSum = 0;
    long updateTimeSum = 0;
    long deleteTimeSum = 0;
    long startTime;
    long finishedTime;

    try {
        // h?C??
        String myDomain = "MyStore";
        sdb.createDomain(new CreateDomainRequest(myDomain));

        for (int i = 0; i < roopCount; i++) {
            // ?f?[^
            sdb.batchPutAttributes(new BatchPutAttributesRequest(myDomain, createSampleData()));

            // f?[^1?}(PutAttributes API)
            ReplaceableItem rItem = new ReplaceableItem("Item_06").withAttributes(
                    new ReplaceableAttribute("Category", "Car Parts", true),
                    new ReplaceableAttribute("Subcategory", "Exhaust", true),
                    new ReplaceableAttribute("Name", "O2 Sensor", true),
                    new ReplaceableAttribute("Make", "Audi", true),
                    new ReplaceableAttribute("Model", "TT Coupe", true),
                    new ReplaceableAttribute("Year", "2009", true),
                    new ReplaceableAttribute("Year", "2010", true),
                    new ReplaceableAttribute("Year", "2011", true));
            PutAttributesRequest putAttributesRequest = new PutAttributesRequest(myDomain, rItem.getName(),
                    rItem.getAttributes());
            startTime = System.currentTimeMillis();
            sdb.putAttributes(putAttributesRequest);
            finishedTime = System.currentTimeMillis();
            insertTimeSum += finishedTime - startTime;

            // f?[^?iSelect API)
            String selectExpression = "select * from `" + myDomain + "` where Category = 'Clothes'";
            SelectRequest selectRequest = new SelectRequest(selectExpression);
            startTime = System.currentTimeMillis();
            sdb.select(selectRequest);
            finishedTime = System.currentTimeMillis();
            selectTimeSum += finishedTime - startTime;

            // f?[^?X?V(PutAttributes API)
            List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>();
            replaceableAttributes.add(new ReplaceableAttribute("Size", "Medium", true));
            startTime = System.currentTimeMillis();
            sdb.putAttributes(new PutAttributesRequest(myDomain, "Item_03", replaceableAttributes));
            finishedTime = System.currentTimeMillis();
            updateTimeSum += finishedTime - startTime;

            // f?[^??(DeleteAttributes API)
            startTime = System.currentTimeMillis();
            sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03"));
            finishedTime = System.currentTimeMillis();
            deleteTimeSum += finishedTime - startTime;

            // f?[^??
            sdb.batchDeleteAttributes(new BatchDeleteAttributesRequest(myDomain, deleteSampleData()));
        }
        // h?C??
        sdb.deleteDomain(new DeleteDomainRequest(myDomain));

        System.out.println("insert:AVG:" + (float) insertTimeSum / roopCount);
        System.out.println("select:AVG:" + (float) selectTimeSum / roopCount);
        System.out.println("update:AVG:" + (float) updateTimeSum / roopCount);
        System.out.println("delete:AVG:" + (float) deleteTimeSum / roopCount);

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon SimpleDB, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with SimpleDB, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:com.shelfmap.simplequery.DefaultContext.java

License:Apache License

private void doDeleteObjects(Map<Domain<?>, List<DeletableItem>> deleteItems) throws AmazonClientException {
    AmazonSimpleDB sdb = getSimpleDB();
    for (Map.Entry<Domain<?>, List<DeletableItem>> entry : deleteItems.entrySet()) {
        Domain<?> domain = entry.getKey();
        List<DeletableItem> items = entry.getValue();
        BatchDeleteAttributesRequest request = new BatchDeleteAttributesRequest(domain.getDomainName(), items);
        sdb.batchDeleteAttributes(request);
    }// w w  w.  ja  va 2  s  . com
    deleteItems.clear();
}