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

项目:spring-data-dynamodb    文件:DynamoDBEntityWithHashAndRangeKeyCriteria.java   
protected Query<Long> buildFinderCountQuery(DynamoDBOperations dynamoDBOperations,boolean pageQuery) {
    if (isApplicableForQuery()) {
        if (isApplicableForGlobalSecondaryIndex()) {
            String tableName = dynamoDBOperations.getOverriddenTableName(entityInformation.getDynamoDBTableName());
            QueryRequest queryRequest = buildQueryRequest(tableName, getGlobalSecondaryIndexName(),
                    getHashKeyAttributeName(), getRangeKeyAttributeName(), this.getRangeKeyPropertyName(),
                    getHashKeyConditions(), getRangeKeyConditions());
            return new QueryRequestCountQuery<T>(dynamoDBOperations,entityInformation.getJavaType(), queryRequest);

        } else {
            DynamoDBQueryExpression<T> queryExpression = buildQueryExpression();
            return new QueryExpressionCountQuery<T>(dynamoDBOperations, entityInformation.getJavaType(), queryExpression);

        }
    } else {
        return new ScanExpressionCountQuery<T>(dynamoDBOperations, clazz, buildScanExpression(),pageQuery);
    }
}
项目:strongbox    文件:GenericDynamoDBTest.java   
@Test
public void testDeleteSecretMaliciousResults() {
    QueryRequest request = constructQueryRequest(SECRET_NAME);

    // Result contains entries that do no match the filter in the request (i.e. items for secret2). So it should be
    // considered malicious.
    QueryResult maliciousResult = constructQueryResult(true);
    when(mockDynamoDBClient.query(request)).thenReturn(maliciousResult);

    // Call the delete secret method.
    boolean consideredMalicious = false;
    try {
        dynamoDB.delete(new SecretIdentifier(SECRET_NAME));
    } catch (PotentiallyMaliciousDataException e) {
        consideredMalicious = true;
    }
    assertTrue(consideredMalicious);

    // Verify nothing was actually deleted because the malicious check failed.
    verify(mockDynamoDBClient, times(1)).query(request);
    verify(mockDynamoDBClient, never()).deleteItem(tableName, constructKey(SECRET_NAME, 1));
    verify(mockDynamoDBClient, never()).deleteItem(tableName, constructKey(SECRET_NAME, 2));
    verify(mockDynamoDBClient, never()).deleteItem(tableName, constructKey(SECRET2_NAME, 1));
}
项目:AbacusUtil    文件:DynamoDBExecutor.java   
/**
 * 
 * @param targetClass <code>Map</code> or entity class with getter/setter method.
 * @param queryRequest
 * @return
 */
public <T> List<T> find(final Class<T> targetClass, final QueryRequest queryRequest) {
    final QueryResult queryResult = dynamoDB.query(queryRequest);
    final List<T> res = toList(targetClass, queryResult);

    if (N.notNullOrEmpty(queryResult.getLastEvaluatedKey()) && N.isNullOrEmpty(queryRequest.getExclusiveStartKey())) {
        final QueryRequest newQueryRequest = queryRequest.clone();
        QueryResult newQueryResult = queryResult;

        while (N.notNullOrEmpty(newQueryResult.getLastEvaluatedKey())) {
            newQueryRequest.setExclusiveStartKey(newQueryResult.getLastEvaluatedKey());
            newQueryResult = dynamoDB.query(newQueryRequest);
            res.addAll(toList(targetClass, newQueryResult));
        }
    }

    return res;
}
项目:AbacusUtil    文件:DynamoDBExecutor.java   
/**
 * 
 * @param targetClass
 * @param queryRequest
 * @return
 * @see #find(Class, QueryRequest)
 */
