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

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

Introduction

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

Prototype

public Attribute(String name, String value) 

Source Link

Document

Constructs a new Attribute object.

Usage

From source file:SimpleDBExample.java

License:Open Source License

public static void main(String[] args) throws Exception {
    /*//from   w  ww.  ja  v  a 2 s.  c  o  m
     * This credentials provider implementation loads your AWS credentials
     * from a properties file at the root of your classpath.
     *
     * Important: Be sure to fill in your AWS access credentials in the
     *            AwsCredentials.properties file before you try to run this
     *            sample.
     * http://aws.amazon.com/security-credentials
     */
    AmazonSimpleDB sdb = new AmazonSimpleDBClient(new ClasspathPropertiesFileCredentialsProvider());
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    sdb.setRegion(usWest2);

    System.out.println("===========================================");
    System.out.println("Getting Started with Amazon SimpleDB");
    System.out.println("===========================================\n");

    try {
        // Create a domain
        String myDomain = "MyStore";
        System.out.println("Creating domain called " + myDomain + ".\n");
        sdb.createDomain(new CreateDomainRequest(myDomain));

        // List domains
        System.out.println("Listing all domains in your account:\n");
        for (String domainName : sdb.listDomains().getDomainNames()) {
            System.out.println("  " + domainName);
        }
        System.out.println();

        // Put data into a domain
        System.out.println("Putting data into " + myDomain + " domain.\n");
        sdb.batchPutAttributes(new BatchPutAttributesRequest(myDomain, createSampleData()));

        // Select data from a domain
        // Notice the use of backticks around the domain name in our select expression.
        String selectExpression = "select * from `" + myDomain + "` where Category = 'Clothes'";
        System.out.println("Selecting: " + selectExpression + "\n");
        SelectRequest selectRequest = new SelectRequest(selectExpression);
        for (Item item : sdb.select(selectRequest).getItems()) {
            System.out.println("  Item");
            System.out.println("    Name: " + item.getName());
            for (Attribute attribute : item.getAttributes()) {
                System.out.println("      Attribute");
                System.out.println("        Name:  " + attribute.getName());
                System.out.println("        Value: " + attribute.getValue());
            }
        }
        System.out.println();

        // Delete values from an attribute
        System.out.println("Deleting Blue attributes in Item_O3.\n");
        Attribute deleteValueAttribute = new Attribute("Color", "Blue");
        sdb.deleteAttributes(
                new DeleteAttributesRequest(myDomain, "Item_03").withAttributes(deleteValueAttribute));

        // Delete an attribute and all of its values
        System.out.println("Deleting attribute Year in Item_O3.\n");
        sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03")
                .withAttributes(new Attribute().withName("Year")));

        // Replace an attribute
        System.out.println("Replacing Size of Item_03 with Medium.\n");
        List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>();
        replaceableAttributes.add(new ReplaceableAttribute("Size", "Medium", true));
        sdb.putAttributes(new PutAttributesRequest(myDomain, "Item_03", replaceableAttributes));

        // Delete an item and all of its attributes
        System.out.println("Deleting Item_03.\n");
        sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03"));

        // Delete a domain
        System.out.println("Deleting " + myDomain + " domain.\n");
        sdb.deleteDomain(new DeleteDomainRequest(myDomain));
    } 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:SimpleDBSample.java

License:Open Source License

