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

下面列出了怎么用com.amazonaws.services.dynamodbv2.model.Condition的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: 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);
        }
    }
 
源代码2 项目: emr-dynamodb-connector   文件: DynamoDBClient.java
public RetryResult<ScanResult> scanTable(
    String tableName, DynamoDBQueryFilter dynamoDBQueryFilter, Integer segment, Integer
    totalSegments, Map<String, AttributeValue> exclusiveStartKey, long limit, Reporter reporter) {
  final ScanRequest scanRequest = new ScanRequest(tableName)
      .withExclusiveStartKey(exclusiveStartKey)
      .withLimit(Ints.checkedCast(limit))
      .withSegment(segment)
      .withTotalSegments(totalSegments)
      .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);

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

  RetryResult<ScanResult> retryResult = getRetryDriver().runWithRetry(new Callable<ScanResult>() {
    @Override
    public ScanResult call() {
      log.debug("Executing DynamoDB scan: " + scanRequest);
      return dynamoDB.scan(scanRequest);
    }
  }, reporter, PrintCounter.DynamoDBReadThrottle);
  return retryResult;
}
 
源代码3 项目: aws-doc-sdk-examples   文件: LowLevelQuery.java
private static void findRepliesForAThread(String forumName, String threadSubject) {

        String replyId = forumName + "#" + threadSubject;

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

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

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

        QueryResult result = client.query(queryRequest);
        for (Map<String, AttributeValue> item : result.getItems()) {
            printItem(item);
        }
    }
 
源代码4 项目: aws-doc-sdk-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 sortKeyCondition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString())
            .withAttributeValueList(new AttributeValue().withS(twoWeeksAgoStr));

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

        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);
        }

    }
 
源代码5 项目: openhab1-addons   文件: DynamoDBQueryUtils.java
private static 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;
}
 
源代码6 项目: aws-doc-sdk-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);
        }
    }
 
源代码7 项目: aws-dynamodb-encryption-java   文件: ScanITCase.java
/**
 * Tests scanning the table with AND/OR logic operator.
 */
@Test
public void testScanWithConditionalOperator() {
    DynamoDBMapper mapper = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo);

    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression()
        .withLimit(SCAN_LIMIT)
        .withScanFilter(ImmutableMapParameter.of(
                "value", new Condition().withComparisonOperator(ComparisonOperator.NOT_NULL),
                "non-existent-field", new Condition().withComparisonOperator(ComparisonOperator.NOT_NULL)
                ))
        .withConditionalOperator(ConditionalOperator.AND);

    List<SimpleClass> andConditionResult = mapper.scan(SimpleClass.class, scanExpression);
    assertTrue(andConditionResult.isEmpty());

    List<SimpleClass> orConditionResult = mapper.scan(SimpleClass.class,
            scanExpression.withConditionalOperator(ConditionalOperator.OR));
    assertFalse(orConditionResult.isEmpty());
}
 
private static PaginatedList<RangeKeyTestClass> getTestPaginatedScanList(PaginationLoadingStrategy paginationLoadingStrategy) {
    DynamoDBMapperConfig mapperConfig = new DynamoDBMapperConfig(ConsistentReads.CONSISTENT);
    DynamoDBMapper mapper = new DynamoDBMapper(dynamo, mapperConfig);
    
    // Construct the scan expression with the exact same conditions
    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
    scanExpression.addFilterCondition("key", 
            new Condition().withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(
                    new AttributeValue().withN(Long.toString(hashKey))));
    scanExpression.addFilterCondition("rangeKey", 
            new Condition().withComparisonOperator(ComparisonOperator.GT).withAttributeValueList(
                    new AttributeValue().withN("1.0")));
    scanExpression.setLimit(PAGE_SIZE);
    
    return mapper.scan(RangeKeyTestClass.class, scanExpression, new DynamoDBMapperConfig(paginationLoadingStrategy));
}
 
