本文整理匯總了Java中com.amazonaws.services.dynamodbv2.model.CreateTableRequest.setAttributeDefinitions方法的典型用法代碼示例。如果您正苦於以下問題:Java CreateTableRequest.setAttributeDefinitions方法的具體用法?Java CreateTableRequest.setAttributeDefinitions怎麽用?Java CreateTableRequest.setAttributeDefinitions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.amazonaws.services.dynamodbv2.model.CreateTableRequest
的用法示例。
在下文中一共展示了CreateTableRequest.setAttributeDefinitions方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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");
}
}
示例2: buildCreateTableRequest
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入方法依賴的package包/類
/**
* Builds the necessary requests to create tables
*
* @param tableName
* @param keySchema
* @param proThrou
* @param attrs
* @return
*/
public static CreateTableRequest buildCreateTableRequest(String tableName,
ArrayList<KeySchemaElement> keySchema, ProvisionedThroughput proThrou, Map<String, String> attrs) {
CreateTableRequest createTableRequest = new CreateTableRequest();
createTableRequest.setTableName(tableName);
createTableRequest.setKeySchema(keySchema);
ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
for (KeySchemaElement kEle : keySchema) {
AttributeDefinition attrDef = new AttributeDefinition();
attrDef.setAttributeName(kEle.getAttributeName());
attrDef.setAttributeType(attrs.get(kEle.getAttributeName()));
attributeDefinitions.add(attrDef);
}
createTableRequest.setAttributeDefinitions(attributeDefinitions);
createTableRequest.setProvisionedThroughput(proThrou);
return createTableRequest;
}
示例3: testCreateResourceTable
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入方法依賴的package包/類
@Test
public void testCreateResourceTable() {
final AmazonDynamoDB dynamoDB = PowerMock.createMock(AmazonDynamoDB.class);
PowerMock.mockStatic(DynamoDBManager.class);
final CreateTableRequest request = new CreateTableRequest();
request.setAttributeDefinitions(MarsDynamoDBManager.RESOURCE_TABLE_ATTRIBUTE_DEFINITIONS);
request.setKeySchema(MarsDynamoDBManager.RESOURCE_TABLE_KEY_SCHEMA);
request.setProvisionedThroughput(PROVISIONED_THROUGHPUT);
request.setTableName(TABLE_NAME);
DynamoDBManager.createTable(dynamoDB, request);
PowerMock.expectLastCall().andReturn(null);
PowerMock.replayAll();
MarsDynamoDBManager.createResourceTable(dynamoDB, TABLE_NAME, PROVISIONED_THROUGHPUT);
PowerMock.verifyAll();
}
示例4: createExampleTable
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入方法依賴的package包/類
static void createExampleTable() {
// Provide the initial provisioned throughput values as Java long data types
ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
.withReadCapacityUnits(5L)
.withWriteCapacityUnits(6L);
CreateTableRequest request = new CreateTableRequest()
.withTableName(tableName)
.withProvisionedThroughput(provisionedThroughput);
ArrayList<AttributeDefinition> attributeDefinitions= new ArrayList<AttributeDefinition>();
attributeDefinitions.add(new AttributeDefinition().withAttributeName("Id").withAttributeType("N"));
request.setAttributeDefinitions(attributeDefinitions);
ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
tableKeySchema.add(new KeySchemaElement().withAttributeName("Id").withKeyType(KeyType.HASH));
request.setKeySchema(tableKeySchema);
client.createTable(request);
waitForTableToBecomeAvailable(tableName);
getTableInformation();
}
示例5: createImageTable
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入方法依賴的package包/類
/**
* Creates the table that stores images.
*
* @param dynamoDB
* {@link AmazonDynamoDB} used to create the image table
* @param tableName
* name of the table to create
* @param tableProvisionedThroughput
* initial provisioned throughput for the table
* @param timeGSIProvisionedThroughput
* initial provisioned throughput for the time-based global secondary index
* @param voteGSIProvisionedThroughput
* initial provisioned throughput for the vote-based global secondary index
* @see <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html">Global Secondary
* Indexes</a> ======= initial provisioned throughput for the time-based global secondary index
* @see <a
* href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ProvisionedThroughputIntro.html">Provisioned
* Throughput in Amazon DynamoDB</a>
*/
public static void createImageTable(final AmazonDynamoDB dynamoDB, final String tableName,
final ProvisionedThroughput tableProvisionedThroughput,
final ProvisionedThroughput timeGSIProvisionedThroughput,
final ProvisionedThroughput voteGSIProvisionedThroughput) {
// Set up time GSI
final GlobalSecondaryIndex timeGSI = new GlobalSecondaryIndex();
timeGSI.setIndexName(IMAGE_TABLE_TIME_GSI_NAME);
timeGSI.setKeySchema(Arrays.asList(IMAGE_TABLE_TIME_GSI_HASH_KSE, IMAGE_TABLE_TIME_GSI_RANGE_KSE));
timeGSI.setProjection(IMAGE_TABLE_TIME_GSI_PROJECTION);
timeGSI.setProvisionedThroughput(timeGSIProvisionedThroughput);
// Set up vote GSI
final GlobalSecondaryIndex voteGSI = new GlobalSecondaryIndex();
voteGSI.setIndexName(IMAGE_TABLE_VOTE_GSI_NAME);
voteGSI.setKeySchema(Arrays.asList(IMAGE_TABLE_VOTE_GSI_HASH_KSE, IMAGE_TABLE_VOTE_GSI_RANGE_KSE));
voteGSI.setProjection(IMAGE_TABLE_VOTE_GSI_PROJECTION);
voteGSI.setProvisionedThroughput(voteGSIProvisionedThroughput);
// Create table
final CreateTableRequest request = new CreateTableRequest();
request.setAttributeDefinitions(IMAGE_TABLE_ATTRIBUTE_DEFINITIONS);
request.setKeySchema(IMAGE_TABLE_KEY_SCHEMA);
request.setGlobalSecondaryIndexes(Arrays.asList(timeGSI, voteGSI));
request.setProvisionedThroughput(tableProvisionedThroughput);
request.setTableName(tableName);
LOGGER.info("Creating image table: " + request);
final TableDescription result = DynamoDBManager.createTable(dynamoDB, request);
LOGGER.info("Image table successfully created: " + result);
}
示例6: testCreateImageTable
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入方法依賴的package包/類
@Test
public void testCreateImageTable() {
final AmazonDynamoDB dynamoDB = PowerMock.createMock(AmazonDynamoDB.class);
PowerMock.mockStatic(DynamoDBManager.class);
final CreateTableRequest request = new CreateTableRequest();
request.setAttributeDefinitions(MarsDynamoDBManager.IMAGE_TABLE_ATTRIBUTE_DEFINITIONS);
request.setKeySchema(MarsDynamoDBManager.IMAGE_TABLE_KEY_SCHEMA);
final GlobalSecondaryIndex timeGSI = new GlobalSecondaryIndex();
timeGSI.setIndexName(MarsDynamoDBManager.IMAGE_TABLE_TIME_GSI_NAME);
timeGSI.setKeySchema(Arrays.asList(MarsDynamoDBManager.IMAGE_TABLE_TIME_GSI_HASH_KSE,
MarsDynamoDBManager.IMAGE_TABLE_TIME_GSI_RANGE_KSE));
timeGSI.setProjection(MarsDynamoDBManager.IMAGE_TABLE_TIME_GSI_PROJECTION);
timeGSI.setProvisionedThroughput(PROVISIONED_THROUGHPUT);
final GlobalSecondaryIndex voteGSI = new GlobalSecondaryIndex();
voteGSI.setIndexName(MarsDynamoDBManager.IMAGE_TABLE_VOTE_GSI_NAME);
voteGSI.setKeySchema(Arrays.asList(MarsDynamoDBManager.IMAGE_TABLE_VOTE_GSI_HASH_KSE,
MarsDynamoDBManager.IMAGE_TABLE_VOTE_GSI_RANGE_KSE));
voteGSI.setProjection(MarsDynamoDBManager.IMAGE_TABLE_VOTE_GSI_PROJECTION);
voteGSI.setProvisionedThroughput(PROVISIONED_THROUGHPUT);
request.setGlobalSecondaryIndexes(Arrays.asList(timeGSI, voteGSI));
request.setProvisionedThroughput(PROVISIONED_THROUGHPUT);
request.setTableName(TABLE_NAME);
DynamoDBManager.createTable(dynamoDB, request);
PowerMock.expectLastCall().andReturn(null);
PowerMock.replayAll();
MarsDynamoDBManager.createImageTable(dynamoDB, TABLE_NAME, PROVISIONED_THROUGHPUT, PROVISIONED_THROUGHPUT,
PROVISIONED_THROUGHPUT);
PowerMock.verifyAll();
}
示例7: createTable
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入方法依賴的package包/類
private void createTable() {
try {
final ArrayList<KeySchemaElement> keySchema = new ArrayList<>();
keySchema.add(new KeySchemaElement()
.withAttributeName("id")
.withKeyType(KeyType.HASH));
final ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<>();
attributeDefinitions.add(new AttributeDefinition()
.withAttributeName("id")
.withAttributeType("S"));
final ArrayList<GlobalSecondaryIndex> globalSecondaryIndices = new ArrayList<>();
if (secondaryIndexNames != null) {
for (final String indexName : secondaryIndexNames) {
attributeDefinitions.add(new AttributeDefinition()
.withAttributeName(indexName)
.withAttributeType("S"));
globalSecondaryIndices.add(new GlobalSecondaryIndex()
.withIndexName(indexName + "-index")
.withKeySchema(new KeySchemaElement().withAttributeName(indexName).withKeyType(KeyType.HASH))
.withProjection(new Projection().withProjectionType(ProjectionType.ALL))
.withProvisionedThroughput(new ProvisionedThroughput()
.withReadCapacityUnits(readCapacityUnits)
.withWriteCapacityUnits(writeCapacityUnits)));
}
}
final CreateTableRequest request = new CreateTableRequest()
.withTableName(tableName)
.withKeySchema(keySchema)
.withProvisionedThroughput(new ProvisionedThroughput()
.withReadCapacityUnits(readCapacityUnits)
.withWriteCapacityUnits(writeCapacityUnits));
if (!globalSecondaryIndices.isEmpty()) {
request.withGlobalSecondaryIndexes(globalSecondaryIndices);
}
request.setAttributeDefinitions(attributeDefinitions);
logger.debug("Issuing CreateTable request for " + tableName);
final Table table = DynamoCommons.getInstance().getDb().createTable(request);
logger.debug("Waiting for table to be created...");
table.waitForActive();
} catch (final Exception e) {
logger.error("CreateTable request failed: " + e.getMessage());
}
}
示例8: createTable
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入方法依賴的package包/類
private static void createTable(
String tableName, long readCapacityUnits, long writeCapacityUnits,
String hashKeyName, String hashKeyType,
String rangeKeyName, String rangeKeyType) {
try {
ArrayList<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>();
keySchema.add(new KeySchemaElement()
.withAttributeName(hashKeyName)
.withKeyType(KeyType.HASH));
ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
attributeDefinitions.add(new AttributeDefinition()
.withAttributeName(hashKeyName)
.withAttributeType(hashKeyType));
if (rangeKeyName != null) {
keySchema.add(new KeySchemaElement()
.withAttributeName(rangeKeyName)
.withKeyType(KeyType.RANGE));
attributeDefinitions.add(new AttributeDefinition()
.withAttributeName(rangeKeyName)
.withAttributeType(rangeKeyType));
}
CreateTableRequest request = new CreateTableRequest()
.withTableName(tableName)
.withKeySchema(keySchema)
.withProvisionedThroughput( new ProvisionedThroughput()
.withReadCapacityUnits(readCapacityUnits)
.withWriteCapacityUnits(writeCapacityUnits));
// If this is the Reply table, define a local secondary index
if (replyTableName.equals(tableName)) {
attributeDefinitions.add(new AttributeDefinition()
.withAttributeName("PostedBy")
.withAttributeType("S"));
ArrayList<LocalSecondaryIndex> localSecondaryIndexes = new ArrayList<LocalSecondaryIndex>();
localSecondaryIndexes.add(new LocalSecondaryIndex()
.withIndexName("PostedBy-Index")
.withKeySchema(
new KeySchemaElement().withAttributeName(hashKeyName).withKeyType(KeyType.HASH),
new KeySchemaElement() .withAttributeName("PostedBy") .withKeyType(KeyType.RANGE))
.withProjection(new Projection() .withProjectionType(ProjectionType.KEYS_ONLY)));
request.setLocalSecondaryIndexes(localSecondaryIndexes);
}
request.setAttributeDefinitions(attributeDefinitions);
System.out.println("Issuing CreateTable request for " + tableName);
Table table = dynamoDB.createTable(request);
System.out.println("Waiting for " + tableName
+ " to be created...this may take a while...");
table.waitForActive();
} catch (Exception e) {
System.err.println("CreateTable request failed for " + tableName);
System.err.println(e.getMessage());
}
}
示例9: execute
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入方法依賴的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: createResourceTable
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; //導入方法依賴的package包/類
/**
* Creates the table that stores resources with an ETag.
*
* @param dynamoDB
* {@link AmazonDynamoDB} used to create DynamoDB table
* @param tableName
* name of the table to create
* @param provisionedThroughput
* initial provisioned throughput for the table
* @see <a
* href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ProvisionedThroughputIntro.html">Provisioned
* Througput in Amazon DynamoDB</a>
*/
public static void createResourceTable(final AmazonDynamoDB dynamoDB, final String tableName,
final ProvisionedThroughput provisionedThroughput) {
final CreateTableRequest request = new CreateTableRequest();
request.setAttributeDefinitions(RESOURCE_TABLE_ATTRIBUTE_DEFINITIONS);
request.setKeySchema(RESOURCE_TABLE_KEY_SCHEMA);
request.setProvisionedThroughput(provisionedThroughput);
request.setTableName(tableName);
LOGGER.info("Creating resource table: " + request);
DynamoDBManager.createTable(dynamoDB, request);
LOGGER.info("Resource table successfully created");
}