public static void main(String[] args) throws Exception {
    /*//  w w w.java 2s . co m
     * Important: Be sure to fill in your AWS access credentials in the
     *            AwsCredentials.properties file before you try to run this
     *            sample.
     * http://aws.amazon.com/security-credentials
     */
    AmazonSimpleDB sdb = new AmazonSimpleDBClient(
            new PropertiesCredentials(SimpleDBSample.class.getResourceAsStream("AwsCredentials.properties")));

    System.out.println("===========================================");
    System.out.println("Getting Started with Amazon SimpleDB");
    System.out.println("===========================================\n");

    try {
        // Create a domain
        String myDomain = "MyStore";
        System.out.println("Creating domain called " + myDomain + ".\n");
        sdb.createDomain(new CreateDomainRequest(myDomain));

        // List domains
        System.out.println("Listing all domains in your account:\n");
        for (String domainName : sdb.listDomains().getDomainNames()) {
            System.out.println("  " + domainName);
        }
        System.out.println();

        // Put data into a domain
        System.out.println("Putting data into " + myDomain + " domain.\n");
        sdb.batchPutAttributes(new BatchPutAttributesRequest(myDomain, createSampleData()));

        // Select data from a domain
        // Notice the use of backticks around the domain name in our select expression.
        String selectExpression = "select * from `" + myDomain + "` where Category = 'Clothes'";
        System.out.println("Selecting: " + selectExpression + "\n");
        SelectRequest selectRequest = new SelectRequest(selectExpression);
        for (Item item : sdb.select(selectRequest).getItems()) {
            System.out.println("  Item");
            System.out.println("    Name: " + item.getName());
            for (Attribute attribute : item.getAttributes()) {
                System.out.println("      Attribute");
                System.out.println("        Name:  " + attribute.getName());
                System.out.println("        Value: " + attribute.getValue());
            }
        }
        System.out.println();

        // Delete values from an attribute
        System.out.println("Deleting Blue attributes in Item_O3.\n");
        Attribute deleteValueAttribute = new Attribute("Color", "Blue");
        sdb.deleteAttributes(
                new DeleteAttributesRequest(myDomain, "Item_03").withAttributes(deleteValueAttribute));

        // Delete an attribute and all of its values
        System.out.println("Deleting attribute Year in Item_O3.\n");
        sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03")
                .withAttributes(new Attribute().withName("Year")));

        // Replace an attribute
        System.out.println("Replacing Size of Item_03 with Medium.\n");
        List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>();
        replaceableAttributes.add(new ReplaceableAttribute("Size", "Medium", true));
        sdb.putAttributes(new PutAttributesRequest(myDomain, "Item_03", replaceableAttributes));

        // Delete an item and all of its attributes
        System.out.println("Deleting Item_03.\n");
        sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03"));

        // Delete a domain
        System.out.println("Deleting " + myDomain + " domain.\n");
        sdb.deleteDomain(new DeleteDomainRequest(myDomain));
    } 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:aws.sample.SimpleDBSample.java

License:Open Source License

public static void main(String[] args) throws Exception {
    /*/*from  w  w w. j a  v  a2s. c  om*/
     * Important: Be sure to fill in your AWS access credentials in the AwsCredentials.properties file before you try to run this sample. http://aws.amazon.com/security-credentials
     */
    AmazonSimpleDB sdb = new AmazonSimpleDBClient(
            new PropertiesCredentials(SimpleDBSample.class.getResourceAsStream("AwsCredentials.properties")));

    System.out.println("===========================================");
    System.out.println("Getting Started with Amazon SimpleDB");
    System.out.println("===========================================\n");

    try {
        // Create a domain
        String myDomain = "MyStore";
        System.out.println("Creating domain called " + myDomain + ".\n");
        sdb.createDomain(new CreateDomainRequest(myDomain));

        // List domains
        System.out.println("Listing all domains in your account:\n");
        for (String domainName : sdb.listDomains().getDomainNames()) {
            System.out.println("  " + domainName);
        }
        System.out.println();

        // Put data into a domain
        System.out.println("Putting data into " + myDomain + " domain.\n");
        sdb.batchPutAttributes(new BatchPutAttributesRequest(myDomain, createSampleData()));

        // Select data from a domain
        // Notice the use of backticks around the domain name in our select expression.
        String selectExpression = "select * from `" + myDomain + "` where Category = 'Clothes'";
        System.out.println("Selecting: " + selectExpression + "\n");
        SelectRequest selectRequest = new SelectRequest(selectExpression);
        for (Item item : sdb.select(selectRequest).getItems()) {
            System.out.println("  Item");
            System.out.println("    Name: " + item.getName());
            for (Attribute attribute : item.getAttributes()) {
                System.out.println("      Attribute");
                System.out.println("        Name:  " + attribute.getName());
                System.out.println("        Value: " + attribute.getValue());
            }
        }
        System.out.println();

        // Delete values from an attribute
        System.out.println("Deleting Blue attributes in Item_O3.\n");
        Attribute deleteValueAttribute = new Attribute("Color", "Blue");
        sdb.deleteAttributes(
                new DeleteAttributesRequest(myDomain, "Item_03").withAttributes(deleteValueAttribute));

        // Delete an attribute and all of its values
        System.out.println("Deleting attribute Year in Item_O3.\n");
        sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03")
                .withAttributes(new Attribute().withName("Year")));

        // Replace an attribute
        System.out.println("Replacing Size of Item_03 with Medium.\n");
        List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>();
        replaceableAttributes.add(new ReplaceableAttribute("Size", "Medium", true));
        sdb.putAttributes(new PutAttributesRequest(myDomain, "Item_03", replaceableAttributes));

        // Delete an item and all of its attributes
        System.out.println("Deleting Item_03.\n");
        sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03"));

        // Delete a domain
        System.out.println("Deleting " + myDomain + " domain.\n");
        sdb.deleteDomain(new DeleteDomainRequest(myDomain));
    } 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:bench.auth.SimpleDBSample.java

