Search in sources :

Example 1 with Document

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;
}
Also used : ScanRequest(com.amazonaws.services.dynamodbv2.model.ScanRequest) ScanResult(com.amazonaws.services.dynamodbv2.model.ScanResult) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) ArrayList(java.util.ArrayList) Document(com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.Document)

Example 2 with Document

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;
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) QueryResult(com.amazonaws.services.dynamodbv2.model.QueryResult) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) QueryRequest(com.amazonaws.services.dynamodbv2.model.QueryRequest) ArrayList(java.util.ArrayList) Document(com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.Document)

Example 3 with Document

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;
}
Also used : DeleteItemRequest(com.amazonaws.services.dynamodbv2.model.DeleteItemRequest) DeleteItemResult(com.amazonaws.services.dynamodbv2.model.DeleteItemResult) Document(com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.Document)

Example 4 with Document

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;
}
Also used : JsonObject(com.google.gson.JsonObject) Document(com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.Document) JsonParser(com.google.gson.JsonParser)

Example 5 with Document

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());
}
Also used : JsonArray(com.google.gson.JsonArray) Primitive(com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.Primitive) JsonPrimitive(com.google.gson.JsonPrimitive) JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) DynamoDBBool(com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.DynamoDBBool) Document(com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.Document) JsonParseException(com.google.gson.JsonParseException) DynamoDBList(com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.DynamoDBList)

Aggregations

Document (com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.Document)8 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)4 Primitive (com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.Primitive)3 DynamoDBBool (com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.DynamoDBBool)2 DynamoDBEntry (com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.DynamoDBEntry)2 DynamoDBList (com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.DynamoDBList)2 JsonParseException (com.google.gson.JsonParseException)2 JsonPrimitive (com.google.gson.JsonPrimitive)2 ArrayList (java.util.ArrayList)2 DynamoDBNull (com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.DynamoDBNull)1 PrimitiveList (com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.PrimitiveList)1 Key (com.amazonaws.mobileconnectors.dynamodbv2.document.internal.Key)1 KeyDescription (com.amazonaws.mobileconnectors.dynamodbv2.document.internal.KeyDescription)1 Condition (com.amazonaws.services.dynamodbv2.model.Condition)1 DeleteItemRequest (com.amazonaws.services.dynamodbv2.model.DeleteItemRequest)1 DeleteItemResult (com.amazonaws.services.dynamodbv2.model.DeleteItemResult)1 GetItemRequest (com.amazonaws.services.dynamodbv2.model.GetItemRequest)1 GetItemResult (com.amazonaws.services.dynamodbv2.model.GetItemResult)1 PutItemRequest (com.amazonaws.services.dynamodbv2.model.PutItemRequest)1 PutItemResult (com.amazonaws.services.dynamodbv2.model.PutItemResult)1