Java 类com.amazonaws.services.dynamodbv2.model.Condition 实例源码

项目:rehttp    文件:DyBase.java   
@Override
public Iterable<Take> expired() {
    return new Mapped<>(
        this.table()
            .frame()
            .through(
                new QueryValve()
                    .withIndexName("expired")
                    .withConsistentRead(false)
                    .withSelect(Select.ALL_ATTRIBUTES)
            )
            .where("success", Conditions.equalTo(Boolean.toString(false)))
            .where(
                "when",
                new Condition()
                    .withComparisonOperator(ComparisonOperator.LT)
                    .withAttributeValueList(
                        new AttributeValue().withN(
                            Long.toString(System.currentTimeMillis())
                        )
                    )
            ),
        item -> new DyTake(item, this.delay)
    );
}
项目:threecopies    文件:DyScript.java   
@Override
public String ocket(final long time) throws IOException {
    final Iterator<Item> items = this.region.table("logs")
        .frame()
        .through(new QueryValve().withLimit(1))
        .where("group", this.group())
        .where(
            "start",
            new Condition()
                .withComparisonOperator(ComparisonOperator.EQ)
                .withAttributeValueList(
                    new AttributeValue().withN(Long.toString(time))
                )
        )
        .iterator();
    if (!items.hasNext()) {
        throw new RsForward(
            new RsFlash("Can't find log"),
            "/scripts"
        );
    }
    return items.next().get("ocket").getS();
}
项目:PlatePicks-Android    文件:NoSQLTableFood.java   
@Override
public boolean executeOperation() {
    final FoodDO itemToFind = new FoodDO();
    itemToFind.setFoodId(getDemoPartitionValue());

    final Condition rangeKeyCondition = new Condition()
        .withComparisonOperator(ComparisonOperator.LT.toString())
        .withAttributeValueList(new AttributeValue().withS(DEMO_SORT_VALUE));
    final DynamoDBQueryExpression<FoodDO> queryExpression = new DynamoDBQueryExpression<FoodDO>()
        .withHashKeyValues(itemToFind)
        .withRangeKeyCondition(DEMO_SORT_KEY, rangeKeyCondition)
        .withConsistentRead(false)
        .withLimit(RESULTS_PER_RESULT_GROUP);

    results = mapper.query(FoodDO.class, queryExpression);
    if (results != null) {
        resultsIterator = results.iterator();
        if (resultsIterator.hasNext()) {
            return true;
        }
    }
    return false;
}
项目:PlatePicks-Android    文件:NoSQLTableList.java   
@Override
public boolean executeOperation() {
    final ListDO itemToFind = new ListDO();
    itemToFind.setUserId(getDemoPartitionValue());

    final Condition rangeKeyCondition = new Condition()
        .withComparisonOperator(ComparisonOperator.LT.toString())
        .withAttributeValueList(new AttributeValue().withS(DEMO_SORT_VALUE));
    final DynamoDBQueryExpression<ListDO> queryExpression = new DynamoDBQueryExpression<ListDO>()
        .withHashKeyValues(itemToFind)
        .withRangeKeyCondition(DEMO_SORT_KEY, rangeKeyCondition)
        .withConsistentRead(false)
        .withLimit(RESULTS_PER_RESULT_GROUP);

    results = mapper.query(ListDO.class, queryExpression);
    if (results != null) {
        resultsIterator = results.iterator();
        if (resultsIterator.hasNext()) {
            return true;
        }
    }
    return false;
}
项目:PlatePicks-Android    文件:NoSQLTableList.java   
public boolean executeOperation() {
    final ListDO itemToFind = new ListDO();
    itemToFind.setUserId(getDemoPartitionValue());

    final Condition rangeKeyCondition = new Condition()
        .withComparisonOperator(ComparisonOperator.LT.toString())
        .withAttributeValueList(new AttributeValue().withS(DEMO_SORT_VALUE));

    // Use an expression names Map to avoid the potential for attribute names
    // colliding with DynamoDB reserved words.
    final Map <String, String> filterExpressionAttributeNames = new HashMap<>();
    filterExpressionAttributeNames.put("#creationDate", DEMO_PRIMARY_CONDITION_KEY);

    final Map<String, AttributeValue> filterExpressionAttributeValues = new HashMap<>();
    filterExpressionAttributeValues.put(":MincreationDate",
        new AttributeValue().withN(DEMO_PRIMARY_CONDITION_VALUE));

    final DynamoDBQueryExpression<ListDO> queryExpression = new DynamoDBQueryExpression<ListDO>()
        .withHashKeyValues(itemToFind)
        .withRangeKeyCondition(DEMO_SORT_KEY, rangeKeyCondition)
        .withFilterExpression("#creationDate > :MincreationDate")
        .withExpressionAttributeNames(filterExpressionAttributeNames)
        .withExpressionAttributeValues(filterExpressionAttributeValues)
        .withConsistentRead(false)
        .withLimit(RESULTS_PER_RESULT_GROUP);

    results = mapper.query(ListDO.class, queryExpression);
    if (results != null) {
        resultsIterator = results.iterator();
        if (resultsIterator.hasNext()) {
            return true;
        }
    }
    return false;
}
项目:PlatePicks-Android    文件:NoSQLTableList.java   
public boolean executeOperation() {
    // Perform a query using a partition key and sort key condition.
    final ListDO itemToFind = new ListDO();
    itemToFind.setUserId(getDemoDateSortedPartitionValue());
    final Condition sortKeyCondition = new Condition()
        .withComparisonOperator(ComparisonOperator.LT.toString())

        .withAttributeValueList(new AttributeValue().withN(DEMO_DATESORTED_SORT_VALUE.toString()));
    // Perform get using Partition key and sort key condition
    DynamoDBQueryExpression<ListDO> queryExpression = new DynamoDBQueryExpression<ListDO>()
        .withHashKeyValues(itemToFind)
        .withRangeKeyCondition("creationDate", sortKeyCondition)
        .withConsistentRead(false);
    results = mapper.query(ListDO.class, queryExpression);
    if (results != null) {
        resultsIterator = results.iterator();
        if (resultsIterator.hasNext()) {
            return true;
        }
    }
    return false;
}
项目:PlatePicks-Android    文件:NoSQLTableComment.java   
@Override
public boolean executeOperation() {
    final CommentDO itemToFind = new CommentDO();
    itemToFind.setUserId(getDemoPartitionValue());

    final Condition rangeKeyCondition = new Condition()
        .withComparisonOperator(ComparisonOperator.LT.toString())
        .withAttributeValueList(new AttributeValue().withS(DEMO_SORT_VALUE));
    final DynamoDBQueryExpression<CommentDO> queryExpression = new DynamoDBQueryExpression<CommentDO>()
        .withHashKeyValues(itemToFind)
        .withRangeKeyCondition(DEMO_SORT_KEY, rangeKeyCondition)
        .withConsistentRead(false)
        .withLimit(RESULTS_PER_RESULT_GROUP);

    results = mapper.query(CommentDO.class, queryExpression);
    if (results != null) {
        resultsIterator = results.iterator();
        if (resultsIterator.hasNext()) {
            return true;
        }
    }
    return false;
}
项目:emr-dynamodb-connector    文件:DynamoDBClient.java   
public RetryResult<ScanResult> scanTable(
    String tableName, DynamoDBQueryFilter dynamoDBQueryFilter, Integer segment, Integer
    totalSegments, Map<String, AttributeValue> exclusiveStartKey, long limit, Reporter reporter) {
  final ScanRequest scanRequest = new ScanRequest(tableName)
      .withExclusiveStartKey(exclusiveStartKey)
      .withLimit(Ints.checkedCast(limit))
      .withSegment(segment)
      .withTotalSegments(totalSegments)
      .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);

  if (dynamoDBQueryFilter != null) {
    Map<String, Condition> scanFilter = dynamoDBQueryFilter.getScanFilter();
    if (!scanFilter.isEmpty()) {
      scanRequest.setScanFilter(scanFilter);
    }
  }

  RetryResult<ScanResult> retryResult = getRetryDriver().runWithRetry(new Callable<ScanResult>() {
    @Override
    public ScanResult call() {
      log.debug("Executing DynamoDB scan: " + scanRequest);
      return dynamoDB.scan(scanRequest);
    }
  }, reporter, PrintCounter.DynamoDBReadThrottle);
  return retryResult;
}
项目:duckdns    文件:AmazonDynamoDBDAO.java   
public Account accountGetAccountByToken(String token) {

    Condition hashKeyCondition = new Condition();
    hashKeyCondition.withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(new AttributeValue().withS(token));

    Map<String, Condition> keyConditions = new HashMap<String, Condition>();
    keyConditions.put("accountToken", hashKeyCondition);

    QueryRequest queryRequest = new QueryRequest();
    queryRequest.withTableName("accountsv2");
    queryRequest.withIndexName("accountToken-index");
    queryRequest.withKeyConditions(keyConditions);

    QueryResult result = dynamoDB.query(queryRequest);

    for(Map<String, AttributeValue> item : result.getItems()) {
        Account mappedItem = mapper.marshallIntoObject(Account.class, item);
        // Only want the First one
        return mappedItem;
    }

    return null;
}
项目:duckdns    文件:AmazonDynamoDBDAO.java   
public Account accountGetAccountByToken(String token) {

    Condition hashKeyCondition = new Condition();
    hashKeyCondition.withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(new AttributeValue().withS(token));

    Map<String, Condition> keyConditions = new HashMap<String, Condition>();
    keyConditions.put("accountToken", hashKeyCondition);

    QueryRequest queryRequest = new QueryRequest();
    queryRequest.withTableName("accountsv2");
    queryRequest.withIndexName("accountToken-index");
    queryRequest.withKeyConditions(keyConditions);

    QueryResult result = dynamoDB.query(queryRequest);

    for(Map<String, AttributeValue> item : result.getItems()) {
        Account mappedItem = mapper.marshallIntoObject(Account.class, item);
        // Only want the First one
        return mappedItem;
    }

    return null;
}
项目:Camel    文件:ScanCommandTest.java   
@Test
public void execute() {
    Map<String, Condition> scanFilter = new HashMap<String, Condition>();
    Condition condition = new Condition()
            .withComparisonOperator(ComparisonOperator.GT.toString())
            .withAttributeValueList(new AttributeValue().withN("1985"));
    scanFilter.put("year", condition);
    exchange.getIn().setHeader(DdbConstants.SCAN_FILTER, scanFilter);

    command.execute();

    Map<String, AttributeValue> mapAssert = new HashMap<String, AttributeValue>();
    mapAssert.put("1", new AttributeValue("LAST_KEY"));

    ConsumedCapacity consumed = (ConsumedCapacity) exchange.getIn().getHeader(DdbConstants.CONSUMED_CAPACITY);
    assertEquals(scanFilter, ddbClient.scanRequest.getScanFilter());
    assertEquals(Integer.valueOf(10), exchange.getIn().getHeader(DdbConstants.SCANNED_COUNT, Integer.class));
    assertEquals(Integer.valueOf(1), exchange.getIn().getHeader(DdbConstants.COUNT, Integer.class));
    assertEquals(Double.valueOf(1.0), consumed.getCapacityUnits());
    assertEquals(mapAssert, exchange.getIn().getHeader(DdbConstants.LAST_EVALUATED_KEY, Map.class));

    Map<?, ?> items = (Map<?, ?>) exchange.getIn().getHeader(DdbConstants.ITEMS, List.class).get(0);
    assertEquals(new AttributeValue("attrValue"), items.get("attrName"));
}
项目:querydsl-contrib    文件:DynamodbSerializer.java   
private void populateScanExpression(List<Expression<?>> expressions, Condition condition,
        DynamoDBScanExpression scanExpression) {

    List<AttributeValue> attributeValueList = new ArrayList<AttributeValue>();

    String attributeName = null;
    for (Expression<?> expression : expressions) {
        Object result = expression.accept(this, scanExpression);
        if (result instanceof String) {
            if (attributeName != null) {
                throw new RuntimeException("Already in use");
            }
            attributeName = (String) result;
        } else if (result instanceof AttributeValue) {
            attributeValueList.add((AttributeValue) result);
        } else {
            throw new UnsupportedOperationException("Invalid result: " + result);
        }
    }

    condition.setAttributeValueList(attributeValueList);
    scanExpression.addFilterCondition(attributeName, condition);
}
项目:milton-aws    文件:DynamoDBManagerImpl.java   
/**
 * The findRootFolder method retrieves an root item
 * 
 * @return
 */