License:Open Source License

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

    /*/*from   w  w w.j a  v a2s  .  c  o  m*/
     * Important: Be sure to fill in your AWS access credentials in the
     * AwsCredentials.properties file before you try to run this sample.
     * http://aws.amazon.com/security-credentials
     */

    String home = System.getProperty("user.home");

    String props = home + "/.amazon/AwsCredentials.properties";
    System.out.println("props = " + props);

    URL url = new File(props).toURI().toURL();
    System.out.println("url = " + url);

    final AWSCredentials credentials = new PropertiesCredentials(url.openStream());

    final AmazonSimpleDB sdb = new AmazonSimpleDBClient(credentials);

    System.out.println("===========================================");
    System.out.println("Getting Started with Amazon SimpleDB");
    System.out.println("===========================================\n");

    try {

        // Create a domain
        String domain = "domain-tester";
        System.out.println("Creating domain called " + domain + ".\n");
        sdb.createDomain(new CreateDomainRequest(domain));

        // List domains
        System.out.println("Listing all domains in your account:\n");
        for (String domainName : sdb.listDomains().getDomainNames()) {
            System.out.println("  " + domainName);
        }
        System.out.println();

        // Put data into a domain
        System.out.println("Putting data into " + domain + " domain.\n");
        sdb.batchPutAttributes( //
                new BatchPutAttributesRequest(domain, createSampleData()));

        // Select data from a domain
        // Notice the use of backticks around the domain name in our select
        // expression.
        String selectExpression = //
                "select * from `" + domain + "` where Category = 'Clothes'";

        System.out.println("Selecting: " + selectExpression + "\n");

        SelectRequest selectRequest = new SelectRequest(selectExpression);

        for (Item item : sdb.select(selectRequest).getItems()) {
            System.out.println("  Item");
            System.out.println("    Name: " + item.getName());
            for (Attribute attribute : item.getAttributes()) {
                System.out.println("      Attribute");
                System.out.println("        Name:  " + attribute.getName());
                System.out.println("        Value: " + attribute.getValue());
            }
        }
        System.out.println();

        // Delete values from an attribute
        System.out.println("Deleting Blue attributes in Item_O3.\n");
        Attribute deleteValueAttribute = new Attribute("Color", "Blue");
        sdb.deleteAttributes(
                new DeleteAttributesRequest(domain, "Item_03").withAttributes(deleteValueAttribute));

        // Delete an attribute and all of its values
        System.out.println("Deleting attribute Year in Item_O3.\n");
        sdb.deleteAttributes(new DeleteAttributesRequest(domain, "Item_03")
                .withAttributes(new Attribute().withName("Year")));

        // Replace an attribute
        System.out.println("Replacing Size of Item_03 with Medium.\n");
        List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>();
        replaceableAttributes.add(new ReplaceableAttribute("Size", "Medium", true));
        sdb.putAttributes(new PutAttributesRequest(domain, "Item_03", replaceableAttributes));

        // Delete an item and all of its attributes
        System.out.println("Deleting Item_03.\n");
        sdb.deleteAttributes(new DeleteAttributesRequest(domain, "Item_03"));

        // Delete a domain
        // System.out.println("Deleting " + myDomain + " domain.\n");
        // sdb.deleteDomain(new DeleteDomainRequest(myDomain));

    } 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:c3.ops.priam.aws.SDBInstanceData.java

