本文整理匯總了Java中com.amazonaws.services.dynamodbv2.AmazonDynamoDB.createTable方法的典型用法代碼示例。如果您正苦於以下問題:Java AmazonDynamoDB.createTable方法的具體用法?Java AmazonDynamoDB.createTable怎麽用?Java AmazonDynamoDB.createTable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.amazonaws.services.dynamodbv2.AmazonDynamoDB
的用法示例。
在下文中一共展示了AmazonDynamoDB.createTable方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createTable
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入方法依賴的package包/類
private static void createTable(AmazonDynamoDB dynamodb, String tableName, String tableKeyFieldName) {
List<AttributeDefinition> attributeDefinitions= new ArrayList<>();
attributeDefinitions.add(new AttributeDefinition().withAttributeName(tableKeyFieldName).withAttributeType("S"));
List<KeySchemaElement> keySchema = new ArrayList<>();
keySchema.add(new KeySchemaElement().withAttributeName(tableKeyFieldName).withKeyType(KeyType.HASH));
CreateTableRequest request = new CreateTableRequest()
.withTableName(tableName)
.withKeySchema(keySchema)
.withAttributeDefinitions(attributeDefinitions)
.withProvisionedThroughput(new ProvisionedThroughput()
.withReadCapacityUnits(1L)
.withWriteCapacityUnits(1L));
dynamodb.createTable(request);
//TODO: just to look at the result, if needed
// TableDescription table = dynamodb.describeTable(tableName).getTable();
}
示例2: safeCreateTable
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入方法依賴的package包/類
/**
* Private interface for creating tables which handles any instances of
* Throttling of the API
*
* @param dynamoClient
* @param dynamoTable
* @return
* @throws Exception
*/
public static CreateTableResult safeCreateTable(
final AmazonDynamoDB dynamoClient,
final CreateTableRequest createTableRequest) throws Exception {
CreateTableResult res = null;
final int tryMax = 10;
int tries = 0;
while (true) {
try {
res = dynamoClient.createTable(createTableRequest);
return res;
} catch (LimitExceededException le) {
if (tries < tryMax) {
// back off for 1 second
Thread.sleep(1000);
tries++;
} else {
throw le;
}
} catch (ResourceInUseException rie) {
// someone else is trying to create the table while we are, so
// return ok
return null;
}
}
}
示例3: createTable
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入方法依賴的package包/類
private static CreateTableResult createTable(AmazonDynamoDB ddb, String tableName, String hashKeyName) {
List<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
attributeDefinitions.add(new AttributeDefinition(hashKeyName, ScalarAttributeType.S));
List<KeySchemaElement> ks = new ArrayList<KeySchemaElement>();
ks.add(new KeySchemaElement(hashKeyName, KeyType.HASH));
ProvisionedThroughput provisionedthroughput = new ProvisionedThroughput(1000L, 1000L);
CreateTableRequest request =
new CreateTableRequest()
.withTableName(tableName)
.withAttributeDefinitions(attributeDefinitions)
.withKeySchema(ks)
.withProvisionedThroughput(provisionedthroughput);
return ddb.createTable(request);
}
示例4: create
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入方法依賴的package包/類
/**
* Create table.
* @throws InterruptedException If something fails
*/
public void create() throws InterruptedException {
final AmazonDynamoDB aws = this.region.aws();
final String name = this.request.getTableName();
aws.createTable(this.request);
Logger.info(this, "DynamoDB table '%s' creation requested...", name);
final DescribeTableRequest req = new DescribeTableRequest()
.withTableName(name);
while (true) {
final DescribeTableResult result = aws.describeTable(req);
if ("ACTIVE".equals(result.getTable().getTableStatus())) {
Logger.info(
this,
"DynamoDB table '%s' is %s",
name, result.getTable().getTableStatus()
);
break;
}
Logger.info(
this,
"waiting for DynamoDB table '%s': %s",
name, result.getTable().getTableStatus()
);
TimeUnit.SECONDS.sleep((long) Tv.TEN);
}
}
示例5: createTable
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入方法依賴的package包/類
/**
* Creates a DynamoDB Table with the correct properties to be used with a ProviderStore.
*/
public static CreateTableResult createTable(final AmazonDynamoDB ddb, final String tableName,
final ProvisionedThroughput provisionedThroughput) {
return ddb.createTable(Arrays.asList(new AttributeDefinition(DEFAULT_HASH_KEY,
ScalarAttributeType.S), new AttributeDefinition(DEFAULT_RANGE_KEY,
ScalarAttributeType.N)), tableName, Arrays.asList(new KeySchemaElement(
DEFAULT_HASH_KEY, KeyType.HASH), new KeySchemaElement(DEFAULT_RANGE_KEY,
KeyType.RANGE)), provisionedThroughput);
}
示例6: open
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入方法依賴的package包/類
private void open(boolean batchLoading)
{
if(type == GraphDatabaseType.TITAN_DYNAMODB && config.getDynamodbPrecreateTables()) {
List<CreateTableRequest> requests = new LinkedList<>();
long wcu = config.getDynamodbTps();
long rcu = Math.max(1, config.dynamodbConsistentRead() ? wcu : (wcu / 2));
for(String store : Constants.REQUIRED_BACKEND_STORES) {
final String tableName = config.getDynamodbTablePrefix() + "_" + store;
if(BackendDataModel.MULTI == config.getDynamodbDataModel()) {
requests.add(DynamoDBStore.createTableRequest(tableName,
rcu, wcu));
} else if(BackendDataModel.SINGLE == config.getDynamodbDataModel()) {
requests.add(DynamoDBSingleRowStore.createTableRequest(tableName, rcu, wcu));
}
}
//TODO is this autocloseable?
final AmazonDynamoDB client =
new AmazonDynamoDBClient(Client.createAWSCredentialsProvider(config.getDynamodbCredentialsFqClassName(),
config.getDynamodbCredentialsCtorArguments() == null ? null : config.getDynamodbCredentialsCtorArguments().split(",")));
client.setEndpoint(config.getDynamodbEndpoint());
for(CreateTableRequest request : requests) {
try {
client.createTable(request);
} catch(ResourceInUseException ignore) {
//already created, good
}
}
client.shutdown();
}
titanGraph = buildTitanGraph(type, dbStorageDirectory, config, batchLoading);
}
示例7: main
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入方法依賴的package包/類
public static void main(String[] args)
{
final String USAGE = "\n" +
"Usage:\n" +
" CreateTable <table>\n\n" +
"Where:\n" +
" table - the table to create.\n\n" +
"Example:\n" +
" CreateTable HelloTable\n";
if (args.length < 1) {
System.out.println(USAGE);
System.exit(1);
}
/* Read the name from command args */
String table_name = args[0];
System.out.format(
"Creating table \"%s\" with a simple primary key: \"Name\".\n",
table_name);
CreateTableRequest request = new CreateTableRequest()
.withAttributeDefinitions(new AttributeDefinition(
"Name", ScalarAttributeType.S))
.withKeySchema(new KeySchemaElement("Name", KeyType.HASH))
.withProvisionedThroughput(new ProvisionedThroughput(
new Long(10), new Long(10)))
.withTableName(table_name);
final AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();
try {
CreateTableResult result = ddb.createTable(request);
System.out.println(result.getTableDescription().getTableName());
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
System.out.println("Done!");
}
示例8: main
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入方法依賴的package包/類
public static void main(String[] args)
{
final String USAGE = "\n" +
"Usage:\n" +
" CreateTable <table>\n\n" +
"Where:\n" +
" table - the table to create.\n\n" +
"Example:\n" +
" CreateTable GreetingsTable\n";
if (args.length < 1) {
System.out.println(USAGE);
System.exit(1);
}
/* Read the name from command args */
String table_name = args[0];
System.out.format("Creating table %s\n with a composite primary key:\n");
System.out.format("* Language - partition key\n");
System.out.format("* Greeting - sort key\n");
CreateTableRequest request = new CreateTableRequest()
.withAttributeDefinitions(
new AttributeDefinition("Language", ScalarAttributeType.S),
new AttributeDefinition("Greeting", ScalarAttributeType.S))
.withKeySchema(
new KeySchemaElement("Language", KeyType.HASH),
new KeySchemaElement("Greeting", KeyType.RANGE))
.withProvisionedThroughput(
new ProvisionedThroughput(new Long(10), new Long(10)))
.withTableName(table_name);
final AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();
try {
CreateTableResult result = ddb.createTable(request);
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
System.out.println("Done!");
}
示例9: execute
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入方法依賴的package包/類
@Override
public Table execute() throws MetaModelException {
final MutableTable table = getTable();
final String tableName = table.getName();
final Collection<AttributeDefinition> attributes = new ArrayList<>();
final Collection<KeySchemaElement> keySchema = new ArrayList<>();
final Collection<GlobalSecondaryIndex> globalSecondaryIndices = new ArrayList<>();
final long readCapacity = Long.parseLong(System.getProperty(
DynamoDbDataContext.SYSTEM_PROPERTY_THROUGHPUT_READ_CAPACITY, "5"));
final long writeCapacity = Long.parseLong(System.getProperty(
DynamoDbDataContext.SYSTEM_PROPERTY_THROUGHPUT_WRITE_CAPACITY, "5"));
final ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput(readCapacity, writeCapacity);
for (Column column : table.getColumns()) {
if (column.isPrimaryKey()) {
final KeyType keyType = getKeyType(column.getRemarks());
keySchema.add(new KeySchemaElement(column.getName(), keyType));
attributes.add(new AttributeDefinition(column.getName(), DynamoDbUtils.toAttributeType(column
.getType())));
}
}
final CreateTableRequest createTableRequest = new CreateTableRequest();
createTableRequest.setTableName(tableName);
createTableRequest.setAttributeDefinitions(attributes);
createTableRequest.setGlobalSecondaryIndexes(globalSecondaryIndices);
createTableRequest.setKeySchema(keySchema);
createTableRequest.setProvisionedThroughput(provisionedThroughput);
final AmazonDynamoDB client = getUpdateCallback().getDataContext().getDynamoDb();
final CreateTableResult createTableResult = client.createTable(createTableRequest);
// await the table creation to be "done".
{
String tableStatus = createTableResult.getTableDescription().getTableStatus();
while (TableStatus.CREATING.name().equals(tableStatus)) {
logger.debug("Waiting for table status to be ACTIVE. Currently: {}", tableStatus);
try {
Thread.sleep(300);
} catch (InterruptedException e) {
getUpdateCallback().setInterrupted(true);
}
tableStatus = client.describeTable(tableName).getTable().getTableStatus();
}
}
return table;
}
示例10: startsAndStops
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入方法依賴的package包/類
/**
* Instances can start and stop.
* @throws Exception If something is wrong
*/
@Test
public void startsAndStops() throws Exception {
final int port = this.reserve();
final Instances instances = new Instances();
instances.start(
new File(InstancesTest.DIST), port,
new File(System.getProperty("java.home")),
Collections.singletonList("-inMemory")
);
try {
final AmazonDynamoDB aws = new AmazonDynamoDBClient(
new BasicAWSCredentials("AWS-key", "AWS-secret")
);
aws.setEndpoint(String.format("http://localhost:%d", port));
final String table = "test";
final String attr = "key";
final CreateTableResult result = aws.createTable(
new CreateTableRequest()
.withTableName(table)
.withProvisionedThroughput(
new ProvisionedThroughput()
.withReadCapacityUnits(1L)
.withWriteCapacityUnits(1L)
)
.withAttributeDefinitions(
new AttributeDefinition()
.withAttributeName(attr)
.withAttributeType(ScalarAttributeType.S)
)
.withKeySchema(
new KeySchemaElement()
.withAttributeName(attr)
.withKeyType(KeyType.HASH)
)
);
MatcherAssert.assertThat(
result.getTableDescription().getTableName(),
Matchers.equalTo(table)
);
aws.putItem(
new PutItemRequest()
.withTableName(table)
.addItemEntry(attr, new AttributeValue("testvalue"))
);
} finally {
instances.stop(port);
}
}