Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   *
   * Licensed under the Apache License, Version 2.0 (the "License").
   * You may not use this file except in compliance with the License.
   * A copy of the License is located at
   *
   *  http://aws.amazon.com/apache2.0
   *
  * or in the "license" file accompanying this file. This file is distributed
  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
 package com.amazonaws.services.dynamodbv2.document.internal;
 
 import java.util.Map;
 
The implementation for QueryApi of a table.
 
 public class QueryImpl extends AbstractImpl implements QueryApi {
     public QueryImpl(AmazonDynamoDB clientTable table) {
         super(clienttable);
     }
 
     @Override
     public ItemCollection<QueryOutcomequery(String hashKeyNameObject hashKey) {
         return doQuery(new QuerySpec()
             .withHashKey(new KeyAttribute(hashKeyNamehashKey)));
     }
 
     @Override
     public ItemCollection<QueryOutcomequery(KeyAttribute hashKey) {
         return doQuery(new QuerySpec().withHashKey(hashKey));
     }
 
     @Override
     public ItemCollection<QueryOutcomequery(KeyAttribute hashKey,
             RangeKeyCondition rangeKeyCondition) {
         return doQuery(new QuerySpec().withHashKey(hashKey)
                 .withRangeKeyCondition(rangeKeyCondition));
     }
 
     @Override
     public ItemCollection<QueryOutcomequery(KeyAttribute hashKey,
             RangeKeyCondition rangeKeyConditionQueryFilter... queryFilters) {
         return doQuery(new QuerySpec().withHashKey(hashKey)
                 .withRangeKeyCondition(rangeKeyCondition)
                 .withQueryFilters(queryFilters));
     }
 
     @Override
     public ItemCollection<QueryOutcomequery(KeyAttribute hashKey,
             RangeKeyCondition rangeKeyConditionString filterExpression,
             Map<StringStringnameMapMap<StringObjectvalueMap) {
         return doQuery(new QuerySpec().withHashKey(hashKey)
                 .withRangeKeyCondition(rangeKeyCondition)
                 .withFilterExpression(filterExpression)
                 .withNameMap(nameMap)
                 .withValueMap(valueMap));
     }
 
     @Override
     public ItemCollection<QueryOutcomequery(KeyAttribute hashKey,
             RangeKeyCondition rangeKeyConditionString filterExpression,
             String projectionExpressionMap<StringStringnameMap,
             Map<StringObjectvalueMap) {
         return doQuery(new QuerySpec().withHashKey(hashKey)
                 .withRangeKeyCondition(rangeKeyCondition)
                 .withFilterExpression(filterExpression)
                 .withProjectionExpression(projectionExpression)
                 .withNameMap(nameMap)
                 .withValueMap(valueMap));
     }
 
     @Override
     public ItemCollection<QueryOutcomequery(QuerySpec spec) {
         return doQuery(spec);
     }
 
     protected ItemCollection<QueryOutcomedoQuery(QuerySpec spec) {
         // set the table name
        String tableName = getTable().getTableName();
        QueryRequest req = spec.getRequest().withTableName(tableName);
        // hash key
        final KeyAttribute hashKey = spec.getHashKey();
        if (hashKey != null) {
            req.addKeyConditionsEntry(hashKey.getName(),
                    new Condition()
                    .withComparisonOperator(.)
                    .withAttributeValueList(InternalUtils.toAttributeValue(hashKey.getValue()))
            );
        }
        // range key condition
        RangeKeyCondition rangeKeyCond = spec.getRangeKeyCondition();
        if (rangeKeyCond != null) {
            KeyConditions keyCond = rangeKeyCond.getKeyCondition();
            if (keyCond == null)
                throw new IllegalArgumentException("key condition not specified in range key condition");
            Object[] values = rangeKeyCond.getValues();
            if (values == null)
                throw new IllegalArgumentException("key condition values not specified in range key condition");
            req.addKeyConditionsEntry(rangeKeyCond.getAttrName(),
                    new Condition()
                    .withComparisonOperator(keyCond.toComparisonOperator())
                    .withAttributeValueList(InternalUtils.toAttributeValues(values))
            );
        }
        // query filters;
        Collection<QueryFilterfilters = spec.getQueryFilters();
        if (filters != null) {
            req.setQueryFilter(InternalUtils.toAttributeConditionMap(filters));
        }
        // set up the start key, if any
        Collection<KeyAttributestartKey = spec.getExclusiveStartKey();
        if (startKey != null)
            req.setExclusiveStartKey(InternalUtils.toAttributeValueMap(startKey));
        // set up the value map, if any (when expression API is used)
        final Map<String,AttributeValueattrValMap = InternalUtils.fromSimpleMap(spec.getValueMap());
        // set up expressions, if any
        req.withExpressionAttributeNames(spec.getNameMap())
           .withExpressionAttributeValues(attrValMap)
           ;
        return new QueryCollection(getClient(), spec);
    }
    @Override
    public ItemCollection<QueryOutcomequery(String hashKeyName,
            Object hashKeyValueRangeKeyCondition rangeKeyCondition) {
        return query(new KeyAttribute(hashKeyNamehashKeyValue), rangeKeyCondition);
    }
    @Override
    public ItemCollection<QueryOutcomequery(String hashKeyName,
            Object hashKeyValueRangeKeyCondition rangeKeyCondition,
            QueryFilter... queryFilters) {
        return query(new KeyAttribute(hashKeyNamehashKeyValue),
                rangeKeyConditionqueryFilters);
    }
    @Override
    public ItemCollection<QueryOutcomequery(String hashKeyName,
            Object hashKeyValueRangeKeyCondition rangeKeyCondition,
            String filterExpressionMap<StringStringnameMap,
            Map<StringObjectvalueMap) {
        return query(new KeyAttribute(hashKeyNamehashKeyValue),
                rangeKeyConditionfilterExpressionnameMapvalueMap);
    }
    @Override
    public ItemCollection<QueryOutcomequery(String hashKeyName,
            Object hashKeyValueRangeKeyCondition rangeKeyCondition,
            String filterExpressionString projectionExpression,
            Map<StringStringnameMapMap<StringObjectvalueMap) {
        return query(new KeyAttribute(hashKeyNamehashKeyValue),
                rangeKeyConditionfilterExpressionprojectionExpression,
                nameMapvalueMap);
    }
New to GrepCode? Check out our FAQ X