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


Java Item类代码示例

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


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

示例1: queryGSI

import com.amazonaws.services.dynamodbv2.document.Item; //导入依赖的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: create

import com.amazonaws.services.dynamodbv2.document.Item; //导入依赖的package包/类
@Override public Void create(Group group) {
  Item item = preparePutItem(group);

  PutItemSpec putItemSpec = new PutItemSpec()
      .withItem(item)
      .withConditionExpression("attribute_not_exists(#ns_key)")
      .withNameMap(new NameMap().with("#ns_key", HASH_KEY));

  Table table = dynamoDB.getTable(groupTableName);
  final Supplier<PutItemOutcome> putItemOutcomeSupplier = () -> {
    try {
      return table.putItem(putItemSpec);
    } catch (ConditionalCheckFailedException e) {
      throwConflictAlreadyExists(group);
      return null;
    }
  };
  return putItem(group, putItemOutcomeSupplier);
}
 
开发者ID:dehora,项目名称:outland,代码行数:20,代码来源:DefaultGroupStorage.java

示例3: query

import com.amazonaws.services.dynamodbv2.document.Item; //导入依赖的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: transform

import com.amazonaws.services.dynamodbv2.document.Item; //导入依赖的package包/类
@Override
public void transform(Item scoreItem, DynamoDB dynamodb) {
    String playerName = scoreItem.getString(PLAYER_NAME);
    int score = scoreItem.getInt(SCORE);
    int gameLength = scoreItem.getInt(GAME_LENGTH);
    
    /*
     * The XSpec API allows you to use DynamoDB's expression language
     * to execute expressions on the service-side.
     *  
     * https://java.awsblog.com/post/TxBG87QOQZRZJF/-DynamoDB-XSpec-API  
     */
    Table viewTable = dynamodb.getTable(PLAYER_STATS_TABLE_NAME);
    UpdateItemExpressionSpec incrementTotalOrder = new ExpressionSpecBuilder()
            .addUpdate(N(TOTAL_SCORE).add(score))
            .addUpdate(N(TOTAL_GAMEPLAY).add(gameLength))
            .addUpdate(N(TOTAL_GAMES).add(1))
            .buildForUpdate();
    viewTable.updateItem(PLAYER_NAME, playerName, incrementTotalOrder);
}
 
开发者ID:aws-samples,项目名称:reinvent2015-practicaldynamodb,代码行数:21,代码来源:DataTransformer.java

示例5: findRepliesUsingAFilterExpression

import com.amazonaws.services.dynamodbv2.document.Item; //导入依赖的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

示例6: loadByKey

import com.amazonaws.services.dynamodbv2.document.Item; //导入依赖的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

示例7: loadFeatureByKey

import com.amazonaws.services.dynamodbv2.document.Item; //导入依赖的package包/类
@Override public Optional<Feature> loadFeatureByKey(String group, String key) {
  logger.info("{}", kvp("op", "loadFeatureByKey", HASH_KEY, group, RANGE_KEY, key));

  Table table = dynamoDB.getTable(featureTableName);

  DynamoDbCommand<Item> cmd = new DynamoDbCommand<>("loadFeatureByKey",
      () -> getItem(group, key, table),
      () -> {
        throw new RuntimeException("loadFeatureById");
      },
      hystrixReadConfiguration,
      metrics);

  Item item = cmd.execute();
  if (item == null) {
    return Optional.empty();
  }
  return Optional.of(FeatureSupport.toFeature(item.getString("json")));
}
 
开发者ID:dehora,项目名称:outland,代码行数:20,代码来源:DefaultFeatureStorage.java

示例8: loadFeatures

import com.amazonaws.services.dynamodbv2.document.Item; //导入依赖的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

示例9: tryAddMissingPartition

import com.amazonaws.services.dynamodbv2.document.Item; //导入依赖的package包/类
private boolean tryAddMissingPartition(String dyanmoDBTaableName,DynamoDB dynamoDBClient, Partition partition){

        Table ddbTable= dynamoDBClient.getTable(dyanmoDBTaableName);

        Item item=new Item()
                .withPrimaryKey("PartitionSpec",partition.spec())
                .withString("PartitionPath",partition.path())
                .withString("PartitionName", partition.name());

        PutItemSpec itemSpec=new PutItemSpec()
                .withItem(item)
                .withConditionExpression("attribute_not_exists(#ps)")
                .withNameMap(new NameMap()
                        .with("#ps","PartitionSpec"));

        try{
            ddbTable.putItem(itemSpec);
            System.out.println("Item was added to the table.PartitionSpec="+partition.spec()+"; Path="+partition.path());
            return true;
        }
        catch(ConditionalCheckFailedException e){
            System.out.println(e.toString());
            System.out.println("Item already exists. PartitionSpec="+partition.spec()+"; Path="+partition.path());
            return false;
        }
    }
 
开发者ID:awslabs,项目名称:serverless-cf-analysis,代码行数:27,代码来源:CreateAthenaPartitionsBasedOnS3EventWithDDB.java

示例10: getNodes

import com.amazonaws.services.dynamodbv2.document.Item; //导入依赖的package包/类
@Override
public Map<String, AttributeValue> getNodes(WebsiteModel websiteModel) {

    try
    {
        ObjectMapper mapper = new ObjectMapper();
        String string = mapper.writeValueAsString(websiteModel);
        Item item = new Item().withJSON(Utils.params.nodes, string);
        return InternalUtils.toAttributeValues(item);
    }
    catch (JsonProcessingException e)
    {
        LOG.error(e.getMessage());
    }

    return new HashMap<>();
}
 