@Override
public Folder findRootFolder(String tableName) {
       Condition condition = new Condition().withComparisonOperator(ComparisonOperator.EQ.toString())
               .withAttributeValueList(new AttributeValue().withS(AttributeKey.NOT_EXIST));

       Map<String, Condition> conditions = new HashMap<String, Condition>();
       conditions.put(AttributeKey.PARENT_UUID, condition);

       List<Map<String, AttributeValue>> items = dynamoDBService.getItem(tableName, conditions);
       List<Entity> children = DynamoDBEntityMapper.convertItemsToEntities(null, items);
       if (children == null || children.isEmpty()) {
           return null;
       }

       return (Folder) children.get(0);
}
项目:milton-aws    文件:DynamoDBManagerImpl.java   
/**
 * The findEntityByParent method enables you to retrieve multiple items
 * from one table.
 * 
 * @param parent
 * @return
 */
@Override
public List<Entity> findEntityByParent(String tableName, Folder parent) {
    if (parent == null) {
        return Collections.emptyList();
    }

    Condition condition = new Condition().withComparisonOperator(ComparisonOperator.EQ.toString())
           .withAttributeValueList(new AttributeValue().withS(parent.getId().toString()));
       Map<String, Condition> conditions = new HashMap<String, Condition>();
       conditions.put(AttributeKey.PARENT_UUID, condition);

       List<Map<String, AttributeValue>> items = dynamoDBService.getItem(tableName, conditions);
       List<Entity> children = DynamoDBEntityMapper.convertItemsToEntities(parent, items);
       if (children == null || children.isEmpty()) {
           return Collections.emptyList();
       }

       return children;
}
项目:milton-aws    文件:DynamoDBManagerImpl.java   
/**
    * The findEntityByParentAndType method enables you to retrieve multiple items
    * from one table.
    * 
    * @param parent
    * @param isDirectory
    * @return a list of entities
    */