private static PaginatedList<RangeKeyTestClass> getTestPaginatedParallelScanList(PaginationLoadingStrategy paginationLoadingStrategy) {
    DynamoDBMapperConfig mapperConfig = new DynamoDBMapperConfig(ConsistentReads.CONSISTENT);
    DynamoDBMapper mapper = new DynamoDBMapper(dynamo, mapperConfig);
    
    // Construct the scan expression with the exact same conditions
    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
    scanExpression.addFilterCondition("key", 
            new Condition().withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(
                    new AttributeValue().withN(Long.toString(hashKey))));
    scanExpression.addFilterCondition("rangeKey", 
            new Condition().withComparisonOperator(ComparisonOperator.GT).withAttributeValueList(
                    new AttributeValue().withN("1.0")));
    scanExpression.setLimit(PAGE_SIZE);
    
    return mapper.parallelScan(RangeKeyTestClass.class, scanExpression, PARALLEL_SEGMENT, new DynamoDBMapperConfig(paginationLoadingStrategy));
}
 
/** 
 * Tests the exception when user specifies an invalid index name in the query.
 */
@Test
public void testInvalidIndexNameException() {
	IndexRangeKeyTestClass hashKeyItem = new IndexRangeKeyTestClass();
	hashKeyItem.setKey(0);
	try {
		mapper.query(IndexRangeKeyTestClass.class,
				new DynamoDBQueryExpression<IndexRangeKeyTestClass>()
					.withHashKeyValues(hashKeyItem)
					.withRangeKeyCondition(INDEX_BAR_RANGE_KEY, 
							new Condition()
								.withAttributeValueList(new AttributeValue().withN("0"))
								.withComparisonOperator(ComparisonOperator.GE.toString()))
					.withIndexName("some_index"));
		fail("some_index is not a valid index name.");
	} catch (IllegalArgumentException iae) {
		System.out.println(iae.getMessage());
	} catch (Exception e) {
		fail("Should trigger an IllegalArgumentException.");
	}
}
 
源代码11 项目: geowave   文件: DynamoDBReader.java
private List<QueryRequest> getAdapterOnlyQueryRequests(
    final String tableName,
    final ArrayList<Short> internalAdapterIds) {
  final List<QueryRequest> allQueries = new ArrayList<>();

  for (final short internalAdapterId : internalAdapterIds) {
    final QueryRequest singleAdapterQuery = new QueryRequest(tableName);

    final byte[] start = ByteArrayUtils.shortToByteArray(internalAdapterId);
    final byte[] end = new ByteArray(start).getNextPrefix();
    singleAdapterQuery.addKeyConditionsEntry(
        DynamoDBRow.GW_RANGE_KEY,
        new Condition().withComparisonOperator(ComparisonOperator.BETWEEN).withAttributeValueList(
            new AttributeValue().withB(ByteBuffer.wrap(start)),
            new AttributeValue().withB(ByteBuffer.wrap(end))));

    allQueries.add(singleAdapterQuery);
  }

  return allQueries;
}
 
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;
	}
 
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;
}
 
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);

}
 
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);

}
 
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;
	}
 
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);
    }
}
 
源代码18 项目: openhab1-addons   文件: DynamoDBQueryUtils.java
private static 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));
    }
    return timeCondition;
}
 
@Override
public Condition createCondition() {
  Condition condition = new Condition();
  condition.setComparisonOperator(operator.getDynamoDBName());

  List<AttributeValue> attributeValueList = new ArrayList<>();
  for (String value : columnValues) {
    attributeValueList.add(HiveDynamoDBTypeFactory.getTypeObjectFromHiveType(columnType)
        .getAttributeValue(value));
  }
  condition.setAttributeValueList(attributeValueList);

  return condition;
}
 
源代码20 项目: dynamodb-geo   文件: DynamoDBManager.java
/**
 * Query Amazon DynamoDB
 * 
 * @param hashKey
 *            Hash key for the query request.
 * 
 * @param range
 *            The range of geohashs to query.
 * 
 * @return The query result.
 */
