Example usage for com.amazonaws.services.simpledb.model BatchDeleteAttributesRequest BatchDeleteAttributesRequest

List of usage examples for com.amazonaws.services.simpledb.model BatchDeleteAttributesRequest BatchDeleteAttributesRequest

Introduction

In this page you can find the example usage for com.amazonaws.services.simpledb.model BatchDeleteAttributesRequest BatchDeleteAttributesRequest.

Prototype

public BatchDeleteAttributesRequest(String domainName, java.util.List<DeletableItem> items) 

Source Link

Document

Constructs a new BatchDeleteAttributesRequest object.

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  w  w w.  j  a  va 2s  .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();/*from  w  w w .  j a  v  a 2  s .  c  o  m*/
    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);
    }
    deleteItems.clear();
}

From source file:org.teiid.resource.adapter.simpledb.SimpleDBConnectionImpl.java

License:Open Source License

/**
 * Removes item with given ItemName from domain
 * @param domainName//from   w  w  w . ja v  a  2 s  .  com
 * @param itemName
 */
@Override
public int performDelete(String domainName, String selectExpression) throws TranslatorException {
    try {
        List<DeletableItem> deleteItems = new ArrayList<DeletableItem>();
        int count = 0;
        String nextToken = null;
        do {
            SelectResult result = performSelect(selectExpression, nextToken);
            nextToken = result.getNextToken();
            Iterator<Item> iter = result.getItems().iterator();
            while (iter.hasNext()) {
                Item item = iter.next();
                deleteItems.add(new DeletableItem(item.getName(), null));
                count++;
                if (count % 25 == 0) {
                    BatchDeleteAttributesRequest request = new BatchDeleteAttributesRequest(domainName,
                            deleteItems);
                    this.client.batchDeleteAttributes(request);
                    deleteItems.clear();
                }
            }
            // http://docs.aws.amazon.com/AmazonSimpleDB/latest/DeveloperGuide/SDB_API_BatchDeleteAttributes.html
            // 25 limit we may need to batch; but if batch atomicity is gone
            if (!deleteItems.isEmpty()) {
                BatchDeleteAttributesRequest request = new BatchDeleteAttributesRequest(domainName,
                        deleteItems);
                this.client.batchDeleteAttributes(request);
            }
        } while (nextToken != null);
        return count;
    } catch (AmazonServiceException e) {
        throw new TranslatorException(e);
    } catch (AmazonClientException e) {
        throw new TranslatorException(e);
    }
}

From source file:siena.sdb.SdbPersistenceManager.java

License:Apache License

@Override
public int delete(Iterable<?> models) {
    Map<String, List<DeletableItem>> doMap = new HashMap<String, List<DeletableItem>>();
    int nb = 0;/*w  ww.  j  av  a2s  .  c  o m*/
    for (Object obj : models) {
        Class<?> clazz = obj.getClass();
        String domain = SdbMappingUtils.getDomainName(clazz, prefix);
        List<DeletableItem> doList = doMap.get(domain);
        if (doList == null) {
            doList = new ArrayList<DeletableItem>();
            doMap.put(domain, doList);
        }
        doList.add(SdbMappingUtils.createDeletableItem(obj));

        nb++;
    }
    try {
        for (String domain : doMap.keySet()) {
            checkDomain(domain);
            List<DeletableItem> doList = doMap.get(domain);
            int len = doList.size() > MAX_ITEMS_PER_CALL ? MAX_ITEMS_PER_CALL : doList.size();
            for (int i = 0; i < doList.size(); i += len) {
                int sz = i + len;
                if (sz > doList.size()) {
                    sz = doList.size();
                }
                sdb.batchDeleteAttributes(new BatchDeleteAttributesRequest(domain, doList.subList(i, sz)));

            }
        }
    } catch (AmazonClientException ex) {
        throw new SienaException(ex);
    }
    return nb;
}

From source file:siena.sdb.SdbPersistenceManager.java

License:Apache License

@Override
public <T> int deleteByKeys(Class<T> clazz, Iterable<?> keys) {
    List<DeletableItem> doList = new ArrayList<DeletableItem>();
    int nb = 0;//from   w w  w . java2  s  .co  m
    String domain = SdbMappingUtils.getDomainName(clazz, prefix);
    for (Object key : keys) {
        doList.add(SdbMappingUtils.createDeletableItemFromKey(clazz, key));
        nb++;
    }
    try {
        checkDomain(domain);
        int len = doList.size() > MAX_ITEMS_PER_CALL ? MAX_ITEMS_PER_CALL : doList.size();
        for (int i = 0; i < doList.size(); i += len) {
            int sz = i + len;
            if (sz > doList.size()) {
                sz = doList.size();
            }
            sdb.batchDeleteAttributes(new BatchDeleteAttributesRequest(domain, doList.subList(i, sz)));
        }
    } catch (AmazonClientException ex) {
        throw new SienaException(ex);
    }
    return nb;
}

From source file:wwutil.jsoda.SimpleDBService.java

License:Mozilla Public License

public void batchDelete(String modelName, List idList, List rangeKeyList) throws Exception {
    String table = jsoda.getModelTable(modelName);
    List<DeletableItem> items = new ArrayList<DeletableItem>();
    for (int i = 0; i < idList.size(); i++) {
        String idValue = makeIdValue(modelName, idList.get(i),
                rangeKeyList == null ? null : rangeKeyList.get(i));
        items.add(new DeletableItem().withName(idValue));
    }/*from w w  w.jav a2s .co  m*/
    sdbClient.batchDeleteAttributes(new BatchDeleteAttributesRequest(table, items));
}