当前位置: 首页>>代码示例>>Java>>正文


Java QuerySpec类代码示例

本文整理汇总了Java中com.amazonaws.services.dynamodbv2.document.spec.QuerySpec的典型用法代码示例。如果您正苦于以下问题:Java QuerySpec类的具体用法?Java QuerySpec怎么用?Java QuerySpec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


QuerySpec类属于com.amazonaws.services.dynamodbv2.document.spec包,在下文中一共展示了QuerySpec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: queryGSI

import com.amazonaws.services.dynamodbv2.document.spec.QuerySpec; //导入依赖的package包/类
private static Page<Item, QueryOutcome> queryGSI(String appid, Pager p) {
	Pager pager = (p != null) ? p : new Pager();
	Index index = getSharedIndex();
	QuerySpec spec = new QuerySpec().
			withMaxPageSize(pager.getLimit()).
			withMaxResultSize(pager.getLimit()).
			withKeyConditionExpression(Config._APPID + " = :aid").
			withValueMap(new ValueMap().withString(":aid", appid));

	if (!StringUtils.isBlank(pager.getLastKey())) {
		spec = spec.withExclusiveStartKey(new KeyAttribute(Config._APPID, appid),	// HASH/PARTITION KEY
				new KeyAttribute(Config._ID, pager.getLastKey()), // RANGE/SORT KEY
				new KeyAttribute(Config._KEY, getKeyForAppid(pager.getLastKey(), appid))); // TABLE PRIMARY KEY
	}
	return index != null ? index.query(spec).firstPage() : null;
}
 
开发者ID:Erudika,项目名称:para,代码行数:17,代码来源:AWSDynamoUtils.java

示例2: queryRelationExists

import com.amazonaws.services.dynamodbv2.document.spec.QuerySpec; //导入依赖的package包/类
@Override public boolean queryRelationExists(String relationHashKey, String relationRangeKey) {

    Table table = dynamoDB.getTable(this.groupGraphTableName);

    QuerySpec querySpec = new QuerySpec()
        .withKeyConditionExpression("subject = :k_subject and object_relation = :k_object_relation")
        .withValueMap(new ValueMap()
            .withString(":k_subject", relationHashKey)
            .withString(":k_object_relation", relationRangeKey)
        )
        .withMaxResultSize(1)
        .withConsistentRead(true);

    DynamoDbCommand<ItemCollection<QueryOutcome>> cmd = new DynamoDbCommand<>("queryRelation",
        () -> queryTable(table, querySpec),
        () -> {
          throw new RuntimeException("queryRelation");
        },
        dynamodbNamespaceGraphQueryHystrix,
        metrics);

    // can't use getLastLowLevelResult directly; it's false unless the outcome is iterated first :|
    return cmd.execute().iterator().hasNext();
  }
 
开发者ID:dehora,项目名称:outland,代码行数:25,代码来源:DefaultGroupStorage.java

示例3: query

import com.amazonaws.services.dynamodbv2.document.spec.QuerySpec; //导入依赖的package包/类
private QueryOutcome query(Object hk, QuerySpec querySpec, PageIterator pageIterator) {
    if ( null == _convertMarker ) {
        throw new IllegalStateException("Index must first be initialized with ConvertMarker");
    }
    if ( pageIterator.getPageSize() <= 0 ) {
        return new QueryOutcome(new QueryResult());
    }
    ItemCollection<QueryOutcome> itemCollection =
        maybeBackoff(true, () ->
                     _query.query(withMarker(querySpec.withHashKey(_hkName, hk), pageIterator, hk)));

    if ( null != itemCollection ) {
        Iterator<Page<Item, QueryOutcome>> iterator = itemCollection.pages().iterator();
        if ( iterator.hasNext() ) {
            QueryOutcome outcome = maybeBackoff(true, () -> iterator.next().getLowLevelResult());
            QueryResult result = outcome.getQueryResult();
            if ( null != pageIterator.getMarker() && null != result.getItems() && result.getItems().size() > 0 ) {
                pageIterator.setPrevMarker(toMarker(result.getItems().get(0), true));
            } else {
                pageIterator.setPrevMarker(null);
            }
            Map<String,AttributeValue> lastKey = result.getLastEvaluatedKey();
            if ( null != lastKey && ! lastKey.isEmpty() ) {
                pageIterator.setMarker(toMarker(lastKey, true));
            } else {
                pageIterator.setMarker(null);
            }
            return outcome;
        }
    }
    pageIterator.setPrevMarker(null);
    pageIterator.setMarker(null);
    return new QueryOutcome(new QueryResult());
}
 
