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

项目: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;
}
项目: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"));
}
项目:dynamodb-janusgraph-storage-backend    文件:SingleExpectedAttributeValueBuilder.java   
private void addExpectedValueIfPresent(final StaticBuffer column, final Map<String, ExpectedAttributeValue> expectedValueMap) {
    final String dynamoDbColumn = encodeKeyBuffer(column);

    if (expectedValueMap.containsKey(dynamoDbColumn)) {
        return;
    }

    if (transaction.contains(store, key, column)) {
        final StaticBuffer expectedValue = transaction.get(store, key, column);
        final ExpectedAttributeValue expectedAttributeValue;
        if (expectedValue == null) {
            expectedAttributeValue = new ExpectedAttributeValue().withExists(false);
        } else {
            final AttributeValue attributeValue = encodeValue(expectedValue);
            expectedAttributeValue = new ExpectedAttributeValue().withValue(attributeValue)
                                                                 .withComparisonOperator(ComparisonOperator.EQ);
        }
        expectedValueMap.put(dynamoDbColumn, expectedAttributeValue);
    }
}
项目: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;
}
项目:amazon-kinesis-aggregators    文件:StreamAggregator.java   
/**
 * Return the stored value for a label and date value at the configured time
 * granularity
 * 
 * @param label
 *            The Aggregated Label Value to get data for
 * @param dateValue
 *            The Date Value to obtain data from
 * @param h
 *            The Time Horizon to query
 * @return
 */
