use of com.amazonaws.AmazonClientException in project siena by mandubian.
the class SdbPersistenceManager method deleteByKeys.
@Override
public <T> int deleteByKeys(Class<T> clazz, Iterable<?> keys) {
List<DeletableItem> doList = new ArrayList<DeletableItem>();
int nb = 0;
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;
}
use of com.amazonaws.AmazonClientException in project siena by mandubian.
the class SdbPersistenceManager method rawGet.
protected <T> int rawGet(Iterable<T> models) {
StringBuffer domainBuf = new StringBuffer();
SelectRequest req = SdbMappingUtils.buildBatchGetQuery(models, prefix, domainBuf);
req.setConsistentRead(isReadConsistent());
try {
checkDomain(domainBuf.toString());
SelectResult res = sdb.select(req);
int nb = SdbMappingUtils.mapSelectResult(res, models);
// join management
// gets class
Class<?> clazz = null;
for (T obj : models) {
if (clazz == null) {
clazz = obj.getClass();
break;
}
}
if (!ClassInfo.getClassInfo(clazz).joinFields.isEmpty()) {
mapJoins(models);
}
return nb;
} catch (AmazonClientException ex) {
throw new SienaException(ex);
}
}
use of com.amazonaws.AmazonClientException in project siena by mandubian.
the class SdbPersistenceManager method update.
public <T> int update(Iterable<T> models) {
Map<String, List<ReplaceableItem>> doMap = new HashMap<String, List<ReplaceableItem>>();
int nb = 0;
for (Object obj : models) {
Class<?> clazz = obj.getClass();
String domain = SdbMappingUtils.getDomainName(clazz, prefix);
List<ReplaceableItem> doList = doMap.get(domain);
if (doList == null) {
doList = new ArrayList<ReplaceableItem>();
doMap.put(domain, doList);
}
doList.add(SdbMappingUtils.createItem(obj));
nb++;
}
try {
for (String domain : doMap.keySet()) {
checkDomain(domain);
List<ReplaceableItem> 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.batchPutAttributes(new BatchPutAttributesRequest(domain, doList.subList(i, sz)));
}
}
} catch (AmazonClientException ex) {
throw new SienaException(ex);
}
return nb;
}
use of com.amazonaws.AmazonClientException in project siena by mandubian.
the class SdbPersistenceManager method insert.
@Override
public int insert(Iterable<?> objects) {
Map<String, List<ReplaceableItem>> doMap = new HashMap<String, List<ReplaceableItem>>();
int nb = 0;
for (Object obj : objects) {
Class<?> clazz = obj.getClass();
String domain = SdbMappingUtils.getDomainName(clazz, prefix);
List<ReplaceableItem> doList = doMap.get(domain);
if (doList == null) {
doList = new ArrayList<ReplaceableItem>();
doMap.put(domain, doList);
}
doList.add(SdbMappingUtils.createItem(obj));
nb++;
}
try {
for (String domain : doMap.keySet()) {
checkDomain(domain);
List<ReplaceableItem> 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.batchPutAttributes(new BatchPutAttributesRequest(domain, doList.subList(i, sz)));
}
}
} catch (AmazonClientException ex) {
throw new SienaException(ex);
}
return nb;
}
use of com.amazonaws.AmazonClientException in project beam by apache.
the class S3FileSystem method expandGlob.
private ExpandedGlob expandGlob(S3ResourceId glob) {
// The S3 API can list objects, filtered by prefix, but not by wildcard.
// Here, we find the longest prefix without wildcard "*",
// then filter the results with a regex.
checkArgument(glob.isWildcard(), "isWildcard");
String keyPrefix = glob.getKeyNonWildcardPrefix();
Pattern wildcardRegexp = Pattern.compile(wildcardToRegexp(glob.getKey()));
LOG.debug("expanding bucket {}, prefix {}, against pattern {}", glob.getBucket(), keyPrefix, wildcardRegexp.toString());
ImmutableList.Builder<S3ResourceId> expandedPaths = ImmutableList.builder();
String continuationToken = null;
do {
ListObjectsV2Request request = new ListObjectsV2Request().withBucketName(glob.getBucket()).withPrefix(keyPrefix).withContinuationToken(continuationToken);
ListObjectsV2Result result;
try {
result = amazonS3.get().listObjectsV2(request);
} catch (AmazonClientException e) {
return ExpandedGlob.create(glob, new IOException(e));
}
continuationToken = result.getNextContinuationToken();
for (S3ObjectSummary objectSummary : result.getObjectSummaries()) {
// Filter against regex.
if (wildcardRegexp.matcher(objectSummary.getKey()).matches()) {
S3ResourceId expandedPath = S3ResourceId.fromComponents(glob.getScheme(), objectSummary.getBucketName(), objectSummary.getKey()).withSize(objectSummary.getSize()).withLastModified(objectSummary.getLastModified());
LOG.debug("Expanded S3 object path {}", expandedPath);
expandedPaths.add(expandedPath);
}
}
} while (continuationToken != null);
return ExpandedGlob.create(glob, expandedPaths.build());
}
Aggregations