本文整理汇总了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;
}
示例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);
}
}
示例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);
}
}
示例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"));
}
示例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();
}
示例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();
}
}
}