Example usage for com.amazonaws.services.dynamodbv2.datamodeling DynamoDBQueryExpression setRangeKeyConditions

List of usage examples for com.amazonaws.services.dynamodbv2.datamodeling DynamoDBQueryExpression setRangeKeyConditions

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.datamodeling DynamoDBQueryExpression setRangeKeyConditions.

Prototype

public void setRangeKeyConditions(Map<String, Condition> rangeKeyConditions) 

Source Link

Document

Sets the range key condition for this query.

Usage

From source file:com.alertlogic.aws.kinesis.test1.webserver.GetCountsServlet.java

License:Open Source License

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    MultiMap<String> params = new MultiMap<>();
    UrlEncoded.decodeTo(req.getQueryString(), params, "UTF-8");

    // We need both parameters to properly query for counts
    if (!params.containsKey(PARAMETER_RESOURCE) || !params.containsKey(PARAMETER_RANGE_IN_SECONDS)) {
        resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return;/*from   w ww  . ja v  a  2s  .co m*/
    }

    // Parse query string as a single integer - the number of seconds since "now" to query for new counts
    String resource = params.getString(PARAMETER_RESOURCE);
    int rangeInSeconds = Integer.parseInt(params.getString(PARAMETER_RANGE_IN_SECONDS));

    Calendar c = Calendar.getInstance();
    c.add(Calendar.SECOND, -1 * rangeInSeconds);
    Date startTime = c.getTime();
    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("Querying for counts of resource %s since %s", resource,
                DATE_FORMATTER.get().format(startTime)));
    }

    DynamoDBQueryExpression<HttpReferrerPairsCount> query = new DynamoDBQueryExpression<>();
    HttpReferrerPairsCount hashKey = new HttpReferrerPairsCount();
    hashKey.setResource(resource);
    query.setHashKeyValues(hashKey);

    Condition recentUpdates = new Condition().withComparisonOperator(ComparisonOperator.GT)
            .withAttributeValueList(new AttributeValue().withS(DATE_FORMATTER.get().format(startTime)));
    query.setRangeKeyConditions(Collections.singletonMap("timestamp", recentUpdates));

    List<HttpReferrerPairsCount> counts = mapper.query(HttpReferrerPairsCount.class, query);

    // Return the counts as JSON
    resp.setContentType("application/json");
    resp.setStatus(HttpServletResponse.SC_OK);
    JSON.writeValue(resp.getWriter(), counts);
}

From source file:com.kinesis.datavis.servlet.GetBidRqCountsServlet.java

License:Open Source License

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    MultiMap<String> params = new MultiMap<>();
    UrlEncoded.decodeTo(req.getQueryString(), params, "UTF-8");

    // We need both parameters to properly query for counts
    if (!params.containsKey(PARAMETER_RESOURCE) || !params.containsKey(PARAMETER_RANGE_IN_SECONDS)) {
        resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return;//from w  w w  . jav a  2 s .  c o  m
    }

    // Parse query string as a single integer - the number of seconds since "now" to query for new counts
    String resource = params.getString(PARAMETER_RESOURCE);
    int rangeInSeconds = Integer.parseInt(params.getString(PARAMETER_RANGE_IN_SECONDS));

    Calendar c = Calendar.getInstance();
    c.add(Calendar.SECOND, -1 * rangeInSeconds);
    Date startTime = c.getTime();
    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("Querying for counts of resource %s since %s", resource,
                DATE_FORMATTER.get().format(startTime)));
    }

    DynamoDBQueryExpression<BidRequestCount> query = new DynamoDBQueryExpression<>();

    BidRequestCount hashKey = new BidRequestCount();
    hashKey.setHashKey(Ticker.getInstance().hashKey());

    query.setHashKeyValues(hashKey);

    Condition recentUpdates = new Condition().withComparisonOperator(ComparisonOperator.GT)
            .withAttributeValueList(new AttributeValue().withS(DATE_FORMATTER.get().format(startTime)));
    //        Condition attrFilter =
    //                new Condition().
    //                        withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(new AttributeValue().withS(resource));

    query.setRangeKeyConditions(Collections.singletonMap("timestamp", recentUpdates));
    //        query.setQueryFilter(Collections.singletonMap("wh", attrFilter));

    List<BidRequestCount> counts = mapper.query(BidRequestCount.class, query);

    //        System.out.println(counts.size());
    // Return the counts as JSON
    resp.setContentType("application/json");
    resp.setStatus(HttpServletResponse.SC_OK);
    JSON.writeValue(resp.getWriter(), counts);
}

From source file:eu.roschi.obdkinesis.webserver.GetCountsServlet.java

License:Open Source License

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    MultiMap<String> params = new MultiMap<>();
    UrlEncoded.decodeTo(req.getQueryString(), params, "UTF-8");

    // We need both parameters to properly query for counts
    if (!params.containsKey(PARAMETER_RESOURCE) || !params.containsKey(PARAMETER_RANGE_IN_SECONDS)) {
        resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return;/* w  w w.j av  a2  s  .c om*/
    }

    // Parse query string as a single integer - the number of seconds since "now" to query for new counts
    String resource = params.getString(PARAMETER_RESOURCE);
    int rangeInSeconds = Integer.parseInt(params.getString(PARAMETER_RANGE_IN_SECONDS));

    Calendar c = Calendar.getInstance();
    c.add(Calendar.SECOND, -1 * rangeInSeconds);
    Date startTime = c.getTime();
    //if (LOG.isDebugEnabled()) {
    LOG.debug(String.format("Querying for counts of resource %s since %s", resource,
            DATE_FORMATTER.get().format(startTime)));
    //}

    DynamoDBQueryExpression<HttpReferrerPairsCount> query = new DynamoDBQueryExpression<>();
    HttpReferrerPairsCount hashKey = new HttpReferrerPairsCount();
    hashKey.setResource(resource);
    query.setHashKeyValues(hashKey);

    Condition recentUpdates = new Condition().withComparisonOperator(ComparisonOperator.GT)
            .withAttributeValueList(new AttributeValue().withS(DATE_FORMATTER.get().format(startTime)));
    query.setRangeKeyConditions(Collections.singletonMap("timestamp", recentUpdates));

    List<HttpReferrerPairsCount> counts = mapper.query(HttpReferrerPairsCount.class, query);

    // Return the counts as JSON
    resp.setContentType("application/json");
    resp.setStatus(HttpServletResponse.SC_OK);
    JSON.writeValue(resp.getWriter(), counts);
}

From source file:org.openhab.persistence.dynamodb.internal.DynamoDBPersistenceService.java

License:Open Source License

private Condition maybeAddTimeFilter(final DynamoDBQueryExpression<DynamoDBItem<?>> queryExpression,
        final FilterCriteria filter) {
    final Condition timeCondition = constructTimeCondition(filter);
    if (timeCondition != null) {
        queryExpression.setRangeKeyConditions(
                Collections.singletonMap(DynamoDBItem.ATTRIBUTE_NAME_TIMEUTC, timeCondition));
    }//  ww w.  j  a  v  a  2  s .  c  o  m
    return timeCondition;
}