@Override
   public List<Entity> findEntityByParentAndType(String tableName, Folder parent, boolean isDirectory) {
    if (parent == null) {
           return Collections.emptyList();
       }

    Map<String, Condition> conditions = new HashMap<String, Condition>();
    Condition parentUniqueId = new Condition().withComparisonOperator(ComparisonOperator.EQ.toString())
            .withAttributeValueList(new AttributeValue().withS(parent.getId().toString()));
       conditions.put(AttributeKey.PARENT_UUID, parentUniqueId);

       Condition entityType = new Condition().withComparisonOperator(ComparisonOperator.EQ.toString())
               .withAttributeValueList(new AttributeValue().withN(Integer.toString(isDirectory ? 1 : 0)));
       conditions.put(AttributeKey.IS_DIRECTORY, entityType);

       List<Map<String, AttributeValue>> items = dynamoDBService.getItem(tableName, conditions);
       List<Entity> children = DynamoDBEntityMapper.convertItemsToEntities(parent, items);
       if (children == null || children.isEmpty()) {
           return Collections.emptyList();
       }

       return children;
   }
项目:oada-ref-impl-java    文件:DynamodbDAO.java   
@Override
public List<LandUnit> getLandUnits(Long userId) {
    List<LandUnit> retval = new ArrayList<LandUnit>();
    try {
        /*
         * Scan items for movies with user id attribute.
         */
        Map<String, Condition> scanFilter = new HashMap<String, Condition>();
        Condition condition = new Condition()
            .withComparisonOperator(ComparisonOperator.EQ.toString())
            .withAttributeValueList(new AttributeValue().withN(userId.toString()));
        scanFilter.put(LandUnit.USER_ID_ATTR_NAME, condition);
        ScanRequest scanRequest =
                new ScanRequest(LANDUNIT_DYNAMO_DB_TABLE_NAME).withScanFilter(scanFilter);
        ScanResult scanResult = dynamoDB.scan(scanRequest);
        LOG.debug("DDB Scan Result: " + scanResult);
        retval = mapItemsToLandUnit(scanResult.getItems());
    } catch (Exception e) {
        LOG.error("Unable to retrieve land units from DDB " + e.getMessage());
    }
    return retval;
}
项目:aws-dynamodb-encryption-java    文件:MetaStore.java   
@Override
public long getMaxVersion(final String materialName) {
    final List<Map<String, AttributeValue>> items = ddb.query(
            new QueryRequest()
            .withTableName(tableName)
            .withConsistentRead(Boolean.TRUE)
            .withKeyConditions(
                    Collections.singletonMap(
                            DEFAULT_HASH_KEY,
                            new Condition().withComparisonOperator(
                                    ComparisonOperator.EQ).withAttributeValueList(
                                            new AttributeValue().withS(materialName))))
                                            .withLimit(1).withScanIndexForward(false)
                                            .withAttributesToGet(DEFAULT_RANGE_KEY)).getItems();
    if (items.isEmpty()) {
        return -1L;
    } else {
        return Long.parseLong(items.get(0).get(DEFAULT_RANGE_KEY).getN());
    }
}
项目:tcc-oada    文件:DynamodbDAO.java   
@Override
public List<LandUnit> getLandUnits(Long userId) {
    List<LandUnit> retval = new ArrayList<LandUnit>();
    try {
        /*
         * Scan items for movies with user id attribute.
         */
        Map<String, Condition> scanFilter = new HashMap<String, Condition>();
        Condition condition = new Condition()
            .withComparisonOperator(ComparisonOperator.EQ.toString())
            .withAttributeValueList(new AttributeValue().withN(userId.toString()));
        scanFilter.put(LandUnit.USER_ID_ATTR_NAME, condition);
        ScanRequest scanRequest =
                new ScanRequest(LANDUNIT_DYNAMO_DB_TABLE_NAME).withScanFilter(scanFilter);
        ScanResult scanResult = dynamoDB.scan(scanRequest);
        LOG.debug("DDB Scan Result: " + scanResult);
        retval = mapItemsToLandUnit(scanResult.getItems());
    } catch (Exception e) {
        LOG.error("Unable to retrieve land units from DDB " + e.getMessage());
    }
    return retval;
}
项目:spring-security-oauth2-dynamodb    文件:DynamoDBTokenStore.java   
public void removeAccessTokenUsingRefreshToken(String refreshToken) {
    String tokenId = null;

    try {
        tokenId = dynamoDBTemplate.queryUnique(schema.getAccessTableName(), schema.getAccessIndexRefreshToken(), //
                Collections.singletonMap(schema.getAccessColumnRefreshToken(), new Condition().withAttributeValueList(new AttributeValue(extractTokenKey(refreshToken))).withComparisonOperator(ComparisonOperator.EQ)),// 
                new ObjectExtractor<String>() {

                    public String extract(Map<String, AttributeValue> values) {
                        return values.get(schema.getAccessColumnTokenId()).getS();
                    }
                }, schema.getAccessColumnTokenId());
    } catch (EmptyResultDataAccessException | IncorrectResultSizeDataAccessException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Failed to find access token for refresh token " + refreshToken);
        }
    }

    if (tokenId == null) {
        return;
    }

    dynamoDBTemplate.delete(schema.getAccessTableName(), Collections.singletonMap(schema.getAccessColumnTokenId(), new AttributeValue(tokenId)));
}
项目:aws-dynamodb-examples    文件:LowLevelQuery.java   
private static void findRepliesForAThread(String forumName, String threadSubject) {

        String replyId = forumName + "#" + threadSubject;

        Condition hashKeyCondition = new Condition()
            .withComparisonOperator(ComparisonOperator.EQ)
            .withAttributeValueList(new AttributeValue().withS(replyId));

        Map<String, Condition> keyConditions = new HashMap<String, Condition>();
        keyConditions.put("Id", hashKeyCondition);

        QueryRequest queryRequest = new QueryRequest()
            .withTableName(tableName)
            .withKeyConditions(keyConditions);

        QueryResult result = client.query(queryRequest);
        for (Map<String, AttributeValue> item : result.getItems()) {
            printItem(item);
        }
    }