开发者ID:hafidsousa,项目名称:webcrawler,代码行数:18,代码来源:CrawlerBatchService.java

示例11: readStateInternal

import com.amazonaws.services.dynamodbv2.document.Item; //导入依赖的package包/类
protected void readStateInternal(final Object state, final Class<?> stateClass, final Item item, final ObjectMapper mapper)
{
    try
    {
        if (!state.getClass().equals(stateClass))
        {
            throw new IllegalArgumentException(String.format("State class (%s) did not match expected class (%s), Storage Extension should override generatePutItem method",
                    state.getClass().getName(),
                    stateClass.getName()));
        }

        mapper.readerForUpdating(state).readValue(item.getJSON(DynamoDBUtils.FIELD_NAME_DATA));
    }
    catch (IOException e)
    {
        throw new UncheckedException(e);
    }
}
 
开发者ID:orbit,项目名称:orbit-dynamodb,代码行数:19,代码来源:DynamoDBStorageExtension.java

示例12: readState

import com.amazonaws.services.dynamodbv2.document.Item; //导入依赖的package包/类
@Override
public StorageTestState readState(final String identity)
{
    final Table table = dynamoDBConnection.getDynamoDB().getTable(getTableName());
    final Item item = table.getItem("_id", generateItemId(identity));

    if (item != null)
    {
        try
        {
            final StorageTestState testState = new HelloState();
            dynamoDBConnection.getMapper().readerForUpdating(testState).readValue(item.getJSON("_state"));
            return testState;
        }
        catch (Exception e)
        {
            throw new UncheckedException(e);
        }
    }
    return null;
}
 
开发者ID:orbit,项目名称:orbit-dynamodb,代码行数:22,代码来源:DynamoDBPersistenceTest.java

示例13: next

import com.amazonaws.services.dynamodbv2.document.Item; //导入依赖的package包/类
@Override
public int next() {
  Stopwatch watch = Stopwatch.createStarted();
  topLevelState.reset();

  int count = 0;
  Page<Item, ?> page;
  while (resultIter.hasNext()) {
    page = resultIter.next();
    for (Item item : page) {
      int rowCount = count++;
      for (Map.Entry<String, Object> attribute : item.attributes()) {
        String name = attribute.getKey();
        Object value = attribute.getValue();
        SchemaPath column = getSchemaPath(name);
        topLevelState.setColumn(column);
        handleTopField(rowCount, name, value, topLevelState);
      }
    }
  }

  topLevelState.setRowCount(count);
  LOG.debug("Took {} ms to get {} records", watch.elapsed(TimeUnit.MILLISECONDS), count);
  return count;
}
 
开发者ID:fineoio,项目名称:drill-dynamo-adapter,代码行数:26,代码来源:DynamoRecordReader.java

示例14: verify

import com.amazonaws.services.dynamodbv2.document.Item; //导入依赖的package包/类
protected void verify(List<Map<String, Object>> rows, Item... items) {
  assertEquals("Wrong number of expected rows!" +
               "\nExpected: " + toString(items) +
               "\nGot rows: " + rows,
    items.length, rows.size());
  for (int i = 0; i < items.length; i++) {
    Map<String, Object> row = rows.get(i);
    Item item = items[i];
    assertEquals("Wrong number of fields in row! Got row: " + row + "\nExpected: " + item,
      row.size(), item.asMap().size());
    for (Map.Entry<String, Object> field : row.entrySet()) {
      String name = field.getKey();
      Object o = field.getValue();
      if (o instanceof Text) {
        o = o.toString();
      }
      if (item.get(name) instanceof Number) {
        equalsNumber(item, name, row);
      } else if (o instanceof byte[]) {
        assertArrayEquals("Array mismatch for: " + name, (byte[]) item.get(name), (byte[]) o);
      } else {
        assertEquals("Mismatch for: " + name, item.get(name), o);
      }
    }
  }
}
 
开发者ID:fineoio,项目名称:drill-dynamo-adapter,代码行数:27,代码来源:BaseDynamoTest.java

示例15: testPrimaryAndSortKeySpecification

import com.amazonaws.services.dynamodbv2.document.Item; //导入依赖的package包/类
@Test
public void testPrimaryAndSortKeySpecification() throws Exception {
  String pk = "pk", sort = "sort";
  Table table = createHashAndSortTable(pk, sort);
  Item item = new Item();
  item.with(pk, "p1");
  item.with(sort, "s1");
  item.with(COL1, "1");
  table.putItem(item);

  Item item2 = new Item();
  item2.with(pk, "p1");
  item2.with(sort, "s0");
  item2.with(COL1, "2");
  table.putItem(item2);
  // should create a get
  String query = selectStarWithPK("p1", "t", table) + " AND sort = 's1'";
  verify(runAndReadResults(query), item);
  validatePlanWithGets(query,
    pkEquals("p1").and(create("equal", "sort", "s1")));
  // should create a query
  query = selectStarWithPK("p1", "t", table) + " AND sort >= 's1'";
  verify(runAndReadResults(query), item);
  validatePlanWithQueries(query, of(pkEquals("p1").and(
    DynamoPlanValidationUtils.gte("sort", "s1")), null));
}
 
开发者ID:fineoio,项目名称:drill-dynamo-adapter,代码行数:27,代码来源:TestDynamoFilterPushdown.java


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