Package com.amazonaws.services.dynamodb.model

Examples of com.amazonaws.services.dynamodb.model.ScanResult


        ScanRequest scanRequest = createScanRequestFromExpression(clazz, scanExpression, config);
        scanRequest.setCount(true);

        // Count scans can also be truncated for large datasets
        int count = 0;
        ScanResult scanResult = null;
        do {
            scanResult = db.scan(applyUserAgent(scanRequest));
            count += scanResult.getCount();
            scanRequest.setExclusiveStartKey(scanResult.getLastEvaluatedKey());
        } while (scanResult.getLastEvaluatedKey() != null);

        return count;
    }
View Full Code Here


    public <T> PaginatedScanList<T> scan(Class<T> clazz, DynamoDBScanExpression scanExpression, DynamoDBMapperConfig config) {
        config = mergeConfig(config);

        ScanRequest scanRequest = createScanRequestFromExpression(clazz, scanExpression, config);

        ScanResult scanResult = db.scan(applyUserAgent(scanRequest));
        return new PaginatedScanList<T>(this, clazz, db, scanRequest, scanResult);
    }
View Full Code Here

        ScanRequest scanRequest = createScanRequestFromExpression(clazz, scanExpression, config);
        scanRequest.setCount(true);

        // Count scans can also be truncated for large datasets
        int count = 0;
        ScanResult scanResult = null;
        do {
            scanResult = db.scan(applyUserAgent(scanRequest));
            count += scanResult.getCount();
            scanRequest.setExclusiveStartKey(scanResult.getLastEvaluatedKey());
        } while (scanResult.getLastEvaluatedKey() != null);

        return count;
    }
View Full Code Here

    public <T> PaginatedScanList<T> scan(Class<T> clazz, DynamoDBScanExpression scanExpression, DynamoDBMapperConfig config) {
        config = mergeConfig(config);

        ScanRequest scanRequest = createScanRequestFromExpression(clazz, scanExpression, config);

        ScanResult scanResult = db.scan(applyUserAgent(scanRequest));
        return new PaginatedScanList<T>(this, clazz, db, scanRequest, scanResult);
    }
View Full Code Here

    public <T> ScanResultPage<T> scanPage(Class<T> clazz, DynamoDBScanExpression scanExpression, DynamoDBMapperConfig config) {
        config = mergeConfig(config);

        ScanRequest scanRequest = createScanRequestFromExpression(clazz, scanExpression, config);

        ScanResult scanResult = db.scan(applyUserAgent(scanRequest));
        ScanResultPage<T> result = new ScanResultPage<T>();
        result.setResults(marshallIntoObjects(clazz, scanResult.getItems()));
        result.setLastEvaluatedKey(scanResult.getLastEvaluatedKey());
       
        return result;
    }
View Full Code Here

        ScanRequest scanRequest = createScanRequestFromExpression(clazz, scanExpression, config);
        scanRequest.setCount(true);

        // Count scans can also be truncated for large datasets
        int count = 0;
        ScanResult scanResult = null;
        do {
            scanResult = db.scan(applyUserAgent(scanRequest));
            count += scanResult.getCount();
            scanRequest.setExclusiveStartKey(scanResult.getLastEvaluatedKey());
        } while (scanResult.getLastEvaluatedKey() != null);

        return count;
    }
View Full Code Here

  }

  public com.amazonaws.services.dynamodbv2.model.ScanResult scanV2(com.amazonaws.services.dynamodbv2.model.ScanRequest v2Request) {
        Table table = this.tables.get(v2Request.getTableName());
        ScanRequest request = AlternatorDBApiVersion2Mapper.MapV2ScanRequestToV1(v2Request, table);
        ScanResult result = scan(request);
        return AlternatorDBApiVersion2Mapper.MapV1ScanResultToV2(result, table);
  }