项目:aws-dynamodb-examples    文件:LowLevelQuery.java   
private static void findRepliesUsingAFilterExpression(String forumName, String threadSubject) {

   Map<String, Condition> keyConditions = makeReplyKeyConditions(forumName, threadSubject);

   Map<String, AttributeValue> expressionAttributeValues = new HashMap<String, AttributeValue>();
   expressionAttributeValues.put(":val", new AttributeValue().withS("User B")); 

   QueryRequest queryRequest = new QueryRequest()
       .withTableName(tableName)
       .withKeyConditions(keyConditions)
       .withFilterExpression("PostedBy = :val")
       .withExpressionAttributeValues(expressionAttributeValues)
       .withProjectionExpression("Message, ReplyDateTime, PostedBy");

    QueryResult result = client.query(queryRequest);
    for (Map<String, AttributeValue> item : result.getItems()) {
        printItem(item);
    }        
}
项目:aws-dynamodb-examples    文件:ObjectPersistenceQueryScanExample.java   
private static void FindBooksPricedLessThanSpecifiedValue(
        DynamoDBMapper mapper,
        String value) throws Exception {

    System.out.println("FindBooksPricedLessThanSpecifiedValue: Scan ProductCatalog.");

    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
    scanExpression.addFilterCondition("Price", 
            new Condition()
               .withComparisonOperator(ComparisonOperator.LT)
               .withAttributeValueList(new AttributeValue().withN(value)));
    scanExpression.addFilterCondition("ProductCategory", 
            new Condition()
                .withComparisonOperator(ComparisonOperator.EQ)
                .withAttributeValueList(new AttributeValue().withS("Book")));
    List<Book> scanResult = mapper.scan(Book.class, scanExpression);

    for (Book book : scanResult) {
        System.out.println(book);
    }
}
项目:spring-data-dynamodb    文件:DynamoDBEntityWithHashKeyOnlyCriteria.java   
public DynamoDBScanExpression buildScanExpression() {

        if (sort != null) {
            throw new UnsupportedOperationException("Sort not supported for scan expressions");
        }

        DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
        if (isHashKeySpecified()) {
            scanExpression.addFilterCondition(
                    getHashKeyAttributeName(),
                    createSingleValueCondition(getHashKeyPropertyName(), ComparisonOperator.EQ, getHashKeyAttributeValue(),
                            getHashKeyAttributeValue().getClass(), true));
        }

        for (Map.Entry<String, List<Condition>> conditionEntry : attributeConditions.entrySet()) {
            for (Condition condition : conditionEntry.getValue()) {
                scanExpression.addFilterCondition(conditionEntry.getKey(), condition);
            }
        }
        return scanExpression;
    }
