Search in sources :

Example 1 with GetAttributesRequest

use of com.amazonaws.services.simpledb.model.GetAttributesRequest in project simplejpa by appoxy.

the class DomainHelper method findItemById.

/**
     * Gets the Item based on the item name field which is the same as id in SimpleJPA.
     * If the item doesn't exist then null is returned.
     * 
     * @param db
     * @param domainName
     * @param itemName
     * @param consistentRead true to read consistently, false to use eventual consistency     
     * @return
     * @throws AmazonClientException
     */
public static Item findItemById(AmazonSimpleDB db, String domainName, String itemName, boolean consistentRead) throws AmazonClientException {
    GetAttributesResult results = db.getAttributes(new GetAttributesRequest().withConsistentRead(consistentRead).withDomainName(domainName).withItemName(itemName));
    if (results.getAttributes().size() == 0) {
        return null;
    }
    Item item = new Item(itemName, results.getAttributes());
    return item;
}
Also used : Item(com.amazonaws.services.simpledb.model.Item) GetAttributesRequest(com.amazonaws.services.simpledb.model.GetAttributesRequest) GetAttributesResult(com.amazonaws.services.simpledb.model.GetAttributesResult)

Example 2 with GetAttributesRequest

use of com.amazonaws.services.simpledb.model.GetAttributesRequest in project simplejpa by appoxy.

the class EntityManagerSimpleJPA method putAndDelete.

private void putAndDelete(String domainName, String oldAttributeName, String newAttributeName, List<Item> items) throws AmazonClientException {
    AmazonSimpleDB db = factory.getSimpleDb();
    for (Item item : items) {
        GetAttributesResult getOldResults = db.getAttributes(new GetAttributesRequest().withDomainName(domainName).withConsistentRead(true).withItemName(item.getName()).withAttributeNames(oldAttributeName));
        List<Attribute> oldAtts = getOldResults.getAttributes();
        if (oldAtts.size() > 0) {
            Attribute oldAtt = oldAtts.get(0);
            List<ReplaceableAttribute> atts = new ArrayList<ReplaceableAttribute>();
            atts.add(new ReplaceableAttribute(newAttributeName, oldAtt.getValue(), true));
            db.putAttributes(new PutAttributesRequest().withDomainName(domainName).withItemName(item.getName()).withAttributes(atts));
            db.deleteAttributes(new DeleteAttributesRequest().withDomainName(domainName).withItemName(item.getName()).withAttributes(oldAtts));
        }
    }
}
Also used : Item(com.amazonaws.services.simpledb.model.Item) Attribute(com.amazonaws.services.simpledb.model.Attribute) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) AmazonSimpleDB(com.amazonaws.services.simpledb.AmazonSimpleDB) PutAttributesRequest(com.amazonaws.services.simpledb.model.PutAttributesRequest) DeleteAttributesRequest(com.amazonaws.services.simpledb.model.DeleteAttributesRequest) GetAttributesRequest(com.amazonaws.services.simpledb.model.GetAttributesRequest) GetAttributesResult(com.amazonaws.services.simpledb.model.GetAttributesResult) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute)

Example 3 with GetAttributesRequest

use of com.amazonaws.services.simpledb.model.GetAttributesRequest in project siena by mandubian.

the class SdbPersistenceManager method getByKey.