View Full Code Here

        if (valueType.equals(AttributeValueType.S)) return value.getS();
        throw new IllegalArgumentException("Can only return values for Number and String, got " + valueType);
    }

  public synchronized ScanResult scan(ScanRequest request) {
    ScanResult result = new ScanResult();
    List<Error> errors = new ScanRequestValidator().validate(request);
    if (errors.size() > 0) {
      throw createInternalServerException(errors);
    }
    result.setConsumedCapacityUnits(0.5);
    List<Map<String, AttributeValue>> items = new ArrayList<Map<String, AttributeValue>>();
    for (String key : this.tables.get(request.getTableName()).getItemRangeGroups().keySet()) {
          ItemRangeGroup rangeGroup = this.tables.get(request.getTableName()).getItemRangeGroup(key);
          for (String rangeKey : rangeGroup.getKeySet()) {
      Map<String, AttributeValue> item = rangeGroup.getItem(rangeKey);
      if (request.getScanFilter() != null) {
                //Don't add item immediately - evaluate all conditions first
                boolean shouldAddItem = true;
        for (String k : request.getScanFilter().keySet()) {
                    //Set this to true if one of conditions matches
                    boolean conditionMatches = false;
                    final AttributeValue attribute = item.get(k);
          if (attribute != null) {
            final Condition cond = request.getScanFilter().get(k);
                        final AttributeValue comp = cond.getAttributeValueList().isEmpty() ? null : cond.getAttributeValueList().get(0);
                        final int condSize = cond.getAttributeValueList().size();

                        if (cond.getComparisonOperator() == null) {
              throw new ResourceNotFoundException("There must be a comparisonOperator");
            }

                        if (cond.getComparisonOperator().equals("EQ")) {
              if (condSize == 1 && isComparableInScan(attribute, comp)) {
                conditionMatches = compareForScan(attribute, comp) == 0;
              }
            } else
            if (cond.getComparisonOperator().equals("LE")) {
              if (condSize == 1 && isComparableInScan(attribute, comp)) {
                                conditionMatches = compareForScan(attribute, comp) <= 0;
                }
            } else
            if (cond.getComparisonOperator().equals("LT")) {
              if (condSize == 1 && isComparableInScan(attribute, comp)) {
                                conditionMatches = compareForScan(attribute, comp) < 0;
              }
            } else
            if (cond.getComparisonOperator().equals("GE")) {
              if (condSize == 1 && isComparableInScan(attribute, comp)) {
                                conditionMatches = compareForScan(attribute, comp) >= 0;
                            }
            } else
            if (cond.getComparisonOperator().equals("GT")) {
              if (condSize == 1 && isComparableInScan(attribute, comp)) {
                                conditionMatches = compareForScan(attribute, comp) > 0;
              }
            } else
                        if (cond.getComparisonOperator().equals("BETWEEN")) {
                            if (condSize == 2) {
                                final AttributeValue comp2 = cond.getAttributeValueList().get(1);
                                if (isComparableInScan(attribute, comp) && isComparableInScan(attribute, comp2)) {
                                    conditionMatches = compareForScan(attribute, comp) >= 0 && compareForScan(attribute, comp2) <= 0;
                                }
                            }
                        } else
                        if (cond.getComparisonOperator().equals("BEGINS_WITH")) {
                            //TODO: Should we fail on AttributeValueType other than S (as per AWS DynamoDB docs)?
                            //TODO: Investigate how actual DynamoDB works
                            if (condSize == 1 && getAttributeValueType(attribute).equals(AttributeValueType.S) &&
                                    getAttributeValueType(comp).equals(AttributeValueType.S)) {
                                conditionMatches = attribute.getS().startsWith(comp.getS());
                            }
                        } else
                        if (cond.getComparisonOperator().equals("CONTAINS")) {
                            if (condSize == 1) {
                if (getAttributeValueType(item.get(k)).equals(AttributeValueType.S) || getAttributeValueType(item.get(k)).equals(AttributeValueType.N)) {
                  String value = getAttributeValueAsString(attribute);
                  String subs = getAttributeValueAsString(comp);
                                    conditionMatches = value.contains(subs);
                                }
                            }
                            //TODO: Check for sets!!!
                        } else
            if (cond.getComparisonOperator().equals("IN")) {
              for(AttributeValue value : cond.getAttributeValueList()){
                if (item.get(k).equals(value)){
                                    conditionMatches = true;
                                    break;
                                }
              }
            }
          }
                    shouldAddItem = shouldAddItem && conditionMatches;
        }
                if (shouldAddItem) items.add(item);
      } else {
        items.add(item);
      }
          }
    }
    if ((request.getLimit() != null) && (items.size() > request.getLimit())) {
      items = items.subList(0, request.getLimit() - 1);
    }

    if (request.getAttributesToGet() != null) {
      List<Map<String, AttributeValue>> copy = getItemWithAttributesToGet(items, request.getAttributesToGet());
      items = copy;
    }

    result.setItems(items);
    result.setCount(items.size());
    result.setScannedCount(items.size());
    return result;
  }
View Full Code Here

        rangeKeyCondition.setComparisonOperator(ComparisonOperator.CONTAINS);
        Map<String, Condition> conditionMap = new HashMap<String, Condition>();
        conditionMap.put("range", rangeKeyCondition);
        request.setScanFilter(conditionMap);

        ScanResult result = getClient().scan(request);
        Assert.assertNotNull(result);
        Assert.assertNotNull(result.getItems());
        Assert.assertEquals(40, result.getItems().size());
        for (Map<String, AttributeValue> item : result.getItems()) {
            Assert.assertTrue(item.get("range").getN().contains("4"));
        }
    }
View Full Code Here

        rangeKeyCondition.setComparisonOperator(ComparisonOperator.EQ);
        conditionMap.put("second", rangeKeyCondition);

        request.setScanFilter(conditionMap);

        ScanResult result = getClient().scan(request);
        Assert.assertNotNull(result);
        Assert.assertNotNull(result.getItems());
        //Should be no duplicates
        Assert.assertEquals(10, result.getItems().size());
        for (Map<String,AttributeValue> item : result.getItems()) {
            Assert.assertEquals("4", item.get("range").getN());
            Assert.assertEquals("4", item.get("second").getN());
        }
    }
View Full Code Here

TOP

Related Classes of com.amazonaws.services.dynamodb.model.ScanResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.