开发者ID:Distelli,项目名称:java-persistence,代码行数:35,代码来源:DdbIndex.java

示例4: findRepliesUsingAFilterExpression

import com.amazonaws.services.dynamodbv2.document.spec.QuerySpec; //导入依赖的package包/类
private static void findRepliesUsingAFilterExpression(String forumName, String threadSubject) {

        Table table = dynamoDB.getTable(tableName);
        
        String replyId = forumName + "#" + threadSubject;

        QuerySpec spec = new QuerySpec()
            .withProjectionExpression("Message, ReplyDateTime, PostedBy")
            .withKeyConditionExpression("Id = :v_id")
            .withFilterExpression("PostedBy = :v_postedby")
            .withValueMap(new ValueMap()
                .withString(":v_id", replyId)
                .withString(":v_postedby", "User B"));
        
        ItemCollection<QueryOutcome> items = table.query(spec);

        System.out.println("\nfindRepliesUsingAFilterExpression results:");
        Iterator<Item> iterator = items.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next().toJSONPretty());
        }    
     }
 
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:23,代码来源:DocumentAPIQuery.java

示例5: loadByKey

import com.amazonaws.services.dynamodbv2.document.spec.QuerySpec; //导入依赖的package包/类
@Override public Optional<Group> loadByKey(String key) {
  Table table = dynamoDB.getTable(this.groupTableName);

  QuerySpec querySpec = new QuerySpec()
      .withKeyConditionExpression(HASH_KEY + " = :k_app_key")
      .withValueMap(new ValueMap()
          .withString(":k_app_key", key)
      )
      .withMaxResultSize(1)
      .withConsistentRead(true);

  DynamoDbCommand<ItemCollection<QueryOutcome>> cmd = new DynamoDbCommand<>("loadByKey",
      () -> queryTable(table, querySpec),
      () -> {
        throw new RuntimeException("loadByKey");
      },
      dynamodbNamespaceGraphQueryHystrix,
      metrics);

  final ItemCollection<QueryOutcome> items = cmd.execute();
  final IteratorSupport<Item, QueryOutcome> iterator = items.iterator();
  if (iterator.hasNext()) {
    return Optional.of(GroupSupport.toGroup(iterator.next().getString("json")));
  }

  return Optional.empty();
}
 
开发者ID:dehora,项目名称:outland,代码行数:28,代码来源:DefaultGroupStorage.java

示例6: loadFeatures

import com.amazonaws.services.dynamodbv2.document.spec.QuerySpec; //导入依赖的package包/类
@Override public List<Feature> loadFeatures(String group) {
  logger.info("{}", kvp("op", "loadFeatures", "group", group));
  List<Feature> features = Lists.newArrayList();

  Table table = dynamoDB.getTable(featureTableName);

  QuerySpec querySpec = new QuerySpec()
      .withKeyConditionExpression(HASH_KEY + " = :k_" + HASH_KEY)
      .withValueMap(new ValueMap().withString(":k_" + HASH_KEY, group))
      .withConsistentRead(true);

  DynamoDbCommand<ItemCollection<QueryOutcome>> cmd = new DynamoDbCommand<>("loadFeatures",
      () -> queryTable(table, querySpec),
      () -> {
        throw new RuntimeException("loadFeatureById");
      },
      hystrixReadConfiguration,
      metrics);

  ItemCollection<QueryOutcome> items = cmd.execute();

  for (Page<Item, QueryOutcome> page : items.pages()) {
    page.forEach(item -> features.add(FeatureSupport.toFeature(item.getString("json"))));
  }

  return features;
}
 
开发者ID:dehora,项目名称:outland,代码行数:28,代码来源:DefaultFeatureStorage.java

示例7: queryItems

import com.amazonaws.services.dynamodbv2.document.spec.QuerySpec; //导入依赖的package包/类
@Override
public QueryItemsBuilder<T> queryItems(Object hk, PageIterator pageIterator) {
    if ( null == _convertMarker ) {
        throw new IllegalStateException("Index must first be initialized with ConvertMarker");
    }
    QuerySpec spec = withMarker(new QuerySpec().withHashKey(_hkName, hk), pageIterator, hk);
    return new QueryItemsBuilderImpl<T>(spec, _rkName, pageIterator, this::countItems, this::listItems, _clazz, _encryption);
}
 
开发者ID:Distelli,项目名称:java-persistence,代码行数:9,代码来源:DdbIndex.java

示例8: withMarker