public DataSet query(final Class<?> targetClass, final QueryRequest queryRequest) {
    if (targetClass == null || Map.class.isAssignableFrom(targetClass)) {
        final QueryResult queryResult = dynamoDB.query(queryRequest);
        final List<Map<String, AttributeValue>> items = queryResult.getItems();

        if (N.notNullOrEmpty(queryResult.getLastEvaluatedKey()) && N.isNullOrEmpty(queryRequest.getExclusiveStartKey())) {
            final QueryRequest newQueryRequest = queryRequest.clone();
            QueryResult newQueryResult = queryResult;

            while (N.notNullOrEmpty(newQueryResult.getLastEvaluatedKey())) {
                newQueryRequest.setExclusiveStartKey(newQueryResult.getLastEvaluatedKey());
                newQueryResult = dynamoDB.query(newQueryRequest);
                items.addAll(newQueryResult.getItems());
            }
        }

        return extractData(items, 0, items.size());
    } else {
        return N.newDataSet(find(targetClass, queryRequest));
    }
}
项目:emr-dynamodb-connector    文件:DynamoDBClient.java   
public RetryResult<QueryResult> queryTable(
    String tableName, DynamoDBQueryFilter dynamoDBQueryFilter, Map<String, AttributeValue>
    exclusiveStartKey, long limit, Reporter reporter) {
  final QueryRequest queryRequest = new QueryRequest()
      .withTableName(tableName)
      .withExclusiveStartKey(exclusiveStartKey)
      .withKeyConditions(dynamoDBQueryFilter.getKeyConditions())
      .withLimit(Ints.checkedCast(limit))
      .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);

  RetryResult<QueryResult> retryResult = getRetryDriver().runWithRetry(
      new Callable<QueryResult>() {
        @Override
        public QueryResult call() {
          log.debug("Executing DynamoDB query: " + queryRequest);
          return dynamoDB.query(queryRequest);
        }
      }, 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    文件:QueryCommand.java   
@Override
public void execute() {
    QueryResult result = ddbClient.query(new QueryRequest()
            .withTableName(determineTableName())
            .withAttributesToGet(determineAttributeNames())
            .withConsistentRead(determineConsistentRead())
            .withExclusiveStartKey(determineStartKey())
            .withKeyConditions(determineKeyConditions())
            .withExclusiveStartKey(determineStartKey())
            .withLimit(determineLimit())
            .withScanIndexForward(determineScanIndexForward()));

    Map tmp = new HashMap<>();
    tmp.put(DdbConstants.ITEMS, result.getItems());
    tmp.put(DdbConstants.LAST_EVALUATED_KEY, result.getLastEvaluatedKey());
    tmp.put(DdbConstants.CONSUMED_CAPACITY, result.getConsumedCapacity());
    tmp.put(DdbConstants.COUNT, result.getCount());
    addToResults(tmp);
}
项目:dynamodb-janusgraph-storage-backend    文件:DynamoDbDelegate.java   
public QueryResult query(final QueryRequest request, final int permitsToConsume) throws BackendException {
    setUserAgent(request);
    QueryResult result;
    timedReadThrottle(QUERY, request.getTableName(), permitsToConsume);
    final Timer.Context apiTimerContext = getTimerContext(QUERY, request.getTableName());
    try {
        result = client.query(request);
    } catch (Exception e) {
        throw processDynamoDbApiException(e, QUERY, request.getTableName());
    } finally {
        apiTimerContext.stop();
    }
    meterConsumedCapacity(QUERY, result.getConsumedCapacity());
    measureItemCount(QUERY, request.getTableName(), result.getCount());
    return result;
}
项目:amazon-kinesis-aggregators    文件:DynamoUtils.java   
public static List<Map<String, AttributeValue>> queryUntilDone(
        AmazonDynamoDB dynamoClient, QueryRequest qr, int backoffMillis)
        throws Exception {
    List<Map<String, AttributeValue>> output = new ArrayList<>();

    Map<String, AttributeValue> lastKeyEvaluated = null;
    do {
        int queryAttempts = 0;
        QueryResult result = null;

        do {
            try {
                result = dynamoClient.query(qr).withLastEvaluatedKey(
                        lastKeyEvaluated);

                output.addAll(result.getItems());
            } catch (ProvisionedThroughputExceededException e) {
                LOG.warn(String
                        .format("Provisioned Throughput Exceeded - Retry Attempt %s",
                                queryAttempts));

                Thread.sleep(2 ^ queryAttempts * backoffMillis);

                queryAttempts++;
            }
        } while (queryAttempts < 10 && result == null);

        if (result == null) {
            throw new Exception(String.format(
                    "Unable to execute Query after %s attempts",
                    queryAttempts));
        }

        lastKeyEvaluated = result.getLastEvaluatedKey();
    } while (lastKeyEvaluated != null);

    return output;
}
项目: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());
    }
}
项目:aws-dynamodb-encryption-java    文件:MapperQueryExpressionCryptoTest.java   
private static <T> QueryRequest testCreateQueryRequestFromExpression(
        Class<T> clazz, DynamoDBQueryExpression<T> queryExpression,
        String expectedErrorMessage) {
    try {
        QueryRequest request = (QueryRequest) testedMethod.invoke(mapper, clazz, queryExpression, DynamoDBMapperConfig.DEFAULT);
        if (expectedErrorMessage != null) {
            fail("Exception containing messsage ("
                    + expectedErrorMessage + ") is expected.");
        }
        return request;
    } catch (InvocationTargetException ite) {
        if (expectedErrorMessage != null) {
            assertTrue("Exception message [" + ite.getCause().getMessage() + "] does not contain " +
                    "the expected message [" + expectedErrorMessage + "].",
                    ite.getCause().getMessage().contains(expectedErrorMessage));
        } else {
            ite.getCause().printStackTrace();
            fail("Internal error when calling createQueryRequestFromExpressio method");
        }
    } catch (Exception e) {
        fail(e.getMessage());
    }
    return null;
}
项目: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 findRepliesForAThreadSpecifyOptionalLimit(String forumName, String threadSubject) {

    Map<String, AttributeValue> lastEvaluatedKey = null;
    do {
        QueryRequest queryRequest = new QueryRequest()
                .withTableName(tableName)
                .withKeyConditions(makeReplyKeyConditions(forumName, threadSubject))
                .withLimit(1)
                .withExclusiveStartKey(lastEvaluatedKey);

        QueryResult result = client.query(queryRequest);
        for (Map<String, AttributeValue> item : result.getItems()) {
            printItem(item);
        }
        lastEvaluatedKey = result.getLastEvaluatedKey();
    } while (lastEvaluatedKey != null);        
}
项目: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    文件: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);
    }        
}
项目:spring-data-dynamodb    文件:DynamoDBEntityWithHashAndRangeKeyCriteria.java   
protected Query<T> buildFinderQuery(DynamoDBOperations dynamoDBOperations) {
    if (isApplicableForQuery()) {
        if (isApplicableForGlobalSecondaryIndex()) {
            String tableName = dynamoDBOperations.getOverriddenTableName(entityInformation.getDynamoDBTableName());
            QueryRequest queryRequest = buildQueryRequest(tableName, getGlobalSecondaryIndexName(),
                    getHashKeyAttributeName(), getRangeKeyAttributeName(), this.getRangeKeyPropertyName(),
                    getHashKeyConditions(), getRangeKeyConditions());
            return new MultipleEntityQueryRequestQuery<T>(dynamoDBOperations,entityInformation.getJavaType(), queryRequest);
        } else {
            DynamoDBQueryExpression<T> queryExpression = buildQueryExpression();
            return new MultipleEntityQueryExpressionQuery<T>(dynamoDBOperations, entityInformation.getJavaType(), queryExpression);
        }
    } else {
        return new MultipleEntityScanExpressionQuery<T>(dynamoDBOperations, clazz, buildScanExpression());
    }
}
项目:dynamodb-geo    文件:GeoDataManager.java   
public void run() {
    QueryRequest queryRequest = DynamoDBUtil.copyQueryRequest(geoQueryRequest.getQueryRequest());
    long hashKey = S2Manager.generateHashKey(range.getRangeMin(), config.getHashKeyLength());

    List<QueryResult> queryResults = dynamoDBManager.queryGeohash(queryRequest, hashKey, range);

    for (QueryResult queryResult : queryResults) {
        if (isInterrupted()) {
            return;
        }

        // getQueryResults() returns a synchronized list.
        geoQueryResult.getQueryResults().add(queryResult);

        List<Map<String, AttributeValue>> filteredQueryResult = filter(queryResult.getItems(), geoQueryRequest);

        // getItem() returns a synchronized list.
        geoQueryResult.getItem().addAll(filteredQueryResult);
    }
}
项目: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;
}
项目:strongbox    文件:GenericDynamoDBTest.java   
private static QueryRequest constructQueryRequest(String secretName) {
    Map<String, String> expressionAttributeNames = new HashMap<>();
    expressionAttributeNames.put("#1", KEY_ATTRIBUTE_NAME.toString());
    Map<String, AttributeValue> expressionAttributeValues = new HashMap<>();
    expressionAttributeValues.put(":a", new AttributeValue().withS(secretName));

    QueryRequest request = new QueryRequest()
            .withTableName(tableName)
            .withConsistentRead(true)
            .withKeyConditionExpression("#1 = :a")
            .withExpressionAttributeNames(expressionAttributeNames)
            .withExpressionAttributeValues(expressionAttributeValues);
    return request;
}
项目:strongbox    文件:GenericDynamoDBTest.java   
@Test
public void testDeleteSecret() {
    QueryRequest request = constructQueryRequest(SECRET_NAME);
    QueryResult result = constructQueryResult(false);
    when(mockDynamoDBClient.query(request)).thenReturn(result);

    // Call the delete secret method.
    dynamoDB.delete(new SecretIdentifier(SECRET_NAME));

    // Verify only the entries matching the correct secret were deleted.
    verify(mockDynamoDBClient, times(1)).query(request);
    verify(mockDynamoDBClient, times(1)).deleteItem(tableName, constructKey(SECRET_NAME, 1));
    verify(mockDynamoDBClient, times(1)).deleteItem(tableName, constructKey(SECRET_NAME, 2));
    verify(mockDynamoDBClient, never()).deleteItem(tableName, constructKey(SECRET2_NAME, 1));
}
项目:strongbox    文件:GenericDynamoDBTest.java   
@Test
public void testDeleteSecretNotInTable() {
    QueryRequest request = constructQueryRequest(SECRET_NAME);
    QueryResult result = new QueryResult().withCount(0).withItems(new ArrayList<>());
    when(mockDynamoDBClient.query(request)).thenReturn(result);

    // Try deleting the secret. Method should complete without throwing exception but deleteItem will not be
    // called for any secrets.
    dynamoDB.delete(new SecretIdentifier(SECRET_NAME));
    verify(mockDynamoDBClient, times(1)).query(request);
    verify(mockDynamoDBClient, never()).deleteItem(tableName, constructKey(SECRET_NAME, 1));
}
项目:AbacusUtil    文件:AsyncDynamoDBExecutor.java   
public CompletableFuture<List<Map<String, Object>>> find(final QueryRequest queryRequest) {
    return asyncExecutor.execute(new Callable<List<Map<String, Object>>>() {
        @Override
        public List<Map<String, Object>> call() throws Exception {
            return dbExecutor.find(queryRequest);
        }
    });
}
项目:AbacusUtil    文件:AsyncDynamoDBExecutor.java   
public <T> CompletableFuture<List<T>> find(final Class<T> targetClass, final QueryRequest queryRequest) {
    return asyncExecutor.execute(new Callable<List<T>>() {
        @Override
        public List<T> call() throws Exception {
            return dbExecutor.find(targetClass, queryRequest);
        }
    });
}
项目:AbacusUtil    文件:AsyncDynamoDBExecutor.java   
public CompletableFuture<DataSet> query(final QueryRequest queryRequest) {
    return asyncExecutor.execute(new Callable<DataSet>() {
        @Override
        public DataSet call() throws Exception {
            return dbExecutor.query(queryRequest);
        }
    });
}
项目:AbacusUtil    文件:AsyncDynamoDBExecutor.java   
public <T> CompletableFuture<DataSet> query(final Class<T> targetClass, final QueryRequest queryRequest) {
    return asyncExecutor.execute(new Callable<DataSet>() {
        @Override
        public DataSet call() throws Exception {
            return dbExecutor.query(targetClass, queryRequest);
        }
    });
}
项目:AbacusUtil    文件:AsyncDynamoDBExecutor.java   
public CompletableFuture<Stream<Map<String, Object>>> stream(final QueryRequest queryRequest) {
    return asyncExecutor.execute(new Callable<Stream<Map<String, Object>>>() {
        @Override
        public Stream<Map<String, Object>> call() throws Exception {
            return dbExecutor.stream(queryRequest);
        }
    });
}
项目:AbacusUtil    文件:AsyncDynamoDBExecutor.java   
public <T> CompletableFuture<Stream<T>> stream(final Class<T> targetClass, final QueryRequest queryRequest) {
    return asyncExecutor.execute(new Callable<Stream<T>>() {
        @Override
        public Stream<T> call() throws Exception {
            return dbExecutor.stream(targetClass, queryRequest);
        }
    });
}
项目:Camel    文件:AmazonDDBClientMock.java   
@SuppressWarnings("unchecked")
@Override
public QueryResult query(QueryRequest queryRequest) {
    this.queryRequest = queryRequest;
    ConsumedCapacity consumed = new ConsumedCapacity();
    consumed.setCapacityUnits(1.0);
    Map<String, AttributeValue> lastEvaluatedKey = new HashMap<String, AttributeValue>();
    lastEvaluatedKey.put("1", new AttributeValue("LAST_KEY"));
    return new QueryResult()
            .withConsumedCapacity(consumed)
            .withCount(1)
            .withItems(getAttributes())
            .withLastEvaluatedKey(lastEvaluatedKey);
}
项目:Tank    文件:AmazonDynamoDatabaseDocApi.java   
/**
 * @{inheritDoc
 */