License:Apache License

protected List<Attribute> createAttributesToDeRegister(PriamInstance instance) {
    List<Attribute> attrs = new ArrayList<Attribute>();
    attrs.add(new Attribute(Attributes.INSTANCE_ID, instance.getInstanceId()));
    attrs.add(new Attribute(Attributes.TOKEN, instance.getToken()));
    attrs.add(new Attribute(Attributes.APP_ID, instance.getApp()));
    attrs.add(new Attribute(Attributes.ID, Integer.toString(instance.getId())));
    attrs.add(new Attribute(Attributes.AVAILABILITY_ZONE, instance.getRac()));
    attrs.add(new Attribute(Attributes.ELASTIC_IP, instance.getHostIP()));
    attrs.add(new Attribute(Attributes.HOSTNAME, instance.getHostName()));
    attrs.add(new Attribute(Attributes.LOCATION, instance.getDC()));
    attrs.add(new Attribute(Attributes.UPDATE_TS, Long.toString(instance.getUpdatetime())));
    return attrs;
}

From source file:com.brighttag.agathon.dao.sdb.SdbCassandraInstanceDao.java

License:Apache License

private static Attribute attribute(String key, String value) {
    return new Attribute(key, value);
}

From source file:com.dateofrock.simpledbmapper.SimpleDBMapper.java

License:Apache License

/**
 * SimpleDB?????/*  w w w  .  j av a2 s  .c  o m*/
 * 
 * @param object
 *            {@link SimpleDBDomain}????POJO
 *            {@link SimpleDBVersionAttribute}
 *            ??????????????<a href=
 *            "http://docs.amazonwebservices.com/AmazonSimpleDB/latest/DeveloperGuide/ConditionalPut.html"
 *            >Conditional Put</a>????
 */
