use of com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.Document in project aws-sdk-android by aws-amplify.
the class Search method getNextScanResultSet.
private List<Document> getNextScanResultSet() {
final List<Document> returnValue = new ArrayList<Document>();
final ScanRequest request = new ScanRequest();
request.withExclusiveStartKey(nextKey).withAttributesToGet(attributesToGet).withLimit(limit).withTableName(tableName).withConsistentRead(isConsistentRead);
if (select != null) {
request.withSelect(select);
}
if (this.filter != null) {
request.withScanFilter(this.filter.toConditions());
}
if (!StringUtils.isBlank(this.indexName)) {
request.withIndexName(indexName);
}
if (this.filterExpression != null && this.filterExpression.isSet()) {
this.filterExpression.applyExpression(request, table);
}
if (request.getScanFilter() != null && request.getScanFilter().size() > 1) {
request.setConditionalOperator(this.conditionalOperator);
}
if (this.totalSegments != 0) {
request.withTotalSegments(totalSegments).withSegment(segment);
}
Table.appendDynamoDBDocumentUserAgentString(request);
final ScanResult result = table.getClient().scan(request);
for (final Map<String, AttributeValue> item : result.getItems()) {
final Document doc = Document.fromAttributeMap(item);
returnValue.add(doc);
if (this.collectResults) {
this.matches.add(doc);
}
}
nextKey = result.getLastEvaluatedKey();
if (nextKey == null || nextKey.size() == 0) {
isDone = true;
}
return returnValue;
}
use of com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.Document in project aws-sdk-android by aws-amplify.
the class Search method getNextQueryResultSet.
private List<Document> getNextQueryResultSet() {
final List<Document> returnValue = new ArrayList<Document>();
final QueryRequest request = new QueryRequest();
request.withExclusiveStartKey(nextKey).withAttributesToGet(attributesToGet).withLimit(limit).withTableName(tableName).withConsistentRead(isConsistentRead).withIndexName(this.indexName);
if (select != null) {
request.withSelect(select);
}
Expression.applyExpression(request, table, keyExpression, filterExpression);
if (this.filter != null) {
final Map<String, Condition> keyConditions = getKeyConditions((QueryFilter) this.filter, request.getIndexName());
final Map<String, Condition> filterConditions = getFilterConditions((QueryFilter) this.filter, request.getIndexName());
if (!keyConditions.isEmpty()) {
request.withKeyConditions(keyConditions);
}
if (!filterConditions.isEmpty()) {
request.withQueryFilter(filterConditions);
}
} else {
request.withKeyConditions(null).withQueryFilter(null);
}
if (request.getQueryFilter() != null && request.getQueryFilter().size() > 1) {
request.withConditionalOperator(this.conditionalOperator);
} else {
request.withConditionalOperator((String) null);
}
Table.appendDynamoDBDocumentUserAgentString(request);
final QueryResult result = table.getClient().query(request);
for (final Map<String, AttributeValue> item : result.getItems()) {
final Document doc = Document.fromAttributeMap(item);
returnValue.add(doc);
if (this.collectResults) {
this.matches.add(doc);
}
}
nextKey = result.getLastEvaluatedKey();
if (nextKey == null || nextKey.size() == 0) {
isDone = true;
}
return returnValue;
}
use of com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.Document in project aws-sdk-android by aws-amplify.
the class Table method deleteItem.
private Document deleteItem(Key key, DeleteItemOperationConfig config) {
final DeleteItemRequest request = new DeleteItemRequest(tableName, key);
if (config != null) {
request.setReturnValues(config.getReturnValue());
}
Table.appendDynamoDBDocumentUserAgentString(request);
final DeleteItemResult result = this.client.deleteItem(request);
final Document returnDocument = this.fromAttributeMap(result.getAttributes());
returnDocument.commit();
return returnDocument;
}
use of com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.Document in project aws-sdk-android by aws-amplify.
the class JsonUtils method fromJson.
public static Document fromJson(String jsonText) {
final JsonParser parser = new JsonParser();
final JsonObject json = parser.parse(jsonText).getAsJsonObject();
if (!json.isJsonObject()) {
throw new IllegalArgumentException("expected object as JSON root");
}
final Document doc = (Document) JsonUtils.toEntry(json);
if (doc == null) {
throw new IllegalStateException();
}
return doc;
}
use of com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.Document in project aws-sdk-android by aws-amplify.
the class JsonUtils method toEntry.
private static DynamoDBEntry toEntry(JsonElement data) {
if (data == null || data.isJsonNull()) {
return DynamoDBNull.NULL;
}
if (data.isJsonObject()) {
final Document doc = new Document();
for (final Entry<String, JsonElement> entry : data.getAsJsonObject().entrySet()) {
final String key = entry.getKey();
final JsonElement element = entry.getValue();
doc.put(key, toEntry(element));
}
return doc;
}
if (data.isJsonArray()) {
final DynamoDBList list = new DynamoDBList();
final JsonArray array = data.getAsJsonArray();
for (final Iterator<JsonElement> iterator = array.iterator(); iterator.hasNext(); ) {
final JsonElement type = iterator.next();
list.add(toEntry(type));
}
return list;
}
final JsonPrimitive primitive = data.getAsJsonPrimitive();
if (primitive.isBoolean()) {
return new DynamoDBBool(primitive.getAsBoolean());
}
if (primitive.isString()) {
return new Primitive(primitive.getAsString());
}
if (primitive.isNumber()) {
return new Primitive(primitive.getAsNumber());
}
throw new JsonParseException("unable to parse json for key " + data.toString());
}
Aggregations