use of com.amazonaws.services.simpledb.model.GetAttributesResult 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;
}
use of com.amazonaws.services.simpledb.model.GetAttributesResult 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));
}
}
}
use of com.amazonaws.services.simpledb.model.GetAttributesResult 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);
}
}
use of com.amazonaws.services.simpledb.model.GetAttributesResult 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);
}
}
use of com.amazonaws.services.simpledb.model.GetAttributesResult 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());
}
Aggregations