List of usage examples for com.amazonaws.services.dynamodbv2 AmazonDynamoDB createTable
CreateTableResult createTable(CreateTableRequest createTableRequest);
The CreateTable
operation adds a new table to your account.
From source file:com.github.fge.jsonpatch.JsonPatchToXSpecRemove.java
License:LGPL
@BeforeTest public void setUp() throws Exception { AmazonDynamoDB amazonDynamoDB = DynamoDBEmbedded.create().amazonDynamoDB(); try {/* w w w . ja va2 s . co m*/ amazonDynamoDB.deleteTable(TABLE_NAME); } catch (ResourceNotFoundException e) { //do nothing because the first run will not have the table. } amazonDynamoDB.createTable(new CreateTableRequest().withTableName(TABLE_NAME) .withProvisionedThroughput(new ProvisionedThroughput(1L, 1L)) .withAttributeDefinitions(new AttributeDefinition().withAttributeName(KEY_ATTRIBUTE_NAME) .withAttributeType(ScalarAttributeType.S)) .withKeySchema( new KeySchemaElement().withAttributeName(KEY_ATTRIBUTE_NAME).withKeyType(KeyType.HASH))); table = new Table(amazonDynamoDB, TABLE_NAME); }
From source file:com.netflix.config.sources.DynamoDbIntegrationTestHelper.java
License:Apache License
static void createTable(AmazonDynamoDB dbClient, String tableName) throws InterruptedException { //TODO check to make sure the table isn't being created or deleted. KeySchemaElement hashKey = new KeySchemaElement() .withAttributeName(DynamoDbConfigurationSource.defaultKeyAttribute).withKeyType(KeyType.HASH); ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput().withReadCapacityUnits(1L) .withWriteCapacityUnits(1L); dbClient.createTable(new CreateTableRequest().withTableName(tableName).withKeySchema(hashKey) .withProvisionedThroughput(provisionedThroughput)); while (!dbClient.describeTable(new DescribeTableRequest().withTableName(tableName)).getTable() .getTableStatus().equalsIgnoreCase("active")) { Thread.sleep(10000);/*from w ww.j av a2 s. c o m*/ } }
From source file:io.venable.amazonaws.dynamo.table.builder.TableBuilder.java
License:Apache License
/** * Creates the table for the given {@link AmazonDynamoDB}. * * @param amazonDynamoDB the {@link AmazonDynamoDB} instance * @return the {@link CreateTableResult} from the create request * @since 0.1//from w w w.j a v a 2 s . c o m */ public CreateTableResult create(AmazonDynamoDB amazonDynamoDB) { CreateTableRequest createTableRequest = buildCreateTableRequest(); return amazonDynamoDB.createTable(createTableRequest); }
From source file:kinesisadaptersample.StreamsAdapterDemoHelper.java
License:Open Source License
/** * @return StreamArn//from ww w . j a va2s . c om */ public static String createTable(AmazonDynamoDB client, String tableName) { java.util.List<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>(); attributeDefinitions.add(new AttributeDefinition().withAttributeName("Id").withAttributeType("N")); java.util.List<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>(); keySchema.add(new KeySchemaElement().withAttributeName("Id").withKeyType(KeyType.HASH)); // Partition // key ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput().withReadCapacityUnits(2L) .withWriteCapacityUnits(2L); StreamSpecification streamSpecification = new StreamSpecification(); streamSpecification.setStreamEnabled(true); streamSpecification.setStreamViewType(StreamViewType.NEW_IMAGE); CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName) .withAttributeDefinitions(attributeDefinitions).withKeySchema(keySchema) .withProvisionedThroughput(provisionedThroughput).withStreamSpecification(streamSpecification); try { System.out.println("Creating table " + tableName); CreateTableResult result = client.createTable(createTableRequest); return result.getTableDescription().getLatestStreamArn(); } catch (ResourceInUseException e) { System.out.println("Table already exists."); return describeTable(client, tableName).getTable().getLatestStreamArn(); } }
From source file:org.apache.gora.dynamodb.store.DynamoDBUtils.java
License:Apache License
/** * Executes a create table request using the DynamoDB client and waits the * default time until it's been created. * //from ww w.j av a2 s . c o m * @param awsClient * @param keySchema * @param tableName * @param proThrou */ public static void executeCreateTableRequest(AmazonDynamoDB awsClient, String tableName, ArrayList<KeySchemaElement> keySchema, Map<String, String> attrs, ProvisionedThroughput proThrou) { CreateTableRequest createTableRequest = buildCreateTableRequest(tableName, keySchema, proThrou, attrs); // use the client to perform the request try { awsClient.createTable(createTableRequest).getTableDescription(); // wait for table to become active waitForTableToBecomeAvailable(awsClient, tableName); } catch (ResourceInUseException ex) { LOG.warn("Table '{}' already exists.", tableName); } finally { LOG.info("Table '{}' is available.", tableName); } }
From source file:org.apache.metamodel.dynamodb.DynamoDbTableCreationBuilder.java
License:Apache License
@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(//from w w w .jav a 2s . com 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; }
From source file:org.iternine.jeppetto.dao.dynamodb.extra.TableBuilder.java
License:Apache License
public void build(AmazonDynamoDB amazonDynamoDB) { CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName) .withKeySchema(keySchema).withAttributeDefinitions(attributeDefinitions) .withProvisionedThroughput(new ProvisionedThroughput(64L, 64L)) .withLocalSecondaryIndexes(localSecondaryIndexes) .withGlobalSecondaryIndexes(globalSecondaryIndexes); amazonDynamoDB.createTable(createTableRequest); }