项目:spring-data-dynamodb    文件:AbstractDynamoDBQueryCriteria.java   
protected List<Condition> getHashKeyConditions() {
    List<Condition> hashKeyConditions = null;
    if (isApplicableForGlobalSecondaryIndex()
            && entityInformation.getGlobalSecondaryIndexNamesByPropertyName().keySet().contains(getHashKeyPropertyName())) {
        hashKeyConditions = getHashKeyAttributeValue() == null ? null : Arrays.asList(createSingleValueCondition(
                getHashKeyPropertyName(), ComparisonOperator.EQ, getHashKeyAttributeValue(), getHashKeyAttributeValue()
                        .getClass(), true));
        if (hashKeyConditions == null) {
            if (attributeConditions.containsKey(getHashKeyAttributeName())) {
                hashKeyConditions = attributeConditions.get(getHashKeyAttributeName());
            }

        }

    }
    return hashKeyConditions;
}
项目:spring-data-dynamodb    文件:AbstractDynamoDBQueryCriteria.java   
protected Condition createSingleValueCondition(String propertyName, ComparisonOperator comparisonOperator, Object o,
        Class<?> propertyType, boolean alreadyMarshalledIfRequired) {

    Assert.notNull(o, "Creating conditions on null property values not supported: please specify a value for '"
            + propertyName + "'");

    Object attributeValue = !alreadyMarshalledIfRequired ? getPropertyAttributeValue(propertyName, o) : o;

    boolean marshalled = !alreadyMarshalledIfRequired && attributeValue != o
            && !entityInformation.isCompositeHashAndRangeKeyProperty(propertyName);

    Class<?> targetPropertyType = marshalled ? String.class : propertyType;
    List<AttributeValue> attributeValueList = new ArrayList<AttributeValue>();
    attributeValueList = addAttributeValue(attributeValueList, attributeValue, propertyName, targetPropertyType, true);
    return new Condition().withComparisonOperator(comparisonOperator).withAttributeValueList(attributeValueList);

}
项目:spring-data-dynamodb    文件:AbstractDynamoDBQueryCriteria.java   
protected Condition createCollectionCondition(String propertyName, ComparisonOperator comparisonOperator, Iterable<?> o,
        Class<?> propertyType) {

    Assert.notNull(o, "Creating conditions on null property values not supported: please specify a value for '"
            + propertyName + "'");
    List<AttributeValue> attributeValueList = new ArrayList<AttributeValue>();
    boolean marshalled = false;
    for (Object object : o) {
        Object attributeValue = getPropertyAttributeValue(propertyName, object);
        if (attributeValue != null) {
            marshalled = attributeValue != object && !entityInformation.isCompositeHashAndRangeKeyProperty(propertyName);
        }
        Class<?> targetPropertyType = marshalled ? String.class : propertyType;
        attributeValueList = addAttributeValue(attributeValueList, attributeValue, propertyName, targetPropertyType, false);

    }

    return new Condition().withComparisonOperator(comparisonOperator).withAttributeValueList(attributeValueList);

}
项目:spring-data-dynamodb    文件:DynamoDBEntityWithHashAndRangeKeyCriteria.java   
public DynamoDBScanExpression buildScanExpression() {

        if (sort != null) {
            throw new UnsupportedOperationException("Sort not supported for scan expressions");
        }
        DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
        if (isHashKeySpecified()) {
            scanExpression.addFilterCondition(
                    getHashKeyAttributeName(),
                    createSingleValueCondition(getHashKeyPropertyName(), ComparisonOperator.EQ, getHashKeyAttributeValue(),
                            getHashKeyAttributeValue().getClass(), true));
        }
        if (isRangeKeySpecified()) {
            scanExpression.addFilterCondition(
                    getRangeKeyAttributeName(),
                    createSingleValueCondition(getRangeKeyPropertyName(), ComparisonOperator.EQ, getRangeKeyAttributeValue(),
                            getRangeKeyAttributeValue().getClass(), true));
        }
        for (Map.Entry<String, List<Condition>> conditionEntry : attributeConditions.entrySet()) {
            for (Condition condition : conditionEntry.getValue()) {
                scanExpression.addFilterCondition(conditionEntry.getKey(), condition);
            }
        }
        return scanExpression;
    }
