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


Java Table类代码示例

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


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

示例1: create

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

示例2: queryRelationExists

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

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

示例4: findRepliesUsingAFilterExpression

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

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

示例7: loadFeatures

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

示例8: tryAddMissingPartition

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

示例9: readState

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

示例10: createHashAndSortTable

import com.amazonaws.services.dynamodbv2.document.Table; //导入依赖的package包/类
protected Table createHashAndSortTable(String pk, String sort) throws InterruptedException {
  ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<>();
  ScalarAttributeType type = ScalarAttributeType.S;
  attributeDefinitions.add(new AttributeDefinition()
    .withAttributeName(pk).withAttributeType(type));
  attributeDefinitions
    .add(new AttributeDefinition().withAttributeName(sort).withAttributeType(type));
  ArrayList<KeySchemaElement> keySchema = new ArrayList<>();
  keySchema.add(new KeySchemaElement().withAttributeName(pk).withKeyType(KeyType.HASH));
  keySchema.add(new KeySchemaElement().withAttributeName(sort).withKeyType(KeyType.RANGE));

  CreateTableRequest request = new CreateTableRequest()
    .withKeySchema(keySchema)
    .withAttributeDefinitions(attributeDefinitions);
  return createTable(request);
}
 
开发者ID:fineoio,项目名称:drill-dynamo-adapter,代码行数:17,代码来源:BaseDynamoTest.java

示例11: createTable

import com.amazonaws.services.dynamodbv2.document.Table; //导入依赖的package包/类
protected Table createTable(CreateTableRequest request) throws InterruptedException {
  DynamoDB dynamoDB = new DynamoDB(tables.getAsyncClient());
  request.withProvisionedThroughput(new ProvisionedThroughput()
    .withReadCapacityUnits(5L)
    .withWriteCapacityUnits(6L));

  if (request.getTableName() == null) {
    String tableName = tables.getTestTableName();
    tableName = tableName.replace('-', '_');
    request.setTableName(tableName);
  }

  Table table = dynamoDB.createTable(request);
  table.waitForActive();
  return table;
}
 
开发者ID:fineoio,项目名称:drill-dynamo-adapter,代码行数:17,代码来源:BaseDynamoTest.java

示例12: testPrimaryAndSortKeySpecification

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

示例13: testWhereColumnEqualsNull

import com.amazonaws.services.dynamodbv2.document.Table; //导入依赖的package包/类
@Test
public void testWhereColumnEqualsNull() throws Exception {
  Item item = item();
  item.with(COL1, null);
  Table table = createTableWithItems(item);

  String query =
    selectStarWithPK("pk", "t", table) + " AND t." + COL1 + " = cast(null as varchar)";
  verify(runAndReadResults(query), item);
  ImmutablePair<DynamoFilterSpec, DynamoFilterSpec> spec =
    of(pkEquals("pk"), DynamoPlanValidationUtils


      .equals(COL1, null));
  validatePlanWithQueries(query, spec);
  // we return nulls are varchar b/c we can cast anything from varchar. Make sure that a
  // boolean null cast also works
  query = selectStarWithPK("pk", "t", table) + " AND t." + COL1 + " = cast(null as boolean)";
  verify(runAndReadResults(query), item);
  validatePlanWithQueries(query, spec);
}
 
开发者ID:fineoio,项目名称:drill-dynamo-adapter,代码行数:22,代码来源:TestDynamoFilterPushdown.java

示例14: testWhereNoColumnValueIsNull

import com.amazonaws.services.dynamodbv2.document.Table; //导入依赖的package包/类
/**
 * Similar to above, but we check for the non-existance of a column
 */
@Test
public void testWhereNoColumnValueIsNull() throws Exception {
  Item item = item();
  Table table = createTableWithItems(item);
  String query =
    selectStarWithPK("pk", "t", table) + " AND t." + COL1 + " = cast(null as varchar)";
  assertEquals("Should not have found a row when checking for = null and column not set!",
    0, runAndReadResults(query).size());
  ImmutablePair<DynamoFilterSpec, DynamoFilterSpec> spec =
    of(pkEquals("pk"), DynamoPlanValidationUtils
      .equals(COL1, null));
  validatePlanWithQueries(query, spec);
  // see above for why trying a different type
  query = selectStarWithPK("pk", "t", table) + " AND t." + COL1 + " = cast(null as BOOLEAN)";
  assertEquals("Should not have found a row when checking for = null and column not set!",
    0, runAndReadResults(query).size());
  validatePlanWithQueries(query, spec);
  query = selectStarWithPK("pk", "t", table) + " AND t." + COL1 + " IS NULL";
  verify(runAndReadResults(query), item);
  validatePlanWithQueries(query, of(spec.getLeft(), create("isNull", COL1)));
}
 
开发者ID:fineoio,项目名称:drill-dynamo-adapter,代码行数:25,代码来源:TestDynamoFilterPushdown.java

示例15: testSimpleScan

import com.amazonaws.services.dynamodbv2.document.Table; //导入依赖的package包/类
@Test
public void testSimpleScan() throws Exception {
  Item item = item();
  item.with(COL1, 1);
  Table table = createTableWithItems(item);
  String select = "SELECT *" + from(table) + "t WHERE t." + COL1 + " = 1";
  verify(runAndReadResults(select), item);
  DynamoFilterSpec spec = DynamoPlanValidationUtils.equals(COL1, 1);
  validatePlanWithScan(select, spec);

  Item item2 = new Item();
  item2.with(PK, "pk2");
  item2.with(COL1, 2);
  table.putItem(item2);
  verify(runAndReadResults(select), item);
  // plan doesn't change as the table gets larger
  validatePlanWithScan(select, spec);
}
 
开发者ID:fineoio,项目名称:drill-dynamo-adapter,代码行数:19,代码来源:TestDynamoFilterPushdown.java


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