public <T> void save(T object) {
    Class<?> clazz = object.getClass();
    String domainName = getDomainName(clazz);

    Field itemNameField = this.reflector.findItemNameField(clazz);
    if (itemNameField == null) {
        throw new SimpleDBMapperException(object + "@SimpleDBItemName????");
    }

    String itemName = null;
    itemName = this.reflector.encodeItemNameAsSimpleDBFormat(object, itemNameField);

    Set<Field> allFields = this.reflector.listAllFields(clazz);
    Map<String, Object> attributeMap = new HashMap<String, Object>();
    List<S3BlobReference> blobList = new ArrayList<S3BlobReference>();
    for (Field field : allFields) {
        try {
            String attributeName = this.reflector.getAttributeName(field);
            if (attributeName != null) {
                if (this.reflector.isAttributeField(field)) {
                    attributeMap.put(attributeName, field.get(object));
                } else if (this.reflector.isBlobField(field)) {
                    String s3BucketName = this.reflector.getS3BucketName(clazz);
                    String s3KeyPrefix = this.reflector.getS3KeyPrefix(clazz);
                    String s3ContentType = this.reflector.getS3ContentType(field);
                    // FIXME
                    S3BlobReference s3BlobRef = new S3BlobReference(attributeName, s3BucketName, s3KeyPrefix,
                            s3ContentType, field.get(object));
                    blobList.add(s3BlobRef);
                }
            }
        } catch (Exception e) {
            throw new SimpleDBMapperException(e);
        }
    }

    List<String> nullKeys = new ArrayList<String>();
    List<ReplaceableAttribute> replacableAttrs = new ArrayList<ReplaceableAttribute>();

    // SimpleDBAttribute
    for (Map.Entry<String, Object> entry : attributeMap.entrySet()) {
        String sdbAttributeName = entry.getKey();
        Object sdbValue = entry.getValue();
        if (sdbValue == null) {
            nullKeys.add(sdbAttributeName);// ?
        } else if (sdbValue instanceof Set) { // Set
            Set<?> c = (Set<?>) sdbValue;
            for (Object val : c) {
                replacableAttrs.add(new ReplaceableAttribute(sdbAttributeName,
                        this.reflector.encodeObjectAsSimpleDBFormat(val), true));
            }
        } else {
            replacableAttrs.add(new ReplaceableAttribute(sdbAttributeName,
                    this.reflector.encodeObjectAsSimpleDBFormat(sdbValue), true));
        }
    }

    // SimpleDBBlob
    // Upload?Blob?
    List<S3Task> uploadTasks = new ArrayList<S3Task>();
    for (S3BlobReference s3BlobRef : blobList) {
        String bucketName = s3BlobRef.getS3BucketName();
        if (bucketName == null) {
            throw new SimpleDBMapperException("Blob??s3BucketName????");
        }

        StringBuilder s3Key = new StringBuilder();
        String prefix = s3BlobRef.getPrefix();
        if (prefix == null) {
            throw new SimpleDBMapperException("Blob?prefix?null??????");
        }
        prefix = prefix.trim();
        s3Key.append(prefix);
        if (!prefix.isEmpty() && !prefix.endsWith("/")) {
            s3Key.append("/");
        }
        s3Key.append(itemName).append("/").append(s3BlobRef.getAttributeName());

        Object blobObject = s3BlobRef.getObject();
        if (blobObject == null) {
            nullKeys.add(s3BlobRef.getAttributeName());
            // ???Delete Object?
            // FIXME ????????SDB???DeleteAttribute?
            this.s3.deleteObject(bucketName, s3Key.toString());
        } else {
            // ?Blob????S3??????????????????????
            InputStream input = null;
            if (blobObject instanceof String) {
                // Blob?String
                // FIXME encoding???
                input = new ByteArrayInputStream(((String) blobObject).getBytes(Charset.forName("UTF-8")));
            } else if (blobObject.getClass().getSimpleName().equals("byte[]")) {
                // Blob?Byte?
                input = new ByteArrayInputStream((byte[]) blobObject);
            } else {
                throw new SimpleDBMapperException(
                        "Blob?????String????byte[]????");
            }
            S3Task uploadTask = new S3Task(this.s3, s3BlobRef.getAttributeName(), input, bucketName,
                    s3Key.toString(), s3BlobRef.getContentType());
            uploadTasks.add(uploadTask);
        }
    }

    // PutAttribute
    PutAttributesRequest req = new PutAttributesRequest();
    req.setDomainName(domainName);
    req.setItemName(itemName);

    // Version??object???Conditional PUT?
    Long nowVersion = System.currentTimeMillis();
    Field versionField = this.reflector.findVersionAttributeField(clazz);
    if (versionField != null) {
        try {
            Object versionObject = versionField.get(object);
            String versionAttributeName = versionField.getAnnotation(SimpleDBVersionAttribute.class)
                    .attributeName();
            if (versionObject != null) {
                if (versionObject instanceof Long) {
                    Long currentVersion = (Long) versionObject;
                    UpdateCondition expected = new UpdateCondition();
                    expected.setName(versionAttributeName);
                    expected.setValue(currentVersion.toString());
                    req.setExpected(expected);
                } else {
                    throw new SimpleDBMapperException(
                            "version?Long???????" + versionField);
                }
            }

            replacableAttrs.add(new ReplaceableAttribute(versionAttributeName, nowVersion.toString(), true));
        } catch (Exception e) {
            throw new SimpleDBMapperException("object?version??: " + object, e);
        }
    }

    // S3??
    List<S3TaskResult> taskFailures = new ArrayList<S3TaskResult>();
    ExecutorService executor = Executors.newFixedThreadPool(this.config.geS3AccessThreadPoolSize());
    try {
        List<Future<S3TaskResult>> futures = executor.invokeAll(uploadTasks);
        for (Future<S3TaskResult> future : futures) {
            S3TaskResult result = future.get();
            // SimpleDB?????
            replacableAttrs.add(new ReplaceableAttribute(result.getSimpleDBAttributeName(),
                    result.toSimpleDBAttributeValue(), true));
            if (!result.isSuccess()) {
                // Upload
                taskFailures.add(result);
            }
        }
    } catch (Exception e) {
        throw new SimpleDBMapperS3HandleException("S3??", e);
    }

    // UploadTask???
    if (!taskFailures.isEmpty()) {
        throw new SimpleDBMapperS3HandleException(taskFailures);
    }

    // SDB?PUT
    req.setAttributes(replacableAttrs);
    this.sdb.putAttributes(req);

    // version
    if (versionField != null) {
        try {
            versionField.set(object, nowVersion);
        } catch (Exception ignore) {
            throw new SimpleDBMapperException("version??", ignore);
        }
    }

    // DeleteAttribute
    if (!nullKeys.isEmpty()) {
        DeleteAttributesRequest delReq = new DeleteAttributesRequest();
        delReq.setDomainName(domainName);
        delReq.setItemName(itemName);
        Collection<Attribute> delAttrs = new ArrayList<Attribute>(nullKeys.size());
        for (String nullKey : nullKeys) {
            delAttrs.add(new Attribute(nullKey, null));
        }
        delReq.setAttributes(delAttrs);
        this.sdb.deleteAttributes(delReq);
    }

}