import com.amazonaws.services.dynamodbv2.document.spec.QuerySpec; //导入依赖的package包/类
private QuerySpec withMarker(QuerySpec spec, PageIterator pageIterator, Object hk) {
    if ( null != pageIterator.getMarker() ) {
        spec.withExclusiveStartKey(fromMarker(hk, pageIterator.getMarker()));
    }
    int pageSize = pageIterator.getPageSize();
    if ( pageSize != Integer.MAX_VALUE ) {
        spec.withMaxPageSize(pageSize);
    }
    return spec.withScanIndexForward(pageIterator.isForward());
}
 
开发者ID:Distelli,项目名称:java-persistence,代码行数:11,代码来源:DdbIndex.java

示例9: QueryItemsBuilderImpl

import com.amazonaws.services.dynamodbv2.document.spec.QuerySpec; //导入依赖的package包/类
public QueryItemsBuilderImpl(QuerySpec spec, String rangeKeyName, PageIterator iter, CountItems countItems, ListItems listItems, Class<T> clazz, DDBEncryption encryption) {
    _spec = spec;
    _rkName = rangeKeyName;
    _iter = iter;
    _countItems = countItems;
    _listItems = listItems;
    _clazz = clazz;
    _encryption = encryption;
}
 
开发者ID:Distelli,项目名称:java-persistence,代码行数:10,代码来源:QueryItemsBuilderImpl.java

示例10: retrieveRecordsForProvince

import com.amazonaws.services.dynamodbv2.document.spec.QuerySpec; //导入依赖的package包/类
@Override
public List<String> retrieveRecordsForProvince(String dataSetLabel, String infoSetTag, Province province, Locale locale) {
    if (!useDynamoDirect) {
        URI uriToCall = baseBuilder()
                .path("/records/{dataset}/{infoSet}")
                .queryParam("province", province.toString())
                .queryParam("locale", locale.toLanguageTag())
                .buildAndExpand(dataSetLabel, infoSetTag).toUri();

        log.info("assembled URI to get records = {}", uriToCall.toString());

        return getFromUri(uriToCall);
    } else {
        DynamoDB dynamoDB = new DynamoDB(dynamoDBClient);
        Table geoApiTable = dynamoDB.getTable("geo_" + dataSetLabel.toLowerCase());
        log.info("querying from table, name: {}, number of rows: {}",
                "geo_" + dataSetLabel.toLowerCase(), geoApiTable.describe().toString());
        log.info("looking for province, with name: {}, on infoSet: {}", province.name(), infoSetTag);

        Index provinceIndex = geoApiTable.getIndex("lowestGeoInfo"); // figure out how to adapt when province != lowest
        QuerySpec querySpec = new QuerySpec()
                .withKeyConditionExpression("province = :prv and infoTag = :info")
                .withValueMap(new ValueMap()
                        .withString(":prv", province.name())
                        .withString(":info", infoSetTag));

        try {
            ItemCollection<QueryOutcome> records = provinceIndex.query(querySpec);
            List<String> result = new ArrayList<>();
            records.iterator().forEachRemaining(i -> result.add(i.getString("description")));
            log.info("iterated through the results, number of results: {}", result.size());
            return result;
        } catch (Exception e) {
            log.error("Error!", e);
            throw new IllegalArgumentException("No results for that dataset, province and field");
        }
    }
}
 
开发者ID:grassrootza,项目名称:grassroot-platform,代码行数:39,代码来源:LocationInfoBrokerImpl.java

示例11: addRangeKeyConditionToQuerySpec

import com.amazonaws.services.dynamodbv2.document.spec.QuerySpec; //导入依赖的package包/类
private static <T extends Item> void addRangeKeyConditionToQuerySpec(final QuerySpec querySpec,
        final CompoundAttributeQuery compoundAttributeQuery, final Class<T> itemClass) {
    final String supportingConditionStringValue = compoundAttributeQuery.getSupportingCondition().getValues().iterator()
            .next();
    final Operators comparisonOperator = compoundAttributeQuery.getSupportingCondition().getComparisonOperator();
    final Class<?> supportingAttributeType = compoundAttributeQuery.getSupportingAttributeType(itemClass);

    try {
        final Object supportingConditionValue = supportingAttributeType.getConstructor(String.class).newInstance(supportingConditionStringValue);

        final RangeKeyCondition rangeKeyCondition = RangeKeyConditionBuilder
                .build(compoundAttributeQuery.getSupportingAttributeName(), supportingConditionValue, comparisonOperator);
        querySpec.withRangeKeyCondition(rangeKeyCondition);
    } catch (final Exception e) {
        throw new PersistenceResourceFailureException(
                String.format("Could not add range key condition for query: %s on item %s.", compoundAttributeQuery,
                        itemClass.getSimpleName()),
                e);
    }
}
 