public List<QueryResult> queryGeohash(QueryRequest queryRequest, long hashKey, GeohashRange range) {
	List<QueryResult> queryResults = new ArrayList<QueryResult>();
	Map<String, AttributeValue> lastEvaluatedKey = null;

	do {
		Map<String, Condition> keyConditions = new HashMap<String, Condition>();

		Condition hashKeyCondition = new Condition().withComparisonOperator(ComparisonOperator.EQ)
				.withAttributeValueList(new AttributeValue().withN(String.valueOf(hashKey)));
		keyConditions.put(config.getHashKeyAttributeName(), hashKeyCondition);

		AttributeValue minRange = new AttributeValue().withN(Long.toString(range.getRangeMin()));
		AttributeValue maxRange = new AttributeValue().withN(Long.toString(range.getRangeMax()));

		Condition geohashCondition = new Condition().withComparisonOperator(ComparisonOperator.BETWEEN)
				.withAttributeValueList(minRange, maxRange);
		keyConditions.put(config.getGeohashAttributeName(), geohashCondition);

		queryRequest.withTableName(config.getTableName()).withKeyConditions(keyConditions)
				.withIndexName(config.getGeohashIndexName()).withConsistentRead(true)
				.withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL).withExclusiveStartKey(lastEvaluatedKey);

		QueryResult queryResult = config.getDynamoDBClient().query(queryRequest);
		queryResults.add(queryResult);

		lastEvaluatedKey = queryResult.getLastEvaluatedKey();

	} while (lastEvaluatedKey != null);

	return queryResults;
}
 
源代码21 项目: aws-doc-sdk-examples   文件: LowLevelQuery.java
/**
 * A simple helper function that returns a KeyCondition map filled in with
 * the partition key equality condition for a the Reply example table, given
 * a forumName and threadSubject.
 */
private static Map<String, Condition> makeReplyKeyConditions(String forumName, String threadSubject) {
    String replyId = forumName + "#" + threadSubject;

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

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

    return keyConditions;
}
 
@Override
public ScanResult scan(String tableName, Map<String, Condition> scanFilter)
        throws AmazonServiceException, AmazonClientException {
    ScanRequest request = new ScanRequest()
            .withTableName(tableName)
            .withScanFilter(scanFilter);
    return scan(request);
}
 
/**
 * Tests that we can query using the hash/range GSI on our hash-key only
 * table.
 */
@Test
public void testGSIQuery() throws Exception {
    DynamoDBMapper mapper = TestDynamoDBMapperFactory
            .createDynamoDBMapper(dynamo);
    String status = "foo-status";

    User user = new User();
    user.setId("123");
    user.setStatus(status);
    user.setTs("321");
    mapper.save(user);

    DynamoDBQueryExpression<User> expr = new DynamoDBQueryExpression<User>()
            .withIndexName("statusAndCreation")
            .withLimit(100)
            .withConsistentRead(false)
            .withHashKeyValues(user)
            .withRangeKeyCondition(
                    "ts",
                    new Condition()
                    .withComparisonOperator(ComparisonOperator.GT)
                    .withAttributeValueList(new AttributeValue("100")));

    PaginatedQueryList<User> query = mapper.query(User.class, expr);
    int size = query.size();
    if (DEBUG)
        System.err.println("size=" + size);
    assertTrue(1 == size);
    assertEquals(status, query.get(0).getStatus());
}
 
源代码24 项目: aws-dynamodb-encryption-java   文件: QueryITCase.java
/**
 * Tests that exception should be raised when user provides an index name
 * when making query with the primary range key.
 */
@Test
public void testUnnecessaryIndexNameException() {
    try {
        DynamoDBMapper mapper = TestDynamoDBMapperFactory
                .createDynamoDBMapper(dynamo);
        long hashKey = System.currentTimeMillis();
        RangeKeyTestClass keyObject = new RangeKeyTestClass();
        keyObject.setKey(hashKey);
        DynamoDBQueryExpression<RangeKeyTestClass> queryExpression = new DynamoDBQueryExpression<RangeKeyTestClass>()
                .withHashKeyValues(keyObject);
        queryExpression
                .withRangeKeyCondition(
                        "rangeKey",
                        new Condition().withComparisonOperator(
                                ComparisonOperator.GT.toString())
                                .withAttributeValueList(
                                        new AttributeValue().withN("1.0")))
                .withLimit(11).withIndexName("some_index");
        mapper.query(RangeKeyTestClass.class, queryExpression);
        fail("User should not provide index name when making query with the primary range key");
    } catch (IllegalArgumentException expected) {
        System.out.println(expected.getMessage());
    } catch (Exception e) {
        fail("Should trigger AmazonClientException.");
    }

}
 