From source file:org.apache.camel.component.aws.sdb.AmazonSDBClientMock.java

License:Apache License

@Override
public GetAttributesResult getAttributes(GetAttributesRequest getAttributesRequest)
        throws AmazonServiceException, AmazonClientException {
    this.getAttributesRequest = getAttributesRequest;

    return new GetAttributesResult().withAttributes(new Attribute("AttributeOne", "Value One"))
            .withAttributes(new Attribute("AttributeTwo", "Value Two"));
}

From source file:org.grails.datastore.mapping.simpledb.engine.SimpleDBEntityPersister.java

License:Apache License

@Override
public void updateEntry(final PersistentEntity persistentEntity, final EntityAccess ea, final Object key,
        final SimpleDBNativeItem entry) {

    String id = key.toString();//ww  w .  j  av  a2 s .  c  o  m
    String domain = domainResolver.resolveDomain(id);

    //for non-null values we should call putAttributes, for nulls we should call delete attributes
    List<ReplaceableAttribute> allAttributes = entry.createReplaceableItem().getAttributes();

    List<ReplaceableAttribute> puts = new LinkedList<ReplaceableAttribute>();
    List<Attribute> deletes = new LinkedList<Attribute>();

    //we have to put *new* (incremented) version as part of the 'version' value and use the old version value in the conditional update.
    //if the update fails we have to restore the version to the old value
    Object currentVersion = null;
    String stringCurrentVersion = null;
    if (isVersioned(ea)) {
        currentVersion = ea.getProperty("version");
        stringCurrentVersion = convertVersionToString(currentVersion);
        incrementVersion(ea); //increment version now before we save it
    }

    for (ReplaceableAttribute attribute : allAttributes) {
        if ("version".equals(attribute.getName())) {
            //ignore it, it will be explicitly added later right before the insert by taking incrementing and taking new one
        } else {
            if (attribute.getValue() != null) {
                puts.add(attribute);
            } else {
                deletes.add(new Attribute(attribute.getName(), null));
            }
        }
    }

    if (isVersioned(ea)) {
        puts.add(createAttributeForVersion(ea)); //update the version
        try {
            simpleDBTemplate.deleteAttributesVersioned(domain, id, deletes, stringCurrentVersion,
                    persistentEntity);
            simpleDBTemplate.putAttributesVersioned(domain, id, puts, stringCurrentVersion, persistentEntity);
        } catch (DataAccessException e) {
            //we need to restore version to what it was before the attempt to update
            ea.setProperty("version", currentVersion);
            throw e;
        }
    } else {
        simpleDBTemplate.deleteAttributes(domain, id, deletes);
        simpleDBTemplate.putAttributes(domain, id, puts);
    }
}