开发者ID:travel-cloud,项目名称:Cheddar,代码行数:21,代码来源:QuerySpecBuilder.java

示例12: shouldBuild_withAttributeQuery

import com.amazonaws.services.dynamodbv2.document.spec.QuerySpec; //导入依赖的package包/类
@Test
public void shouldBuild_withAttributeQuery() {
    // Given
    final String attributeName = randomString(10);
    final Condition mockCondition = randomCondition(1);
    final String expectedValue = mockCondition.getValues().iterator().next();
    final AttributeQuery mockAttributeQuery = mock(AttributeQuery.class);

    when(mockAttributeQuery.getAttributeName()).thenReturn(attributeName);
    when(mockAttributeQuery.getCondition()).thenReturn(mockCondition);

    // When
    final QuerySpec querySpec = QuerySpecBuilder.build(mockAttributeQuery, StubItem.class);

    // Then
    assertEquals(attributeName, querySpec.getHashKey().getName());
    assertEquals(expectedValue, querySpec.getHashKey().getValue());
    assertNull(querySpec.getRangeKeyCondition());
}
 
开发者ID:travel-cloud,项目名称:Cheddar,代码行数:20,代码来源:QuerySpecBuilderTest.java

示例13: shouldQueryTable

import com.amazonaws.services.dynamodbv2.document.spec.QuerySpec; //导入依赖的package包/类
@Test
public void shouldQueryTable() {
    // Given
    final ItemId itemId = new ItemId(randomId());

    final ItemConfiguration itemConfiguration = new ItemConfiguration(StubItem.class, tableName);
    final Collection<ItemConfiguration> itemConfigurations = Arrays.asList(itemConfiguration);
    when(mockDatabaseSchemaHolder.itemConfigurations()).thenReturn(itemConfigurations);

    final Table mockTable = mock(Table.class);
    when(mockDynamoDBClient.getTable(any(String.class))).thenReturn(mockTable);

    final DynamoDocumentStoreTemplate dynamoDocumentStoreTemplate = new DynamoDocumentStoreTemplate(
            mockDatabaseSchemaHolder);
    dynamoDocumentStoreTemplate.initialize(mockAmazonDynamoDbClient);

    final ItemCollection<QueryOutcome> outcome = mock(ItemCollection.class);
    when(mockTable.query(any(QuerySpec.class))).thenReturn(outcome);
    // when
    dynamoDocumentStoreTemplate.fetch(new AttributeQuery("id", new Condition(Operators.EQUALS, itemId.value())),
            StubItem.class);
    // then
    verify(mockTable.query(any(QuerySpec.class)));
}
 
开发者ID:travel-cloud,项目名称:Cheddar,代码行数:25,代码来源:DynamoDocumentStoreTemplateTest.java

示例14: build

import com.amazonaws.services.dynamodbv2.document.spec.QuerySpec; //导入依赖的package包/类
public static <T extends Item> QuerySpec build(final AttributeQuery attributeQuery, final Class<T> itemClass) {
    if (CompoundAttributeQuery.class.isAssignableFrom(attributeQuery.getClass())) {
        final CompoundAttributeQuery compoundAttributeQuery = (CompoundAttributeQuery) attributeQuery;
        return buildWithHashAndRangeKey(compoundAttributeQuery, itemClass);
    }

    return buildWithHashKey(attributeQuery);
}
 
开发者ID:travel-cloud,项目名称:Cheddar,代码行数:9,代码来源:QuerySpecBuilder.java

示例15: buildWithHashAndRangeKey

import com.amazonaws.services.dynamodbv2.document.spec.QuerySpec; //导入依赖的package包/类
private static <T extends Item> QuerySpec buildWithHashAndRangeKey(
        final CompoundAttributeQuery compoundAttributeQuery, final Class<T> itemClass) {
    final Set<String> supportingConditionValues = compoundAttributeQuery.getSupportingCondition().getValues();
    validateSupportingConditionValues(supportingConditionValues);

    final QuerySpec querySpec = buildWithHashKey(compoundAttributeQuery);
    addRangeKeyConditionToQuerySpec(querySpec, compoundAttributeQuery, itemClass);

    return querySpec;
}
 
开发者ID:travel-cloud,项目名称:Cheddar,代码行数:11,代码来源:QuerySpecBuilder.java


注:本文中的com.amazonaws.services.dynamodbv2.document.spec.QuerySpec类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。