项目:spring-data-dynamodb    文件:DynamoDBEntityWithHashAndRangeKeyCriteria.java   
@SuppressWarnings("unchecked")
@Override
public DynamoDBQueryCriteria<T, ID> withPropertyEquals(String propertyName, Object value, Class<?> propertyType) {
    if (isHashKeyProperty(propertyName)) {
        return withHashKeyEquals(value);
    } else if (isRangeKeyProperty(propertyName)) {
        return withRangeKeyEquals(value);
    } else if (entityInformation.isCompositeHashAndRangeKeyProperty(propertyName)) {
        Assert.notNull(value,
                "Creating conditions on null composite id properties not supported: please specify a value for '"
                        + propertyName + "'");
        Object hashKey = entityInformation.getHashKey((ID) value);
        Object rangeKey = entityInformation.getRangeKey((ID) value);
        if (hashKey != null) {
            withHashKeyEquals(hashKey);
        }
        if (rangeKey != null) {
            withRangeKeyEquals(rangeKey);
        }
        return this;
    } else {
        Condition condition = createSingleValueCondition(propertyName, ComparisonOperator.EQ, value, propertyType, false);
        return withCondition(propertyName, condition);
    }

}
项目:tweetamo    文件:PersistentStore.java   
public ScanResult getSince(long timestamp, int limit) throws Exception {
    try {
        Condition scanFilterCondition = new Condition()
                .withComparisonOperator(ComparisonOperator.GT.toString())
                .withAttributeValueList(
                        new AttributeValue().withN(Long.toString(timestamp)));
        Map<String, Condition> conditions = new HashMap<String, Condition>();
        conditions.put(COL_CREATEDAT, scanFilterCondition);

        ScanRequest scanRequest = new ScanRequest()
                .withTableName(TABLE_NAME)
                .withScanFilter(conditions)
                .withLimit(limit)
                .withAttributesToGet(
                        Arrays.asList(COL_ID, COL_CREATEDAT, COL_LAT,
                                COL_LONG, COL_SCREENNAME, COL_TEXT));

        return dynamoDB.scan(scanRequest);
    } catch (Exception e) {
        handleException(e);
    }

    return null;
}
项目:bibrarian    文件:RefsITCase.java   
/**
 * Refs can index and retrieve.
 * @throws Exception If some problem inside
 */
