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


Java DynamoDB.createTable方法代码示例

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


在下文中一共展示了DynamoDB.createTable方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTable

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

示例2: createTable

import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入方法依赖的package包/类
private void createTable(Class tableClass) {
    CreateTableRequest createTableRequest = mapper.generateCreateTableRequest(tableClass);

    createTableRequest.setProvisionedThroughput(new ProvisionedThroughput(dbReadCapacity, dbWriteCapacity));
    if (tableExists(createTableRequest.getTableName())) {
        LOG.info("Table {} already exists", createTableRequest.getTableName());
        return;
    }
    try {
        DynamoDB dynamoDB = new DynamoDB(amazonDynamoDB);
        Table table = dynamoDB.createTable(createTableRequest);
        LOG.info("Creating table {} ... ", createTableRequest.getTableName());
        table.waitForActive();
        LOG.info("Table {} was created successfully.", createTableRequest.getTableName());
    } catch (Exception e) {
        LOG.error("Failed to create table {}. ", createTableRequest.getTableName());
        LOG.error(e);
        throw new ConfigurationException("Failed to create table" + createTableRequest.getTableName(), e);
    }
}
 
开发者ID:SungardAS,项目名称:enhanced-snapshots,代码行数:21,代码来源:InitConfigurationServiceImpl.java

示例3: main

import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

        AmazonDynamoDBClient client = new AmazonDynamoDBClient();
        
        client.setEndpoint("http://localhost:8000");
        DynamoDB dynamoDB = new DynamoDB(client);
        
        String tableName = "Movies";
        Table table = dynamoDB.createTable(tableName,
                Arrays.asList(
                        new KeySchemaElement("year", KeyType.HASH),
                        new KeySchemaElement("title", KeyType.RANGE)), 
                Arrays.asList(
                        new AttributeDefinition("year", ScalarAttributeType.N),
                        new AttributeDefinition("title", ScalarAttributeType.S)), 
                new ProvisionedThroughput(10L, 10L));

        try {
            TableUtils.waitUntilActive(client, tableName);
            System.out.println("Table status: " + table.getDescription().getTableStatus());
        } catch (AmazonClientException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
 
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:26,代码来源:MoviesCreateTable.java

示例4: waiterMethodsShouldWorkWithWrapper

import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入方法依赖的package包/类
@Test
public void waiterMethodsShouldWorkWithWrapper() throws InterruptedException {
  DynamoDBClientWithStubbedWaiter subject = new DynamoDBClientWithStubbedWaiter(
      dynamoDbRule.getClient());

  DynamoDB db = new DynamoDB(subject);

  AttributeDefinition id = new AttributeDefinition("id", ScalarAttributeType.S);
  List<KeySchemaElement> keySchema = new ArrayList<>();

  keySchema.add(
      new KeySchemaElement()
          .withAttributeName(id.getAttributeName())
          .withKeyType(KeyType.HASH)
  );

  ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput();
  provisionedThroughput.setReadCapacityUnits(10L);
  provisionedThroughput.setWriteCapacityUnits(10L);

  CreateTableRequest request = new CreateTableRequest()
      .withTableName("test_table")
      .withKeySchema(keySchema)
      .withAttributeDefinitions(singleton(id))
      .withProvisionedThroughput(provisionedThroughput);

  Table result = db.createTable(request);
  TableDescription description = result.waitForActive();

  assertThat(description.getTableName(), is("test_table"));
}
 
开发者ID:mlk,项目名称:AssortmentOfJUnitRules,代码行数:32,代码来源:DynamoDBClientWithStubbedWaiterTest.java

示例5: createTable

import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入方法依赖的package包/类
public static TableDescription createTable(AmazonDynamoDB client, String tableName) throws InterruptedException {
    CreateTableRequest tableReq = new CreateTableRequest().withTableName(tableName)
            .withKeySchema(new KeySchemaElement("Id", KeyType.HASH))
            .withAttributeDefinitions(new AttributeDefinition("Id", ScalarAttributeType.N))
            .withProvisionedThroughput(new ProvisionedThroughput(10L, 10L))
            .withStreamSpecification(new StreamSpecification().withStreamEnabled(true).withStreamViewType(StreamViewType.NEW_AND_OLD_IMAGES));

    DynamoDB dynamoDB = new DynamoDB(client);
    Table table = dynamoDB.createTable(tableReq);
    return table.waitForActive();
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:12,代码来源:DynamoDBUtils.java

示例6: loadFromDynamoDB

import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入方法依赖的package包/类
@Test
public void loadFromDynamoDB()
        throws Exception
{
    DynamoDB dynamoDB = new DynamoDB(dynamoClient);

    ArrayList<AttributeDefinition> attributeDefinitions= new ArrayList<>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName("Id").withAttributeType("N"));

    ArrayList<KeySchemaElement> keySchema = new ArrayList<>();
    keySchema.add(new KeySchemaElement().withAttributeName("Id").withKeyType(KeyType.HASH));

    CreateTableRequest request = new CreateTableRequest()
            .withTableName(dynamoTableName)
            .withKeySchema(keySchema)
            .withAttributeDefinitions(attributeDefinitions)
            .withProvisionedThroughput(new ProvisionedThroughput()
                    .withReadCapacityUnits(1L)
                    .withWriteCapacityUnits(1L));

    ImmutableList<Item> items = ImmutableList.of(
            new Item().withPrimaryKey("Id", 0).withString("Name", "foo").withNumber("Score", 3.14f),
            new Item().withPrimaryKey("Id", 1).withString("Name", "bar").withNumber("Score", 1.23f),
            new Item().withPrimaryKey("Id", 2).withString("Name", "baz").withNumber("Score", 5.0f)
    );

    ImmutableList<Map<String, Object>> expected = ImmutableList.of(
            ImmutableMap.of("id", 0, "name", "foo", "score", 3.14f),
            ImmutableMap.of("id", 1, "name", "bar", "score", 1.23f),
            ImmutableMap.of("id", 2, "name", "baz", "score", 5.0f),
            ImmutableMap.of("id", 9, "name", "zzz", "score", 9.99f)
    );

    Table table = null;
    try {
        table = dynamoDB.createTable(request);
        table.waitForActive();

        items.forEach(table::putItem);

        runDigdagWithDynamoDB(configFile, "acceptance/redshift/load_from_dynamodb.dig", redshiftUser, Optional.absent());

        assertTableContents(DEST_TABLE, expected);
    }
    finally {
        if (table != null) {
            table.delete();
            table.waitForDelete();
        }
    }
}
 
开发者ID:treasure-data,项目名称:digdag,代码行数:52,代码来源:RedshiftIT.java


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