List of usage examples for com.amazonaws.services.dynamodbv2.datamodeling DynamoDBQueryExpression DynamoDBQueryExpression
DynamoDBQueryExpression
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 w w .j a va2 s . 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 ww . j ava 2 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<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:com.kirana.dao.OrderDaoImpl.java
@Override public List<Order> getOrderByShopId(long shopId) throws Exception { DynamoDBMapper mapper = new DynamoDBMapper(dbClient); Date startTime = new Date(0L); SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); dateFormatter.setTimeZone(TimeZone.getTimeZone("UTC")); String startTimeStr = dateFormatter.format(startTime); Condition rangeKeyCondition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString()) .withAttributeValueList(new AttributeValue().withS(startTimeStr)); DynamoDBQueryExpression<Order> queryExpression = new DynamoDBQueryExpression<Order>() .withHashKeyValues(new Order(shopId)).withRangeKeyCondition("created_at", rangeKeyCondition); queryExpression.setConsistentRead(false); return mapper.query(Order.class, queryExpression); }
From source file:com.kirana.dao.OrderDaoImpl.java
@Override public List<Order> getOrderBetween(long id, String FromDate, String ToDate) throws Exception { DynamoDBMapper mapper = new DynamoDBMapper(dbClient); Condition rangeKeyCondition = new Condition().withComparisonOperator(ComparisonOperator.BETWEEN.toString()) .withAttributeValueList(new AttributeValue().withS(FromDate), new AttributeValue().withS(ToDate)); DynamoDBQueryExpression<Order> queryExpression = new DynamoDBQueryExpression<Order>() .withHashKeyValues(new Order(id)).withRangeKeyCondition("created_at", rangeKeyCondition); queryExpression.setConsistentRead(false); List<Order> latestReplies = mapper.query(Order.class, queryExpression); return latestReplies; }
From source file:com.kirana.dao.OrderDaoImpl.java
@Override public Order getOrderByCreatedAt(long id, String createdAt) throws Exception { DynamoDBMapper mapper = new DynamoDBMapper(dbClient); log.info("id : " + id + " createdat:" + createdAt); Condition rangeKeyCondition = new Condition().withComparisonOperator(ComparisonOperator.EQ.toString()) .withAttributeValueList(new AttributeValue().withS(createdAt)); DynamoDBQueryExpression<Order> queryExpression = new DynamoDBQueryExpression<Order>() .withHashKeyValues(new Order(id)).withRangeKeyCondition("created_at", rangeKeyCondition); queryExpression.setConsistentRead(false); PaginatedQueryList list = mapper.query(Order.class, queryExpression); if (list != null && !list.isEmpty()) return (Order) list.get(0); else//from w ww . j av a2 s . co m return null; // return mapper.query(Order.class, queryExpression).get(1); // return mapper.load(Order.class,id,createdAt); }
From source file:com.makariev.dynamodb.preferences.UserPreferenceObjectMapperService.java
License:Open Source License
private List<UserPreference> queryByNames(String firstName, String lastName) { DynamoDBQueryExpression<UserPreference> dynamoDBQueryExpression = new DynamoDBQueryExpression<>(); dynamoDBQueryExpression.withIndexName(UserPreference.NAME_INDEX); dynamoDBQueryExpression.withRangeKeyCondition("firstName", new Condition().withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue().withS(firstName))); dynamoDBQueryExpression.withRangeKeyCondition("lastName", new Condition().withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue().withS(lastName))); final List<UserPreference> list = mapper.query(UserPreference.class, dynamoDBQueryExpression); return list;/*from w w w. ja v a2 s .co m*/ }
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;// ww w . j a v 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<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
/** * Construct dynamodb query from filter// www. j a v a 2 s .c o m * * @param filter * @return DynamoDBQueryExpression corresponding to the given FilterCriteria */ private DynamoDBQueryExpression<DynamoDBItem<?>> createQueryExpression(FilterCriteria filter) { final DynamoDBStringItem itemHash = new DynamoDBStringItem(filter.getItemName(), null, null); final DynamoDBQueryExpression<DynamoDBItem<?>> queryExpression = new DynamoDBQueryExpression<DynamoDBItem<?>>() .withHashKeyValues(itemHash).withScanIndexForward(filter.getOrdering() == Ordering.ASCENDING) .withLimit(filter.getPageSize()); Condition timeFilter = maybeAddTimeFilter(queryExpression, filter); maybeAddStateFilter(filter, queryExpression); logger.debug("Querying: {} with {}", filter.getItemName(), timeFilter); return queryExpression; }
From source file:org.socialsignin.spring.data.dynamodb.repository.query.DynamoDBEntityWithHashAndRangeKeyCriteria.java
License:Apache License
public DynamoDBQueryExpression<T> buildQueryExpression() { DynamoDBQueryExpression<T> queryExpression = new DynamoDBQueryExpression<T>(); if (isHashKeySpecified()) { T hashKeyPrototype = entityInformation.getHashKeyPropotypeEntityForHashKey(getHashKeyPropertyValue()); queryExpression.withHashKeyValues(hashKeyPrototype); queryExpression.withRangeKeyConditions(new HashMap<String, Condition>()); }//w w w . java 2s . com if (isRangeKeySpecified() && !isApplicableForGlobalSecondaryIndex()) { Condition rangeKeyCondition = createSingleValueCondition(getRangeKeyPropertyName(), ComparisonOperator.EQ, getRangeKeyAttributeValue(), getRangeKeyAttributeValue().getClass(), true); queryExpression.withRangeKeyCondition(getRangeKeyAttributeName(), rangeKeyCondition); applySortIfSpecified(queryExpression, Arrays.asList(new String[] { getRangeKeyPropertyName() })); } else if (isOnlyASingleAttributeConditionAndItIsOnEitherRangeOrIndexRangeKey() || (isApplicableForGlobalSecondaryIndex())) { Entry<String, List<Condition>> singlePropertyConditions = propertyConditions.entrySet().iterator() .next(); List<String> allowedSortProperties = new ArrayList<String>(); for (Entry<String, List<Condition>> singlePropertyCondition : propertyConditions.entrySet()) { if (entityInformation.getGlobalSecondaryIndexNamesByPropertyName().keySet() .contains(singlePropertyCondition.getKey())) { allowedSortProperties.add(singlePropertyCondition.getKey()); } } if (allowedSortProperties.size() == 0) { allowedSortProperties.add(singlePropertyConditions.getKey()); } for (Entry<String, List<Condition>> singleAttributeConditions : attributeConditions.entrySet()) { for (Condition condition : singleAttributeConditions.getValue()) { queryExpression.withRangeKeyCondition(singleAttributeConditions.getKey(), condition); } } applySortIfSpecified(queryExpression, allowedSortProperties); if (getGlobalSecondaryIndexName() != null) { queryExpression.setIndexName(getGlobalSecondaryIndexName()); } } else { applySortIfSpecified(queryExpression, Arrays.asList(new String[] { getRangeKeyPropertyName() })); } return queryExpression; }