public List<Map<String, AttributeValue>> queryValue(String label,
        Date dateValue, ComparisonOperator comp) throws Exception {
    if (!(this.dataStore instanceof DynamoDataStore)) {
        throw new Exception(
                "Unable to Query by Date unless Data Store is Dynamo DB");
    }

    if (comp != null && comp.equals(ComparisonOperator.BETWEEN)) {
        throw new InvalidConfigurationException(
                "Between Operator Not Supported");
    }

    return ((DynamoDataStore) this.dataStore).queryEngine().queryByKey(
            label, dateValue, comp);
}
项目: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());
    }
}
项目:micro-genie    文件:EventHandlers.java   
@Override
public void handle(Event event) {

    final EventData eventData = event.getEventData();

    try {

        final String bookId = new String(eventData.getData().get("bookId").toString());
        final String userId = new String(eventData.getData().get("userId").toString());

        final Book book = this.repository.get(Key.create(bookId));
        if(Book.CHECKED_OUT_BY_NOBODY.equals(book.getCheckedOutBy())){
            book.setCheckedOutBy(userId);
            this.repository.saveIf(book,ComparisonOperator.EQ, "checkedOutBy", Book.CHECKED_OUT_BY_NOBODY);
            LOGGER.info("=========================== SAVING BOOK CHECKOUT REQUEST ===========================");
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }



}
项目:gora    文件:TestDynamoDBNativeStore.java   
/**
 * Tests deleting items using a query
 */
@Override
public void assertTestDeleteByQueryDataStore() {
  try {
    log.info("test method: TestDeleteByQuery using DynamoDB store.");
    DynamoDBKey<Long, String> dKey = new DynamoDBKey<>();
    dKey.setHashKey(100L);
    dKey.setRangeKey("10/10/1880");
    Person p1 = buildPerson(dKey.getHashKey(), dKey.getRangeKey().toString(),
        "John", "Doe", "Peru", "Brazil", "Ecuador");
    dataStore.put(dKey, p1);
    dKey.setRangeKey("11/10/1707");
    Person p2 = buildPerson(dKey.getHashKey(), dKey.getRangeKey().toString(),
        "Juan", "Perez", "Germany", "USA", "Scotland");
    dataStore.put(dKey, p2);
    DynamoDBQuery.setScanCompOp(ComparisonOperator.LE);
    DynamoDBQuery.setType(DynamoDBQuery.SCAN_QUERY);
    Query<DynamoDBKey, Person> query = new DynamoDBQuery<DynamoDBKey, Person>();
    query.setKey(dKey);
    log.info("Number of records deleted: " + dataStore.deleteByQuery(query));
  } catch (Exception e) {
    log.error("Error while running test: TestDeleteByQuery", e.getMessage());
    throw new RuntimeException(e);
  }
}
项目:gora    文件:TestDynamoDBNativeStore.java   
/**
 * Method to query the data store
 */
@Override
public void assertTestQueryDataStore() {
  log.info("test method: testQuery using DynamoDB store.");
  try {
    DynamoDBKey<String, String> dKey = new DynamoDBKey<String, String>();
    dKey.setHashKey("Peru");
    DynamoDBQuery.setScanCompOp(ComparisonOperator.LE);
    DynamoDBQuery.setType(DynamoDBQuery.SCAN_QUERY);
    Query<DynamoDBKey, Person> query = new DynamoDBQuery<DynamoDBKey, Person>();
    query.setKey(dKey);
    Result<DynamoDBKey, Person> queryResult = dataStore.execute(query);
    processQueryResult(queryResult);
  } catch (Exception e) {
    log.error("error in test method: testQuery.", e.getMessage());
    throw new RuntimeException(e);
  }
}
项目:gora    文件:TestDynamoDBNativeStore.java   
/**
 * Method to query items into the data store
 */
@Override
public void assertTestQueryKeyRange() {
  log.info("test method: testQueryKeyRange using specific data store.");
  try {
    DynamoDBKey<String, String> dKey = new DynamoDBKey<String, String>();
    DynamoDBKey<String, String> startKey = new DynamoDBKey<String, String>();
    DynamoDBKey<String, String> endKey = new DynamoDBKey<String, String>();
    dKey.setHashKey("Peru");
    startKey.setRangeKey("01/01/1700");
    endKey.setRangeKey("31/12/1900");
    DynamoDBQuery.setRangeCompOp(ComparisonOperator.BETWEEN);
    DynamoDBQuery.setType(DynamoDBQuery.RANGE_QUERY);
    Query<DynamoDBKey, Person> query = new DynamoDBQuery<DynamoDBKey, Person>();
    query.setKey(dKey);
    query.setStartKey(startKey);
    query.setEndKey(endKey);
    Result<DynamoDBKey, Person> queryResult = dataStore.execute(query);
    processQueryResult(queryResult);
  } catch (Exception e) {
    log.error("error in test method: testQueryKeyRange.", e.getMessage());
    throw new RuntimeException(e);
  }
}
项目: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 findRepliesInLast15DaysWithConfig(String forumName, String threadSubject) {

        long twoWeeksAgoMilli = (new Date()).getTime() - (15L*24L*60L*60L*1000L);
        Date twoWeeksAgo = new Date();
        twoWeeksAgo.setTime(twoWeeksAgoMilli);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
        String twoWeeksAgoStr = df.format(twoWeeksAgo);

        Condition rangeKeyCondition = new Condition()
            .withComparisonOperator(ComparisonOperator.GT.toString())
            .withAttributeValueList(new AttributeValue().withS(twoWeeksAgoStr));

        Map<String, Condition> keyConditions = makeReplyKeyConditions(forumName, threadSubject);
        keyConditions.put("ReplyDateTime", rangeKeyCondition);

        QueryRequest queryRequest = new QueryRequest().withTableName(tableName)
            .withKeyConditions(keyConditions)
            .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);
    }
}
项目:aws-dynamodb-examples    文件:ObjectPersistenceQueryScanExample.java   
private static void FindBicyclesOfSpecificTypeWithMultipleThreads(
        DynamoDBMapper mapper, 
        int numberOfThreads,
        String bicycleType) throws Exception {

    System.out.println("FindBicyclesOfSpecificTypeWithMultipleThreads: Scan ProductCatalog With Multiple Threads.");

    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
    scanExpression.addFilterCondition("ProductCategory", 
            new Condition()
                .withComparisonOperator(ComparisonOperator.EQ)
                .withAttributeValueList(new AttributeValue().withS("Bicycle")));
    scanExpression.addFilterCondition("BicycleType", 
            new Condition()
                .withComparisonOperator(ComparisonOperator.EQ)
                .withAttributeValueList(new AttributeValue().withS(bicycleType)));
    List<Bicycle> scanResult = mapper.parallelScan(Bicycle.class, scanExpression, numberOfThreads);
    for (Bicycle bicycle : scanResult) {
        System.out.println(bicycle);
    }
}
项目: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   
@SuppressWarnings("unchecked")
@Override
public DynamoDBQueryCriteria<T, ID> withSingleValueCriteria(String propertyName, ComparisonOperator comparisonOperator,
        Object value, Class<?> propertyType) {

    if (entityInformation.isCompositeHashAndRangeKeyProperty(propertyName)) {
        checkComparisonOperatorPermittedForCompositeHashAndRangeKey(comparisonOperator);
        Object hashKey = entityInformation.getHashKey((ID) value);
        Object rangeKey = entityInformation.getRangeKey((ID) value);
        if (hashKey != null) {
            withSingleValueCriteria(getHashKeyPropertyName(), comparisonOperator, hashKey, hashKey.getClass());
        }
        if (rangeKey != null) {
            withSingleValueCriteria(getRangeKeyPropertyName(), comparisonOperator, rangeKey, rangeKey.getClass());
        }
        return this;
    } else {
        return super.withSingleValueCriteria(propertyName, comparisonOperator, value, propertyType);
    }
}
项目: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);
    }

}
项目: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;
}
项目: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;
}
项目:cloudata    文件:DynamodbDataStore.java   
public void addFilter(Map<String, ExpectedAttributeValue> expected, FieldDescriptor fieldDescriptor,
    Object fieldValue) throws DataStoreException {

  AttributeMapping attributeMapping = getAttributeMapping(fieldDescriptor);
  if (attributeMapping.isHashKey || attributeMapping.isRangeKey) {
    // Skip; we assume that the caller will use the filter
    return;
  }

  if (!attributeMapping.isFilterable) {
    throw new DataStoreException("Field not extracted: " + fieldDescriptor.getName());
  }

  AttributeValue attributeValue = attributeMapping.buildAttributeValue(fieldValue);
  expected.put(attributeMapping.attributeName,
      new ExpectedAttributeValue(attributeValue).withComparisonOperator(ComparisonOperator.EQ));
}
项目: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));
  }
}
项目: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)
        )
    );
}
项目: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)
    );
}