本文整理汇总了Java中com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression类的典型用法代码示例。如果您正苦于以下问题:Java DynamoDBQueryExpression类的具体用法?Java DynamoDBQueryExpression怎么用?Java DynamoDBQueryExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DynamoDBQueryExpression类属于com.amazonaws.services.dynamodbv2.datamodeling包,在下文中一共展示了DynamoDBQueryExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildFinderCountQuery
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression; //导入依赖的package包/类
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);
}
}
开发者ID:michaellavelle,项目名称:spring-data-dynamodb,代码行数:19,代码来源:DynamoDBEntityWithHashAndRangeKeyCriteria.java
示例2: getUnprocessedCpcPlusMetaData
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression; //导入依赖的package包/类
/**
* Queries the DynamoDB GSI for unprocessed {@link Metadata} with a maximum of 96 items.
*
* Iterates over all of the different partitions, returning a maximum of three items from each.
*
* @return {@link List} of unprocessed {@link Metadata}
*/
public List<Metadata> getUnprocessedCpcPlusMetaData() {
return IntStream.range(0, Constants.CPC_DYNAMO_PARTITIONS).mapToObj(partition -> {
Map<String, AttributeValue> valueMap = new HashMap<>();
valueMap.put(":cpcValue", new AttributeValue().withS(Constants.CPC_DYNAMO_PARTITION_START + partition));
valueMap.put(":cpcProcessedValue", new AttributeValue().withS("false"));
DynamoDBQueryExpression<Metadata> metadataQuery = new DynamoDBQueryExpression<Metadata>()
.withIndexName("Cpc-CpcProcessed_CreateDate-index")
.withKeyConditionExpression(Constants.DYNAMO_CPC_ATTRIBUTE + " = :cpcValue and begins_with(" +
Constants.DYNAMO_CPC_PROCESSED_CREATE_DATE_ATTRIBUTE + ", :cpcProcessedValue)")
.withExpressionAttributeValues(valueMap)
.withConsistentRead(false)
.withLimit(LIMIT);
return mapper.queryPage(Metadata.class, metadataQuery).getResults().stream();
}).flatMap(Function.identity()).collect(Collectors.toList());
}
示例3: testCreateQueryRequestFromExpression
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression; //导入依赖的package包/类
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;
}
示例4: applySortIfSpecified
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression; //导入依赖的package包/类
protected void applySortIfSpecified(DynamoDBQueryExpression<T> queryExpression, List<String> permittedPropertyNames) {
if (permittedPropertyNames.size() > 1) {
throw new UnsupportedOperationException("Can only sort by at most a single range or index range key");
}
if (sort != null) {
boolean sortAlreadySet = false;
for (Order order : sort) {
if (permittedPropertyNames.contains(order.getProperty())) {
if (sortAlreadySet) {
throw new UnsupportedOperationException("Sorting by multiple attributes not possible");
}
queryExpression.setScanIndexForward(order.getDirection().equals(Direction.ASC));
sortAlreadySet = true;
} else {
throw new UnsupportedOperationException("Sorting only possible by " + permittedPropertyNames
+ " for the criteria specified");
}
}
}
}
示例5: buildFinderQuery
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression; //导入依赖的package包/类
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());
}
}
开发者ID:michaellavelle,项目名称:spring-data-dynamodb,代码行数:17,代码来源:DynamoDBEntityWithHashAndRangeKeyCriteria.java
示例6: maybeAddStateFilter
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression; //导入依赖的package包/类
private void maybeAddStateFilter(FilterCriteria filter,
final DynamoDBQueryExpression<DynamoDBItem<?>> queryExpression) {
if (filter.getOperator() != null && filter.getState() != null) {
// Convert filter's state to DynamoDBItem in order get suitable string representation for the state
final DynamoDBItem<?> filterState = AbstractDynamoDBItem.fromState(filter.getItemName(), filter.getState(),
new Date());
queryExpression.setFilterExpression(String.format("%s %s :opstate", DynamoDBItem.ATTRIBUTE_NAME_ITEMSTATE,
operatorAsString(filter.getOperator())));
filterState.accept(new DynamoDBItemVisitor() {
@Override
public void visit(DynamoDBStringItem dynamoStringItem) {
queryExpression.setExpressionAttributeValues(
ImmutableMap.of(":opstate", new AttributeValue().withS(dynamoStringItem.getState())));
}
@Override
public void visit(DynamoDBBigDecimalItem dynamoBigDecimalItem) {
queryExpression.setExpressionAttributeValues(ImmutableMap.of(":opstate",
new AttributeValue().withN(dynamoBigDecimalItem.getState().toPlainString())));
}
});
}
}
示例7: testGetUnprocessedCpcPlusMetaData
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression; //导入依赖的package包/类
@Test
void testGetUnprocessedCpcPlusMetaData() {
int itemsPerPartition = 2;
QueryResultPage<Metadata> mockMetadataPage = mock(QueryResultPage.class);
when(mockMetadataPage.getResults()).thenReturn(Stream.generate(Metadata::new).limit(itemsPerPartition).collect(Collectors.toList()));
when(dbMapper.queryPage(eq(Metadata.class), any(DynamoDBQueryExpression.class))).thenReturn(mockMetadataPage);
List<Metadata> metaDataList = underTest.getUnprocessedCpcPlusMetaData();
verify(dbMapper, times(Constants.CPC_DYNAMO_PARTITIONS)).queryPage(any(Class.class), any(DynamoDBQueryExpression.class));
assertThat(metaDataList).hasSize(itemsPerPartition * Constants.CPC_DYNAMO_PARTITIONS);
}
示例8: executeFindInIndex
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression; //导入依赖的package包/类
/**
* Perform a query against DynamoDB. The List returned is a
* {@code com.amazonaws.services.dynamodbv2.datamodeling.PaginatedQueryList}, which loads List items on demand
* (as List is iterated through). Be aware that List methods requiring full iteration (e.g. size()) will
* load all list items immediately into memory.
*
* @param conditionExpression Key condition expression defining the query
* @param expressionAV Map of DynamoDB Expression Attribute Values (used to populate conditionExpression)
* @param indexName Index to run the query against
* @param consistentRead Whether to require consistent read (only available for LocalSecondaryIndexes)
* @return PaginatedQueryList of ResourceTriples
* @see com.amazonaws.services.dynamodbv2.datamodeling.PaginatedQueryList
*/
private List<ResourceTriple> executeFindInIndex(final String conditionExpression,
final Map<String, AttributeValue> expressionAV,
final String indexName,
final boolean consistentRead) {
final DynamoDBQueryExpression<ResourceTriple> query =
new DynamoDBQueryExpression<ResourceTriple>()
.withIndexName(indexName)
.withConsistentRead(consistentRead)
.withKeyConditionExpression(conditionExpression)
.withExpressionAttributeValues(expressionAV);
return mapper.query(ResourceTriple.class, query);
}
示例9: byType
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression; //导入依赖的package包/类
public List<LeagueRecord> byType(GameType gameType) {
PaginatedQueryList<LeagueRecord> results = tableMapper.query(new DynamoDBQueryExpression<LeagueRecord>()
.withScanIndexForward(true)
.withLimit(100)
.withConsistentRead(false)
.withHashKeyValues(LeagueRecord.builder().gameType(gameType).build())
.withIndexName("LeagueByType"));
results.loadAllResults();
return results;
}
示例10: lookupByLeague
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression; //导入依赖的package包/类
public List<PlayerRecord> lookupByLeague(String leagueId) {
PaginatedQueryList<PlayerRecord> results = tableMapper.query(new DynamoDBQueryExpression<PlayerRecord>()
.withScanIndexForward(true)
.withLimit(100)
.withConsistentRead(false)
.withHashKeyValues(PlayerRecord.builder().leagueId(leagueId).build())
.withIndexName("PlayerByLeague"));
results.loadAllResults();
return results;
}
示例11: lookupByUser
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression; //导入依赖的package包/类
public List<PlayerRecord> lookupByUser(String userId) {
PaginatedQueryList<PlayerRecord> results = tableMapper.query(new DynamoDBQueryExpression<PlayerRecord>()
.withScanIndexForward(true)
.withLimit(100)
.withConsistentRead(false)
.withHashKeyValues(PlayerRecord.builder().userId(userId).build())
.withIndexName("LeagueByType"));
results.loadAllResults();
return results;
}
示例12: byEmail
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression; //导入依赖的package包/类
public UserRecord byEmail(String email) {
UserRecord lookup = null;
PaginatedQueryList<UserRecord> results = tableMapper.query(new DynamoDBQueryExpression<UserRecord>()
.withLimit(1)
.withConsistentRead(false)
.withHashKeyValues(UserRecord.builder().email(email).build())
.withIndexName("UserByEmail"));
if (results.size() > 0) {
lookup = results.get(0);
}
return lookup;
}
示例13: findByPartition
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression; //导入依赖的package包/类
public Collection<T> findByPartition(String bucketName) {
PaginatedQueryList<T> result = this.tableMapper.query(
new DynamoDBQueryExpression<T>().withRangeKeyCondition(tableMapper.rangeKey().name(),
new Condition()
.withComparisonOperator(ComparisonOperator.EQ)
.withAttributeValueList(new AttributeValue(bucketName))));
return result;
}
示例14: findEventsByCity
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression; //导入依赖的package包/类
@Override
public List<Event> findEventsByCity(String city) {
Map<String, AttributeValue> eav = new HashMap<>();
eav.put(":v1", new AttributeValue().withS(city));
DynamoDBQueryExpression<Event> query = new DynamoDBQueryExpression<Event>()
.withIndexName(Event.CITY_INDEX)
.withConsistentRead(false)
.withKeyConditionExpression("city = :v1")
.withExpressionAttributeValues(eav);
return mapper.query(Event.class, query);
// NOTE: without an index, this query would require a full table scan with a filter:
/*
DynamoDBScanExpression scanExpression = new DynamoDBScanExpression()
.withFilterExpression("city = :val1")
.withExpressionAttributeValues(eav);
return mapper.scan(Event.class, scanExpression);
*/
}
示例15: findEventsByTeam
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression; //导入依赖的package包/类
@Override
public List<Event> findEventsByTeam(String team) {
DynamoDBQueryExpression<Event> homeQuery = new DynamoDBQueryExpression<>();
Event eventKey = new Event();
eventKey.setHomeTeam(team);
homeQuery.setHashKeyValues(eventKey);
List<Event> homeEvents = mapper.query(Event.class, homeQuery);
Map<String, AttributeValue> eav = new HashMap<>();
eav.put(":v1", new AttributeValue().withS(team));
DynamoDBQueryExpression<Event> awayQuery = new DynamoDBQueryExpression<Event>()
.withIndexName(Event.AWAY_TEAM_INDEX)
.withConsistentRead(false)
.withKeyConditionExpression("awayTeam = :v1")
.withExpressionAttributeValues(eav);
List<Event> awayEvents = mapper.query(Event.class, awayQuery);
// need to create a new list because PaginatedList from query is immutable
List<Event> allEvents = new LinkedList<>();
allEvents.addAll(homeEvents);
allEvents.addAll(awayEvents);
allEvents.sort( (e1, e2) -> e1.getEventDate() <= e2.getEventDate() ? -1 : 1 );
return allEvents;
}