@Test
public void addsAndFetches() throws Exception {
    final Refs refs = new Refs(this.dynamo.region());
    final String name = "test10";
    final String alpha = "alpha:124";
    refs.put(name, alpha);
    refs.put(name, "alpha:899");
    refs.put(name, "beta:600");
    MatcherAssert.assertThat(
        refs.forward(
            name,
            Arrays.asList(
                new Condition()
                    .withComparisonOperator(ComparisonOperator.BEGINS_WITH)
                    .withAttributeValueList(new AttributeValue("alpha:"))
            )
        ),
        Matchers.allOf(
            Matchers.<String>iterableWithSize(2),
            Matchers.hasItem(alpha)
        )
    );
}
项目:cloudata    文件:DynamodbDataStore.java   
public void addRangeKeyCondition(T matcher, Map<String, Condition> keyConditions) {
  AttributeValue rangeKey = null;
  ComparisonOperator comparisonOperator = ComparisonOperator.EQ;

  if (!hasRangeKey()) {
    // We supply the dummy range-key, just for potential speed
    rangeKey = toAttributeValue(EMPTY_RANGE_KEY);
  } else {
    RangeSpecifier spec = buildRangeKey(matcher);
    if (spec != null) {
      if (spec.exact != null) {
        rangeKey = spec.exact;
      } else if (spec.prefix != null) {
        comparisonOperator = ComparisonOperator.BEGINS_WITH;
        rangeKey = spec.prefix;
      } else {
        throw new IllegalStateException();
      }
    }
  }

  if (rangeKey != null) {
    keyConditions.put(FIELD_RANGE_KEY, new Condition().withComparisonOperator(comparisonOperator)
        .withAttributeValueList(rangeKey));
  }
}
项目:openhab1-addons    文件:DynamoDBPersistenceService.java   
private Condition constructTimeCondition(FilterCriteria filter) {
    boolean hasBegin = filter.getBeginDate() != null;
    boolean hasEnd = filter.getEndDate() != null;

    final Condition timeCondition;
    if (!hasBegin && !hasEnd) {
        timeCondition = null;
    } else if (!hasBegin && hasEnd) {
        timeCondition = new Condition().withComparisonOperator(ComparisonOperator.LE).withAttributeValueList(
                new AttributeValue().withS(AbstractDynamoDBItem.DATEFORMATTER.format(filter.getEndDate())));
    } else if (hasBegin && !hasEnd) {
        timeCondition = new Condition().withComparisonOperator(ComparisonOperator.GE).withAttributeValueList(
                new AttributeValue().withS(AbstractDynamoDBItem.DATEFORMATTER.format(filter.getBeginDate())));
    } else {
        timeCondition = new Condition().withComparisonOperator(ComparisonOperator.BETWEEN).withAttributeValueList(
                new AttributeValue().withS(AbstractDynamoDBItem.DATEFORMATTER.format(filter.getBeginDate())),
                new AttributeValue().withS(AbstractDynamoDBItem.DATEFORMATTER.format(filter.getEndDate())));
    }
    return timeCondition;
}
项目:jcabi-dynamo    文件:Conditions.java   
@Override
public String toString() {
    final Collection<String> terms =
        new ArrayList<String>(this.conds.size());
    for (final Map.Entry<String, Condition> cond : this.conds.entrySet()) {
        terms.add(
            String.format(
                "%s %s %s",
                cond.getKey(),
                cond.getValue().getComparisonOperator(),
                cond.getValue().getAttributeValueList()
            )
        );
    }
    return Joiner.on(" AND ").join(terms);
}
项目:bibrarian    文件:Refs.java   
/**
 * Forward search.
 * @param left Left
 * @param cnds Conditions
 * @return Rights
 */