@Override
public boolean hasJobData(String tableName, String jobId) {
    if (hasTable(tableName)) {
        Map<String, Condition> keyConditions = new HashMap<String, Condition>();
        Condition jobIdCondition = new Condition().withComparisonOperator(ComparisonOperator.EQ)
                .withAttributeValueList(new AttributeValue().withS(jobId));
        keyConditions.put(DatabaseKeys.JOB_ID_KEY.getShortKey(), jobIdCondition);
        QueryRequest queryRequest = new QueryRequest().withTableName(tableName).withKeyConditions(keyConditions)
                .withLimit(1);

        return dynamoDb.query(queryRequest).getCount() > 0;
    }
    return false;
}
项目:dynamodb-janusgraph-storage-backend    文件:DynamoDbStore.java   
public QueryWorker buildQueryWorker(final StaticBuffer hashKey, final SliceQuery query) {
    final QueryRequest request = createQueryRequest(hashKey, query);
    // Only enforce a limit when Titan tells us to
    if (query.hasLimit()) {
        final int limit = query.getLimit();
        request.setLimit(limit);
        return new QueryWithLimitWorker(client.getDelegate(), request, hashKey, limit);
    }

    return new QueryWorker(client.getDelegate(), request, hashKey);
}
项目:dynamodb-janusgraph-storage-backend    文件:DynamoDbStore.java   
private QueryRequest createQueryRequest(final StaticBuffer hashKey, final SliceQuery rangeQuery) {
    final Expression keyConditionExpression = new ConditionExpressionBuilder().hashKey(hashKey)
            .rangeKey(rangeQuery.getSliceStart(), rangeQuery.getSliceEnd())
            .build();

    final QueryRequest request = super.createQueryRequest()
           .withKeyConditionExpression(keyConditionExpression.getConditionExpression())
           .withExpressionAttributeValues(keyConditionExpression.getAttributeValues());
    return request;
}
项目:dynamodb-janusgraph-storage-backend    文件:QueryWorker.java   
QueryWorker(final DynamoDbDelegate delegate, final QueryRequest request, final StaticBuffer titanKey) {
    super(delegate, DynamoDbDelegate.QUERY, request.getTableName());
    this.request = request;
    this.titanKey = titanKey;
    this.returnedCount = 0;
    this.scannedCount = 0;
    this.finalItemList = new ArrayList<>();
    this.permitsToConsume = 1;
    this.totalCapacityUnits = 0.0;
}
项目:aws-dynamodb-encryption-java    文件:MapperQueryExpressionCryptoTest.java   
@Test
public void testHashOnlyQueryOnHashRangeTable() {
    // Primary hash only query on a Hash+Range table
    QueryRequest queryRequest = testCreateQueryRequestFromExpression(
            LSIRangeKeyTestClass.class,
            new DynamoDBQueryExpression<LSIRangeKeyTestClass>()
                    .withHashKeyValues(new LSIRangeKeyTestClass("foo", null)));
    assertTrue(queryRequest.getKeyConditions().size() == 1);
    assertTrue(queryRequest.getKeyConditions().containsKey("primaryHashKey"));
    assertNull(queryRequest.getIndexName());

    // Hash+Range query on a LSI
    queryRequest = testCreateQueryRequestFromExpression(
            LSIRangeKeyTestClass.class,
            new DynamoDBQueryExpression<LSIRangeKeyTestClass>()
                    .withHashKeyValues(new LSIRangeKeyTestClass("foo", null))
                    .withRangeKeyCondition("lsiRangeKey", RANGE_KEY_CONDITION)
                    .withIndexName("LSI"));
    assertTrue(queryRequest.getKeyConditions().size() == 2);
    assertTrue(queryRequest.getKeyConditions().containsKey("primaryHashKey"));
    assertTrue(queryRequest.getKeyConditions().containsKey("lsiRangeKey"));
    assertEquals("LSI", queryRequest.getIndexName());

    // Hash-only query on a LSI
    queryRequest = testCreateQueryRequestFromExpression(
            LSIRangeKeyTestClass.class,
            new DynamoDBQueryExpression<LSIRangeKeyTestClass>()
                    .withHashKeyValues(new LSIRangeKeyTestClass("foo", null))
                    .withIndexName("LSI"));
    assertTrue(queryRequest.getKeyConditions().size() == 1);
    assertTrue(queryRequest.getKeyConditions().containsKey("primaryHashKey"));
    assertEquals("LSI", queryRequest.getIndexName());
}
项目:Doradus    文件:DynamoDBService2.java   
@Override
  public List<DColumn> getColumns(String storeName, String rowKey, String startColumn, String endColumn, int count) {
    Timer t = new Timer();
    String key = storeName + "_" + rowKey;
    HashMap<String,Condition> keyConditions = new HashMap<String,Condition>();
    keyConditions.put("key", new Condition()
    .withComparisonOperator(ComparisonOperator.EQ)
    .withAttributeValueList(new AttributeValue().withS(key)));
    if(startColumn != null && endColumn != null) {
        keyConditions.put("column", new Condition()
            .withComparisonOperator(ComparisonOperator.BETWEEN)
            .withAttributeValueList(new AttributeValue().withS(startColumn), new AttributeValue(endColumn)));
    } else if(startColumn != null) {
        keyConditions.put("column", new Condition()
            .withComparisonOperator(ComparisonOperator.GE)
            .withAttributeValueList(new AttributeValue().withS(startColumn)));
    } else if(endColumn != null) {
        keyConditions.put("column", new Condition()
            .withComparisonOperator(ComparisonOperator.LT)
            .withAttributeValueList(new AttributeValue().withS(endColumn)));
    }

QueryRequest request = new QueryRequest()
    .withTableName(getTenant().getName())
    .withLimit(Math.min(100,  count))
    .withKeyConditions(keyConditions);
QueryResult result = m_client.query(request);
List<DColumn> list = fromItems(result.getItems());
      m_logger.debug("get columns range for {} in {}", getTenant().getName(), t);
    return list;
  }
