本文整理匯總了Java中com.amazonaws.services.dynamodbv2.model.CreateTableRequest類的典型用法代碼示例。如果您正苦於以下問題:Java CreateTableRequest類的具體用法?Java CreateTableRequest怎麽用?Java CreateTableRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CreateTableRequest類屬於com.amazonaws.services.dynamodbv2.model包,在下文中一共展示了CreateTableRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: constructCreateTableRequest
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入依賴的package包/類
public CreateTableRequest constructCreateTableRequest() {
ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<>();
attributeDefinitions.add(new AttributeDefinition().withAttributeName(partitionKeyName.toString()).withAttributeType("S"));
attributeDefinitions.add(new AttributeDefinition().withAttributeName(sortKeyName.toString()).withAttributeType("N"));
ArrayList<KeySchemaElement> keySchema = new ArrayList<>();
keySchema.add(new KeySchemaElement().withAttributeName(partitionKeyName.toString()).withKeyType(KeyType.HASH));
keySchema.add(new KeySchemaElement().withAttributeName(sortKeyName.toString()).withKeyType(KeyType.RANGE));
ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
.withReadCapacityUnits(1L)
.withWriteCapacityUnits(1L);
CreateTableRequest request = new CreateTableRequest()
.withTableName(tableName)
.withKeySchema(keySchema)
.withAttributeDefinitions(attributeDefinitions)
.withProvisionedThroughput(provisionedThroughput);
return request;
}
示例2: testCreateTableWithWait
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入依賴的package包/類
@Test
public void testCreateTableWithWait() throws Exception {
// Create fake responses from AWS. First response is still creating the table, second response the table
// has become active.
TableDescription creatingDescription = constructTableDescription(TableStatus.CREATING);
TableDescription createdDescription = constructTableDescription(TableStatus.ACTIVE);
CreateTableResult mockCreateResult = new CreateTableResult().withTableDescription(creatingDescription);
DescribeTableResult mockDescribeResultCreating = new DescribeTableResult().withTable(creatingDescription);
DescribeTableResult mockDescribeResultCreated = new DescribeTableResult().withTable(createdDescription);
// Create the table.
CreateTableRequest expectedRequest = dynamoDB.constructCreateTableRequest();
when(mockDynamoDBClient.createTable(expectedRequest)).thenReturn(mockCreateResult);
when(mockDynamoDBClient.describeTable(tableName)).thenReturn(mockDescribeResultCreating, mockDescribeResultCreated);
assertEquals(dynamoDB.create(), TEST_ARN);
verify(mockDynamoDBClient, times(1)).createTable(expectedRequest);
verify(mockDynamoDBClient, times(2)).describeTable(tableName);
}
示例3: createRecipientTable
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入依賴的package包/類
private void createRecipientTable() {
CreateTableRequest request
= new CreateTableRequest()
.withTableName(TABLE_NAME)
.withAttributeDefinitions(
new AttributeDefinition("_id", ScalarAttributeType.S)
)
.withKeySchema(
new KeySchemaElement("_id", KeyType.HASH)
)
.withProvisionedThroughput(new ProvisionedThroughput(10L, 10L));
ddb.createTable(request);
try {
TableUtils.waitUntilActive(ddb, TABLE_NAME);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
示例4: createHashAndSortTable
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入依賴的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);
}
示例5: createTable
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入依賴的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;
}
示例6: deploy
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入依賴的package包/類
public void deploy() {
final AttributeDefinition idAttr = new AttributeDefinition().withAttributeName("id")
.withAttributeType(ScalarAttributeType.S);
final ProvisionedThroughput throughput = new ProvisionedThroughput().withReadCapacityUnits(5L)
.withWriteCapacityUnits(5L);
final KeySchemaElement idKey = new KeySchemaElement().withAttributeName("id").withKeyType(KeyType.HASH);
final CreateTableRequest createTableRequest = new CreateTableRequest().withTableName("TranslateSlack")
.withAttributeDefinitions(idAttr)
.withKeySchema(idKey)
.withProvisionedThroughput(throughput);
;
;
ddb.createTable(createTableRequest);
}
示例7: setUp
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入依賴的package包/類
@Before
public void setUp() {
// Unique table for each run
tableName = "table" + String.valueOf(tableCount++);
dynamoDB.getDynamoDbClient().createTable(
new CreateTableRequest()
.withTableName(tableName)
.withKeySchema(new KeySchemaElement("id", "HASH"))
.withAttributeDefinitions(
new AttributeDefinition("id", "S")
)
.withProvisionedThroughput(
new ProvisionedThroughput(1L, 1L)
)
);
locker = new DynamoDbLocker(
new DynamoDB(dynamoDB.getDynamoDbClient()),
tableName,
Clock.systemUTC()
);
}
示例8: createTableAndWaitForActive
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入依賴的package包/類
void createTableAndWaitForActive(final CreateTableRequest request) throws BackendException {
final String tableName = request.getTableName();
Preconditions.checkArgument(!Strings.isNullOrEmpty(tableName), "Table name was null or empty");
final TableDescription desc;
try {
desc = this.describeTable(tableName);
if (null != desc && isTableAcceptingWrites(desc.getTableStatus())) {
return; //store existed
}
} catch (BackendNotFoundException e) {
log.debug(tableName + " did not exist yet, creating it", e);
}
createTable(request);
waitForTableCreation(tableName, false /*verifyIndexesList*/, null /*expectedLsiList*/, null /*expectedGsiList*/);
}
示例9: getTableSchema
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入依賴的package包/類
@Override
public CreateTableRequest getTableSchema() {
return super.getTableSchema()
.withAttributeDefinitions(
new AttributeDefinition()
.withAttributeName(Constants.JANUSGRAPH_HASH_KEY)
.withAttributeType(ScalarAttributeType.S),
new AttributeDefinition()
.withAttributeName(Constants.JANUSGRAPH_RANGE_KEY)
.withAttributeType(ScalarAttributeType.S))
.withKeySchema(
new KeySchemaElement()
.withAttributeName(Constants.JANUSGRAPH_HASH_KEY)
.withKeyType(KeyType.HASH),
new KeySchemaElement()
.withAttributeName(Constants.JANUSGRAPH_RANGE_KEY)
.withKeyType(KeyType.RANGE));
}
示例10: createIdentityTable
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入依賴的package包/類
/**
* Used to create the Identity Table. This function only needs to be called
* once.
*/
protected void createIdentityTable() throws DataAccessException {
ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
.withReadCapacityUnits(10L)
.withWriteCapacityUnits(5L);
ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
attributeDefinitions
.add(new AttributeDefinition().withAttributeName(ATTRIBUTE_USERNAME).withAttributeType("S"));
ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
tableKeySchema.add(new KeySchemaElement().withAttributeName(ATTRIBUTE_USERNAME).withKeyType(KeyType.HASH));
CreateTableRequest createTableRequest = new CreateTableRequest()
.withTableName(USER_TABLE)
.withProvisionedThroughput(provisionedThroughput)
.withAttributeDefinitions(attributeDefinitions)
.withKeySchema(tableKeySchema);
try {
ddb.createTable(createTableRequest);
} catch (AmazonClientException e) {
throw new DataAccessException("Failed to create table: " + USER_TABLE, e);
}
}
開發者ID:awslabs,項目名稱:amazon-cognito-developer-authentication-sample,代碼行數:29,代碼來源:UserAuthentication.java
示例11: createDeviceTable
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入依賴的package包/類
/**
* Used to create the device table. This function only needs to be called
* once.
*/
protected void createDeviceTable() throws DataAccessException {
ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
.withReadCapacityUnits(10L)
.withWriteCapacityUnits(5L);
ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
attributeDefinitions.add(new AttributeDefinition().withAttributeName(
ATTRIBUTE_UID).withAttributeType("S"));
ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
tableKeySchema.add(new KeySchemaElement().withAttributeName(ATTRIBUTE_UID)
.withKeyType(KeyType.HASH));
CreateTableRequest createTableRequest = new CreateTableRequest()
.withTableName(DEVICE_TABLE)
.withProvisionedThroughput(provisionedThroughput)
.withAttributeDefinitions(attributeDefinitions)
.withKeySchema(tableKeySchema);
try {
ddb.createTable(createTableRequest);
} catch (AmazonClientException e) {
throw new DataAccessException("Failed to create table: " + DEVICE_TABLE, e);
}
}
開發者ID:awslabs,項目名稱:amazon-cognito-developer-authentication-sample,代碼行數:30,代碼來源:DeviceAuthentication.java
示例12: createTable
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入依賴的package包/類
public void createTable(Class<? extends IDomain> domain){
CreateTableRequest tableRequest = dynamoDBMapper.generateCreateTableRequest(domain);
tableRequest = tableRequest.withProvisionedThroughput(new ProvisionedThroughput(5L,5L));
//check whether or not we need to add a provisioning throughput value for GSI
for (Method method : domain.getMethods()) {
if(method.isAnnotationPresent(DynamoDBIndexHashKey.class)){
String tempGSI = method.getAnnotation(DynamoDBIndexHashKey.class).globalSecondaryIndexName();
for (GlobalSecondaryIndex globalSecondaryIndex : tableRequest.getGlobalSecondaryIndexes()) {
if(globalSecondaryIndex.getIndexName().equals(tempGSI)){
globalSecondaryIndex.setProvisionedThroughput(new ProvisionedThroughput(5L,5L));
}
}
}
}
amazonDynamoDBClient.createTable(tableRequest);
}
示例13: createTable
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入依賴的package包/類
public void createTable() {
List<KeySchemaElement> keySchema = new ArrayList<>();
keySchema.add(
new KeySchemaElement()
.withAttributeName(sequenceNumber.getAttributeName())
.withKeyType(KeyType.HASH)
);
ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput();
provisionedThroughput.setReadCapacityUnits(10L);
provisionedThroughput.setWriteCapacityUnits(10L);
CreateTableRequest request = new CreateTableRequest()
.withTableName("example_table")
.withKeySchema(keySchema)
.withAttributeDefinitions(singleton(sequenceNumber))
.withProvisionedThroughput(provisionedThroughput);
client.createTable(request);
}
示例14: createTable
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入依賴的package包/類
/**
* Create a table with the given hashKey as row id
*
* @param tableName
* @param primaryKey
*/
public static void createTable(String tableName, String primaryKey) {
ArrayList<KeySchemaElement> ks = new ArrayList<KeySchemaElement>();
ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
ks.add(new KeySchemaElement().withAttributeName(primaryKey)
.withKeyType(KeyType.HASH));
attributeDefinitions.add(new AttributeDefinition().withAttributeName(
primaryKey).withAttributeType("S"));
CreateTableRequest request = new CreateTableRequest()
.withTableName(tableName).withKeySchema(ks)
.withProvisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT);
request.setAttributeDefinitions(attributeDefinitions);
try {
DynamoDbHandler.CLIENT.createTable(request);
} catch (ResourceInUseException e) {
//System.err.println("Table '" + tableName + "' already exists");
}
}
示例15: safeCreateTable
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入依賴的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;
}
}
}