public Iterable<String> forward(final String left,
    final Iterable<Condition> cnds) {
    Frame frame = this.region.table(Refs.TABLE)
        .frame()
        .through(new QueryValve().withScanIndexForward(false))
        .where(Refs.HASH, left);
    for (final Condition cnd : cnds) {
        frame = frame.where(Refs.RANGE, cnd);
    }
    return Iterables.transform(
        frame,
        new Function<Item, String>() {
            @Override
            public String apply(final Item input) {
                try {
                    return input.get(Refs.RANGE).getS();
                } catch (final IOException ex) {
                    throw new IllegalStateException(ex);
                }
            }
        }
    );
}
项目:rehttp    文件:DyStatus.java   
@Override
public Collection<Iterable<Directive>> failures(final long after) {
    return new Mapped<>(
        this.table()
            .frame()
            .through(
                new QueryValve()
                    .withIndexName("failures")
                    .withAttributesToGet(
                        "url", "time", "code", "attempts", "when", "ttl"
                    )
                    .withLimit(Tv.TWENTY)
                    .withConsistentRead(false)
                    .withScanIndexForward(false)
            )
            .where("failed_url", Conditions.equalTo(this.url))
            .where(
                "time",
                new Condition()
                    .withComparisonOperator(ComparisonOperator.LT)
                    .withAttributeValueList(
                        new AttributeValue().withN(
                            Long.toString(after)
                        )
                    )
            ),
        item -> DyStatus.xembly(item, false)
    );
}
项目:rehttp    文件:DyStatus.java   
@Override
public Collection<Iterable<Directive>> history(final long after) {
    return new Mapped<>(
        this.table()
            .frame()
            .through(
                new QueryValve()
                    .withAttributesToGet(
                        "url", "time", "code", "attempts", "when", "ttl"
                    )
                    .withLimit(Tv.TEN)
                    .withScanIndexForward(false)
            )
            .where("url", Conditions.equalTo(this.url))
            .where(
                "time",
                new Condition()
                    .withComparisonOperator(ComparisonOperator.LT)
                    .withAttributeValueList(
                        new AttributeValue().withN(
                            Long.toString(after)
                        )
                    )
            ),
        item -> DyStatus.xembly(item, false)
    );
}
项目:CloudPrime    文件:DynamoEntry.java   
public static DynamoEntry getFromMSS(String parameter)
{
    dynamoDB = new AmazonDynamoDBClient(new ProfileCredentialsProvider().getCredentials());
    dynamoDB.setRegion(Region.getRegion(Regions.EU_WEST_1));

    HashMap<String, Condition> keyConditions = new HashMap<String, Condition>();
    keyConditions.put("Parameter", new Condition().withComparisonOperator(ComparisonOperator.EQ)
            .withAttributeValueList(new AttributeValue(parameter)));

    QueryRequest queryRequest = new QueryRequest();
    queryRequest.setKeyConditions(keyConditions);
    queryRequest.withTableName("MSS");

    QueryResult result = dynamoDB.query(queryRequest);
    //se houver um pedido ja tratado no MSS getCount > 0, caso contrario nao existe
    if(result.getCount() == 0)
        return null;
    else
    {
        //vamos buscar o rank
        Map<String, AttributeValue> queryResult = result.getItems().get(0);
        String rank = "";
        boolean runningState = false;

        for (Map.Entry<String, AttributeValue> entry  : queryResult.entrySet()) 
        {
            if(entry.getKey().equals("Rank"))
                rank = entry.getValue().getN();
            else if(entry.getKey().equals("Running"))
                runningState = entry.getValue().getBOOL();
        }
        DynamoEntry rankResult = new DynamoEntry(new BigInteger(rank), runningState);           
        return rankResult;
    }
}
项目:CloudPrime    文件:InstTool.java   
public static synchronized QueryResult getEntryDynamo(String parameter, AmazonDynamoDBClient dynamoDB) {
    HashMap<String, Condition> keyConditions = new HashMap<String, Condition>();
    keyConditions.put("Parameter", new Condition().withComparisonOperator(ComparisonOperator.EQ)
            .withAttributeValueList(new AttributeValue(parameter)));

    QueryRequest queryRequest = new QueryRequest();
    queryRequest.setKeyConditions(keyConditions);
    queryRequest.withTableName("MSS");

    QueryResult result = dynamoDB.query(queryRequest);
    return result;
}
项目:elo-api    文件:GenericDynamoDbRangeDao.java   
public Collection<T> findByPartition(String bucketName) {
    PaginatedQueryList<T> result = this.tableMapper.query(
            new DynamoDBQueryExpression<T>().withRangeKeyCondition(tableMapper.rangeKey().name(),
                    new Condition()
                            .withComparisonOperator(ComparisonOperator.EQ)
                            .withAttributeValueList(new AttributeValue(bucketName))));
    return result;
}
项目:PlatePicks-Android    文件:NoSQLTableFood.java   
public boolean executeOperation() {
    final FoodDO itemToFind = new FoodDO();
    itemToFind.setFoodId(getDemoPartitionValue());

    final Condition rangeKeyCondition = new Condition()
        .withComparisonOperator(ComparisonOperator.LT.toString())
        .withAttributeValueList(new AttributeValue().withS(DEMO_SORT_VALUE));

    // Use an expression names Map to avoid the potential for attribute names
    // colliding with DynamoDB reserved words.
    final Map <String, String> filterExpressionAttributeNames = new HashMap<>();
    filterExpressionAttributeNames.put("#dislike", DEMO_PRIMARY_CONDITION_KEY);

    final Map<String, AttributeValue> filterExpressionAttributeValues = new HashMap<>();
    filterExpressionAttributeValues.put(":Mindislike",
        new AttributeValue().withN(DEMO_PRIMARY_CONDITION_VALUE));

    final DynamoDBQueryExpression<FoodDO> queryExpression = new DynamoDBQueryExpression<FoodDO>()
        .withHashKeyValues(itemToFind)
        .withRangeKeyCondition(DEMO_SORT_KEY, rangeKeyCondition)
        .withFilterExpression("#dislike > :Mindislike")
        .withExpressionAttributeNames(filterExpressionAttributeNames)
        .withExpressionAttributeValues(filterExpressionAttributeValues)
        .withConsistentRead(false)
        .withLimit(RESULTS_PER_RESULT_GROUP);

    results = mapper.query(FoodDO.class, queryExpression);
    if (results != null) {
        resultsIterator = results.iterator();
        if (resultsIterator.hasNext()) {
            return true;
        }
    }
    return false;
}