项目:spring-security-oauth2-dynamodb    文件:DynamoDBTemplate.java   
public <T> List<T> query(String tableName, String indexName, Map<String, Condition> keyConditions, final ObjectExtractor<T> extractor, String... columnsToInclude) throws EmptyResultDataAccessException {
    Assert.notNull(tableName, "Table must not be null");
    Assert.notNull(extractor, "ObjectExtractor must not be null");
    if (logger.isDebugEnabled()) {
        logger.debug("Executing query on " + tableName + " for " + renderKey(keyConditions));
    }

    QueryRequest request = new QueryRequest(tableName) //
            .withConsistentRead(false) // because query is used on GSIs [where consistent reads are not supported] - if we needed to query on the primary index could make this a parameter
            .withKeyConditions(keyConditions);

    if (columnsToInclude != null && columnsToInclude.length > 0) {
        request.setAttributesToGet(Arrays.asList(columnsToInclude));
    }

    if (indexName != null) {
        request.setIndexName(indexName);
    }

    QueryResult result = client.query(request);

    List<Map<String, AttributeValue>> items = result.getItems();
    List<T> convertedItems = new ArrayList<T>(items.size());
    for (Map<String, AttributeValue> item : items) {
        convertedItems.add(extractor.extract(item));
    }

    return convertedItems;
}
项目:aws-dynamodb-examples    文件:LowLevelQuery.java   
private static void findRepliesPostedWithinTimePeriod(String forumName, String threadSubject) {

    long startDateMilli = (new Date()).getTime() - (15L*24L*60L*60L*1000L); 
    long endDateMilli = (new Date()).getTime() - (5L*24L*60L*60L*1000L);    
    java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    String startDate = df.format(startDateMilli);
    String endDate = df.format(endDateMilli);

    Condition rangeKeyCondition = new Condition()
        .withComparisonOperator(ComparisonOperator.BETWEEN.toString())
        .withAttributeValueList(
            new AttributeValue().withS(startDate), 
            new AttributeValue().withS(endDate));

    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);
    }        
}
项目:spring-data-dynamodb    文件:DynamoDBEntityWithHashKeyOnlyCriteria.java   
protected Query<T> buildFinderQuery(DynamoDBOperations dynamoDBOperations) {
    if (isApplicableForGlobalSecondaryIndex()) {

        List<Condition> hashKeyConditions = getHashKeyConditions();
        QueryRequest queryRequest = buildQueryRequest(dynamoDBOperations.getOverriddenTableName(entityInformation.getDynamoDBTableName()),
                getGlobalSecondaryIndexName(), getHashKeyAttributeName(), null, null, hashKeyConditions, null);
        return new MultipleEntityQueryRequestQuery<T>(dynamoDBOperations,entityInformation.getJavaType(), queryRequest);
    } else {
        return new MultipleEntityScanExpressionQuery<T>(dynamoDBOperations, clazz, buildScanExpression());
    }
}
项目:spring-data-dynamodb    文件:DynamoDBEntityWithHashKeyOnlyCriteria.java   
protected Query<Long> buildFinderCountQuery(DynamoDBOperations dynamoDBOperations,boolean pageQuery) {
    if (isApplicableForGlobalSecondaryIndex()) {

        List<Condition> hashKeyConditions = getHashKeyConditions();
        QueryRequest queryRequest = buildQueryRequest(dynamoDBOperations.getOverriddenTableName(entityInformation.getDynamoDBTableName()),
                getGlobalSecondaryIndexName(), getHashKeyAttributeName(), null, null, hashKeyConditions, null);
        return new QueryRequestCountQuery<T>(dynamoDBOperations, entityInformation.getJavaType(), queryRequest);

    } else {
        return new ScanExpressionCountQuery<T>(dynamoDBOperations, clazz, buildScanExpression(),pageQuery);
    }
}