public <T> T getByKey(Class<T> clazz, Object key) {
    String domain = SdbMappingUtils.getDomainName(clazz, prefix);
    try {
        checkDomain(domain);
        GetAttributesRequest req = SdbMappingUtils.createGetRequestFromKey(domain, clazz, key);
        // sets consistent read to true when reading one single object
        req.setConsistentRead(isReadConsistent());
        GetAttributesResult res = sdb.getAttributes(req);
        if (res.getAttributes().size() == 0) {
            throw new SienaException(req.getItemName() + " not found in domain " + req.getDomainName());
        }
        T obj = Util.createObjectInstance(clazz);
        SdbMappingUtils.fillModel(req.getItemName(), res, clazz, obj);
        // join management
        if (!ClassInfo.getClassInfo(clazz).joinFields.isEmpty()) {
            mapJoins(obj);
        }
        return obj;
    } catch (AmazonClientException ex) {
        throw new SienaException(ex);
    }
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) GetAttributesRequest(com.amazonaws.services.simpledb.model.GetAttributesRequest) SienaException(siena.SienaException) GetAttributesResult(com.amazonaws.services.simpledb.model.GetAttributesResult)

Example 4 with GetAttributesRequest

use of com.amazonaws.services.simpledb.model.GetAttributesRequest in project siena by mandubian.

the class SdbPersistenceManager method get.

public void get(Object obj) {
    Class<?> clazz = obj.getClass();
    ClassInfo info = ClassInfo.getClassInfo(obj.getClass());
    String domain = SdbMappingUtils.getDomainName(clazz, prefix);
    try {
        checkDomain(domain);
        GetAttributesRequest req = SdbMappingUtils.createGetRequest(domain, clazz, obj);
        // sets consistent read to true when reading one single object
        req.setConsistentRead(isReadConsistent());
        GetAttributesResult res = sdb.getAttributes(req);
        if (res.getAttributes().size() == 0) {
            throw new SienaException(req.getItemName() + " not found in domain " + req.getDomainName());
        }
        SdbMappingUtils.fillModel(req.getItemName(), res, clazz, obj);
        // join management
        if (!info.joinFields.isEmpty()) {
            mapJoins(obj);
        }
    } catch (AmazonClientException ex) {
        throw new SienaException(ex);
    }
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) GetAttributesRequest(com.amazonaws.services.simpledb.model.GetAttributesRequest) SienaException(siena.SienaException) GetAttributesResult(com.amazonaws.services.simpledb.model.GetAttributesResult) ClassInfo(siena.ClassInfo)

Example 5 with GetAttributesRequest

use of com.amazonaws.services.simpledb.model.GetAttributesRequest in project camel by apache.

the class GetAttributesCommand method execute.

public void execute() {
    GetAttributesRequest request = new GetAttributesRequest().withDomainName(determineDomainName()).withItemName(determineItemName()).withConsistentRead(determineConsistentRead()).withAttributeNames(determineAttributeNames());
    log.trace("Sending request [{}] for exchange [{}]...", request, exchange);
    GetAttributesResult result = this.sdbClient.getAttributes(request);
    log.trace("Received result [{}]", result);
    Message msg = getMessageForResponse(exchange);
    msg.setHeader(SdbConstants.ATTRIBUTES, result.getAttributes());
}
Also used : Message(org.apache.camel.Message) GetAttributesRequest(com.amazonaws.services.simpledb.model.GetAttributesRequest) GetAttributesResult(com.amazonaws.services.simpledb.model.GetAttributesResult)

Aggregations

GetAttributesRequest (com.amazonaws.services.simpledb.model.GetAttributesRequest)5 GetAttributesResult (com.amazonaws.services.simpledb.model.GetAttributesResult)5 AmazonClientException (com.amazonaws.AmazonClientException)2 Item (com.amazonaws.services.simpledb.model.Item)2 SienaException (siena.SienaException)2 AmazonSimpleDB (com.amazonaws.services.simpledb.AmazonSimpleDB)1 Attribute (com.amazonaws.services.simpledb.model.Attribute)1 DeleteAttributesRequest (com.amazonaws.services.simpledb.model.DeleteAttributesRequest)1 PutAttributesRequest (com.amazonaws.services.simpledb.model.PutAttributesRequest)1 ReplaceableAttribute (com.amazonaws.services.simpledb.model.ReplaceableAttribute)1 Message (org.apache.camel.Message)1 ClassInfo (siena.ClassInfo)1