源代码25 项目: aws-dynamodb-encryption-java   文件: ScanITCase.java
@Test
public void testParallelScan() throws Exception {
    DynamoDBMapper util = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo);

    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression().withLimit(SCAN_LIMIT);
    scanExpression.addFilterCondition("value", new Condition().withComparisonOperator(ComparisonOperator.NOT_NULL.toString()));
    scanExpression.addFilterCondition("extraData", new Condition().withComparisonOperator(ComparisonOperator.NOT_NULL.toString()));

    PaginatedParallelScanList<SimpleClass> parallelScanList = util.parallelScan(SimpleClass.class, scanExpression, PARALLEL_SCAN_SEGMENTS);
    int count = 0;
    Iterator<SimpleClass> iterator = parallelScanList.iterator();
    HashMap<String, Boolean> allDataAppearance = new HashMap<String, Boolean>();
    for (int i=0;i<500;i++) {
        allDataAppearance.put("" + i, false);
    }
    while (iterator.hasNext()) {
        count++;
        SimpleClass next = iterator.next();
        assertNotNull(next.getExtraData());
        assertNotNull(next.getValue());
        allDataAppearance.put(next.getId(), true);
    }
    assertFalse(allDataAppearance.values().contains(false));

    int totalCount = util.count(SimpleClass.class, scanExpression);

    assertNotNull(parallelScanList.get(totalCount / 2));
    assertTrue(totalCount == count);
    assertTrue(totalCount == parallelScanList.size());

    assertTrue(parallelScanList.contains(parallelScanList.get(parallelScanList.size() / 2)));
    assertTrue(count == parallelScanList.toArray().length);

}
 
private static PaginatedList<RangeKeyTestClass> getTestPaginatedQueryList(PaginationLoadingStrategy paginationLoadingStrategy) {
    DynamoDBMapperConfig mapperConfig = new DynamoDBMapperConfig(ConsistentReads.CONSISTENT);
    DynamoDBMapper mapper = new DynamoDBMapper(dynamo, mapperConfig);
    
    // Construct the query expression for the tested hash-key value and any range-key value greater that 1.0
    RangeKeyTestClass keyObject = new RangeKeyTestClass();
    keyObject.setKey(hashKey);
    DynamoDBQueryExpression<RangeKeyTestClass> queryExpression = new DynamoDBQueryExpression<RangeKeyTestClass>().withHashKeyValues(keyObject);
    queryExpression.withRangeKeyCondition("rangeKey",
            new Condition().withComparisonOperator(ComparisonOperator.GT.toString()).withAttributeValueList(
                    new AttributeValue().withN("1.0"))).withLimit(PAGE_SIZE);
    
    return mapper.query(RangeKeyTestClass.class, queryExpression, new DynamoDBMapperConfig(paginationLoadingStrategy));
}
 
private QueryRequest createQueryRequest(final boolean filterAttributes) {
    Condition hashKeyCondition = new Condition()
            .withComparisonOperator(ComparisonOperator.EQ)
            .withAttributeValueList(key0.get(ID_ATTRIBUTE));
    QueryRequest request = new QueryRequest()
            .withTableName(INTEG_HASH_TABLE_NAME)
            .withKeyConditions(Collections.singletonMap(ID_ATTRIBUTE, hashKeyCondition));
    if (filterAttributes) {
        request.setAttributesToGet(attributesToGet);
    }
    return request;
}
 
源代码28 项目: 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;
  }
 
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());
	}
}
 
@Override
public ScanResult scan(
        String tableName,
        List<String> attributesToGet,
        Map<String, Condition> scanFilter) throws AmazonServiceException, AmazonClientException {
    ScanRequest request = new ScanRequest()
            .withTableName(tableName)
            .withAttributesToGet(attributesToGet)
            .withScanFilter(scanFilter);
    return scan(request);
}
 
 类方法
 同包方法