Java 类com.amazonaws.services.dynamodbv2.model.CreateTableResult 实例源码

项目:strongbox    文件:GenericDynamoDBTest.java   
@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);
}
项目:aws-java-sdk-stubs    文件:AmazonDynamoDBStubTest.java   
private CreateTableResult createTable() throws Exception {
  List<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
  AttributeDefinition attributeDefinition = new AttributeDefinition()
    .withAttributeName(TEST_ATTRIBUTE)
    .withAttributeType(ScalarAttributeType.S);
  attributeDefinitions.add(attributeDefinition);

  String tableName = TEST_TABLE_NAME;

  List<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>();
  KeySchemaElement keySchemaElement = new KeySchemaElement()
    .withAttributeName(TEST_ATTRIBUTE)
    .withKeyType(KeyType.HASH);

  ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
    .withReadCapacityUnits(UNITS)
    .withWriteCapacityUnits(UNITS);

  CreateTableResult result = dynamoDb.createTable(attributeDefinitions, tableName, keySchema, provisionedThroughput);

  return result;
}
项目:amazon-kinesis-aggregators    文件:DynamoUtils.java   
/**
 * 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;
        }
    }
}
项目:micro-genie    文件:DynamoAdmin.java   
/***
 * Scan classes to determine which tables and indexes need to be created
 * 
 * TODO - DynamoDB has a limit of how many tables can be created at once, I think 10 as of now.
 * This method does not batch but really needs to, so it only tries to create up 10 tables at the same time
 *  
 * @param packagePrefix
 * @param blockUntilActive - If true this method will not return until the table is active or maxBlockTimeSeconds has expired
 * @param  maxBlockTimeSeconds - The maximum amount of time to block for each table until the table becomes active
 */
public void scan(final String packagePrefix, boolean blockUntilActive, long maxBlockTimeSeconds){

    final List<String> createdTables = Lists.newArrayList();
    final Reflections reflections = new Reflections(packagePrefix);
    final Set<Class<?>> tableClasses = reflections.getTypesAnnotatedWith(DynamoDBTable.class);
    for(Class<?> clazz : tableClasses){
        if(!tableExists(clazz)){
            final CreateTableResult result = this.createTable(clazz);
            if(result!=null && result.getTableDescription()!=null){
                final TableDescription description = result.getTableDescription();
                /** If the table is not active add it to the list of tables to wait on **/
                if(!ACTIVE_TABLE_STATUS.equalsIgnoreCase(description.getTableStatus())){
                    createdTables.add(description.getTableName());
                }
            }
        }
    }

    /** If specified, wait for all the tables to become if active **/
    if(blockUntilActive){
        for(final String table : createdTables){
            this.waitForTableToBecomeActive(table, maxBlockTimeSeconds, DEFAULT_PAUSE_TIME_SECONDS);
        }           
    }
}
项目:micro-genie    文件:DynamoAdmin.java   
/***
 * Create the table and the associated indexes if it does not already exist
 * @param reflections
 * @param clazz
 */
private CreateTableResult createTable(Class<?> clazz) {

    final String tableName = this.getClassAnnotationValue(clazz, DynamoDBTable.class, String.class, "tableName");

    final Method hashKeyMember = this.getMethodForAnnotation(clazz, DynamoDBHashKey.class);
    final DynamoDBHashKey hashKeyAnno = hashKeyMember.getAnnotation(DynamoDBHashKey.class);
    final String hashKeyName = this.getAnnotationValue(hashKeyAnno, "attributeName", String.class);
    String rangeKeyName = null;


    final Method rangeKeyMember = this.getMethodForAnnotation(clazz, DynamoDBRangeKey.class);
    if(rangeKeyMember!=null){
        DynamoDBRangeKey rangeKeyAnno = rangeKeyMember.getAnnotation(DynamoDBRangeKey.class);   
        rangeKeyName = this.getAnnotationValue(rangeKeyAnno, "attributeName", String.class);
    }
    final Set<Method> hashKeyIndexFields = this.getMethodsAnnotatedWith(DynamoDBIndexHashKey.class, clazz);
    final Set<Method> rangeKeyIndexFields = this.getMethodsAnnotatedWith(DynamoDBIndexRangeKey.class, clazz);

    final Map<String, GlobalIndex> globalIndexes = this.createGlobalIndexes(hashKeyIndexFields, rangeKeyIndexFields, clazz);
    final Map<String, RangeKeyIndexField> localIndexes = this.createLocalIndexMap(rangeKeyIndexFields);

    final CreateTableRequest tableRequest = this.createCreateTableRequest(tableName, hashKeyName, rangeKeyName, globalIndexes, localIndexes);
    final CreateTableResult result = this.client.createTable(tableRequest);
    return result;
}
项目:aws-dynamodb-examples    文件:DynamoDBEmbeddedTest.java   
@Test
public void createTableTest() {
    AmazonDynamoDB ddb = DynamoDBEmbedded.create().amazonDynamoDB();
    try {
        String tableName = "Movies";
        String hashKeyName = "film_id";
        CreateTableResult res = createTable(ddb, tableName, hashKeyName);

        TableDescription tableDesc = res.getTableDescription();
        assertEquals(tableName, tableDesc.getTableName());
        assertEquals("[{AttributeName: " + hashKeyName + ",KeyType: HASH}]", tableDesc.getKeySchema().toString());
        assertEquals("[{AttributeName: " + hashKeyName + ",AttributeType: S}]",
            tableDesc.getAttributeDefinitions().toString());
        assertEquals(Long.valueOf(1000L), tableDesc.getProvisionedThroughput().getReadCapacityUnits());
        assertEquals(Long.valueOf(1000L), tableDesc.getProvisionedThroughput().getWriteCapacityUnits());
        assertEquals("ACTIVE", tableDesc.getTableStatus());
        assertEquals("arn:aws:dynamodb:ddblocal:000000000000:table/Movies", tableDesc.getTableArn());

        ListTablesResult tables = ddb.listTables();
        assertEquals(1, tables.getTableNames().size());
    } finally {
        ddb.shutdown();
    }
}
项目:aws-dynamodb-examples    文件:DynamoDBEmbeddedTest.java   
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);
}
项目:lambdora    文件:IntegrationTestBase.java   
/**
 * setup
 */
@Before
public void setup() {
    // Create an in-memory and in-process instance of DynamoDB Local that skips HTTP
    dynamodbClient = DynamoDBEmbedded.create().amazonDynamoDB();

    // Create and verify table
    final CreateTableResult createTableResult = createTable();
    assertEquals(TABLE_NAME, createTableResult.getTableDescription().getTableName());
}
项目:lambdora    文件:IntegrationTestBase.java   
private CreateTableResult createTable() {
    final List<AttributeDefinition> attributeDefinitions = new ArrayList<>();
    attributeDefinitions.add(new AttributeDefinition(RESOURCE_NAME_ATT, ScalarAttributeType.S));
    attributeDefinitions.add(new AttributeDefinition(RDF_TRIPLE_ATT, ScalarAttributeType.S));
    attributeDefinitions.add(new AttributeDefinition(RDF_PREDICATE_ATT, ScalarAttributeType.S));
    attributeDefinitions.add(new AttributeDefinition(RDF_OBJECT_ATT, ScalarAttributeType.S));

    final List<KeySchemaElement> keySchema = new ArrayList<>();
    keySchema.add(new KeySchemaElement(RESOURCE_NAME_ATT, KeyType.HASH));
    keySchema.add(new KeySchemaElement(RDF_TRIPLE_ATT, KeyType.RANGE));

    final ProvisionedThroughput provisionedthroughput =
        new ProvisionedThroughput(10L, 10L);

    final LocalSecondaryIndex predicateIndex = new LocalSecondaryIndex()
        .withIndexName(PREDICATE_INDEX_NAME)
        .withKeySchema(new KeySchemaElement(RESOURCE_NAME_ATT, KeyType.HASH))
        .withKeySchema(new KeySchemaElement(RDF_PREDICATE_ATT, KeyType.RANGE))
        .withProjection(new Projection().withNonKeyAttributes(RDF_SUBJECT_ATT, RDF_OBJECT_ATT)
                                        .withProjectionType(ProjectionType.INCLUDE));

    final GlobalSecondaryIndex objectIndex = new GlobalSecondaryIndex()
        .withIndexName(OBJECT_INDEX_NAME)
        .withKeySchema(new KeySchemaElement(RDF_OBJECT_ATT, KeyType.HASH))
        .withKeySchema(new KeySchemaElement(RDF_PREDICATE_ATT, KeyType.RANGE))
        .withProjection(new Projection().withNonKeyAttributes(RDF_SUBJECT_ATT)
                                        .withProjectionType(ProjectionType.INCLUDE))
        .withProvisionedThroughput(new ProvisionedThroughput(10L, 10L));

    final CreateTableRequest request =
        new CreateTableRequest()
            .withTableName(TABLE_NAME)
            .withAttributeDefinitions(attributeDefinitions)
            .withKeySchema(keySchema)
            .withProvisionedThroughput(provisionedthroughput)
            .withLocalSecondaryIndexes(predicateIndex)
            .withGlobalSecondaryIndexes(objectIndex);

    return dynamodbClient.createTable(request);
}
项目:strongbox    文件:GenericDynamoDB.java   
@Override
public String create() {
    readWriteLock.writeLock().lock();

    try {
        CreateTableResult result = client.createTable(constructCreateTableRequest());
        waitForTableToBecomeActive();
        return result.getTableDescription().getTableArn();
    } catch (ResourceInUseException e) {
        throw new AlreadyExistsException(String.format("There is already a DynamoDB table called '%s'", tableName), e);
    } finally {
        readWriteLock.writeLock().unlock();
    }
}
项目:plano    文件:PlanoApplicationDynamoDBTests.java   
private CreateTableResult createPlanoRequestsTable() {
    CreateTableRequest request = mapper.generateCreateTableRequest(DynamoDBPlanoRequest.class)
            .withProvisionedThroughput(new ProvisionedThroughput()
                    .withReadCapacityUnits(5L)
                    .withWriteCapacityUnits(6L));

    CreateTableResult createTableResult = dynamoDB.createTable(request);

    return createTableResult;
}
项目:plano    文件:DynamoDBRepositoryTests.java   
private CreateTableResult createPlanoRequestsTable() {
    CreateTableRequest request = sDynamoDBMapper.generateCreateTableRequest(DynamoDBPlanoRequest.class)
            .withProvisionedThroughput(new ProvisionedThroughput()
                    .withReadCapacityUnits(5L)
                    .withWriteCapacityUnits(6L));

    CreateTableResult createTableResult = sDynamoDB.createTable(request);

    return createTableResult;
}
项目:Tank    文件:AmazonDynamoDatabaseDocApi.java   
/**
 * 
 * @{inheritDoc
 */
@Override
public void createTable(String tableName) {
    try {
        if (!hasTable(tableName)) {
            logger.info("Creating table: " + tableName);
            HierarchicalConfiguration resultsProviderConfig = config.getVmManagerConfig()
                    .getResultsProviderConfig();
            long readCapacity = getCapacity(resultsProviderConfig, "read-capacity", 10L);
            long writeCapacity = getCapacity(resultsProviderConfig, "write-capacity", 50L);
            ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
            attributeDefinitions.add(new AttributeDefinition().withAttributeName(
                    DatabaseKeys.JOB_ID_KEY.getShortKey()).withAttributeType(ScalarAttributeType.S));
            attributeDefinitions.add(new AttributeDefinition().withAttributeName(
                    DatabaseKeys.REQUEST_NAME_KEY.getShortKey()).withAttributeType(ScalarAttributeType.S));
            ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput().withReadCapacityUnits(
                    readCapacity).withWriteCapacityUnits(writeCapacity);
            KeySchemaElement hashKeyElement = new KeySchemaElement().withAttributeName(
                    DatabaseKeys.JOB_ID_KEY.getShortKey()).withKeyType(KeyType.HASH);
            KeySchemaElement rangeKeyElement = new KeySchemaElement().withAttributeName(
                    DatabaseKeys.REQUEST_NAME_KEY.getShortKey()).withKeyType(KeyType.RANGE);
            CreateTableRequest request = new CreateTableRequest()
                    .withTableName(tableName)
                    .withKeySchema(hashKeyElement, rangeKeyElement)
                    .withAttributeDefinitions(attributeDefinitions)
                    .withProvisionedThroughput(provisionedThroughput);

            CreateTableResult result = dynamoDb.createTable(request);
            waitForStatus(tableName, TableStatus.ACTIVE);
            logger.info("Created table: " + result.getTableDescription().getTableName());
        }
    } catch (Exception t) {
        logger.error(t, t);
        throw new RuntimeException(t);
    }
}
项目:dynamodb-janusgraph-storage-backend    文件:DynamoDbDelegate.java   
private CreateTableResult createTable(final CreateTableRequest request) throws BackendException {
    controlPlaneRateLimiter.acquire();
    final Timer.Context apiTimerContext = getTimerContext(CREATE_TABLE, request.getTableName());
    CreateTableResult result;
    try {
        result = client.createTable(request);
    } catch (final Exception e) {
        throw processDynamoDbApiException(e, CREATE_TABLE, request.getTableName());
    } finally {
        apiTimerContext.stop();
    }
    return result;
}
项目:dynamodb-streams-kafka    文件:StreamAdapterDemoHelper.java   
public static String createTable(AmazonDynamoDBClient 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));

    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().getLatestStreamId();
    } catch(ResourceInUseException e) {
        System.out.println("Table already exists.");
        return describeTable(client, tableName).getTable().getLatestStreamId();
    }
}
项目:aws-java-sdk-stubs    文件:AmazonDynamoDBStubTest.java   
@Test
public void test_createTable_WithParameters() throws Exception {
  CreateTableResult result = createTable();
  TableDescription tableDescription = result.getTableDescription();
  String createdTableName = tableDescription.getTableName();

  assertThat(createdTableName, equalTo(TEST_TABLE_NAME));
}
项目:milton-aws    文件:DynamoDBServiceImpl.java   
@Override
  public boolean createTable(String tableName) {
      List<AttributeDefinition> attributeDefinitions= new ArrayList<AttributeDefinition>();
      attributeDefinitions.add(new AttributeDefinition().withAttributeName(AttributeKey.UUID)
            .withAttributeType(ScalarAttributeType.S));

      List<KeySchemaElement> keySchemaElement = new ArrayList<KeySchemaElement>();
      keySchemaElement.add(new KeySchemaElement().withAttributeName(AttributeKey.UUID)
            .withKeyType(KeyType.HASH));

      // Provide the initial provisioned throughput values as Java long data types
      ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
          .withReadCapacityUnits(10L)
          .withWriteCapacityUnits(10L);

      CreateTableRequest createTableRequest = new CreateTableRequest()
          .withTableName(tableName)
          .withAttributeDefinitions(attributeDefinitions)
          .withKeySchema(keySchemaElement)
          .withProvisionedThroughput(provisionedThroughput);

      try {
          CreateTableResult createdTableDescription = dynamoDBClient.createTable(createTableRequest);
          LOG.info("Creating table description: " + createdTableDescription);

          // Wait for it to become active
          waitForTableAvailable(tableName);
          if (describeTable(tableName) != null) {
            return true;
          }
      } catch (ResourceInUseException rie) {
          LOG.warn("Table " + tableName + " already exists");
} catch (AmazonServiceException ase) {
    LOG.error(ase.getMessage(), ase);
} catch (AmazonClientException ace) {
    LOG.error(ace.getMessage(), ace);
}
      return false;
  }
项目:aws-dynamodb-encryption-java    文件:MetaStore.java   
/**
 * 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);

}
项目:spring-security-oauth2-dynamodb    文件:DynamoDBInitializationHelper.java   
public static void createHashTable(AmazonDynamoDBClient client, String tableName, String hashColumnName) {

        CreateTableRequest accessTableRequest = new CreateTableRequest() //
                .withTableName(tableName) //
                .withKeySchema(new KeySchemaElement(hashColumnName, KeyType.HASH)) //
                .withAttributeDefinitions(new AttributeDefinition(hashColumnName, ScalarAttributeType.S) //
                ) //
                .withProvisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) //
        ;

        CreateTableResult accessTableresponse = client.createTable(accessTableRequest);
    }
项目:aws-dynamodb-mars-json-demo    文件:DynamoDBManagerTest.java   
@Test
public void testCreateTableTableDoesNotExist() {
    final Collection<AttributeDefinition> ads = Arrays.asList(new AttributeDefinition("Hash", ScalarAttributeType.S));
    final Collection<KeySchemaElement> kses = Arrays.asList(new KeySchemaElement("Hash", KeyType.HASH));
    final TableDescription description = new TableDescription().withAttributeDefinitions(ads).withKeySchema(kses)
        .withTableName(tableName);
    final CreateTableResult cTR = new CreateTableResult().withTableDescription(description);
    EasyMock.expect(dynamoDB.describeTable(tableName)).andThrow(new ResourceNotFoundException(null));
    final CreateTableRequest request = new CreateTableRequest().withAttributeDefinitions(ads).withKeySchema(kses)
        .withTableName(tableName);
    EasyMock.expect(dynamoDB.createTable(request)).andReturn(cTR);
    PowerMock.replayAll();
    assertEquals(description, DynamoDBManager.createTable(dynamoDB, request));
    PowerMock.verifyAll();
}
项目:aws-dynamodb-examples    文件:StreamsAdapterDemoHelper.java   
/**
 * @return StreamArn
 */
public static String createTable(AmazonDynamoDBClient 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));

    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();
    }
}
项目:aws-dynamodb-examples    文件:DynamoDBDynamicFaultInjection.java   
private static void createTable()
{
    List<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName("name").withAttributeType("S"));

    List<KeySchemaElement> ks = new ArrayList<KeySchemaElement>();
    ks.add(new KeySchemaElement().withAttributeName("name").withKeyType(KeyType.HASH));

    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput().withReadCapacityUnits(10L)
        .withWriteCapacityUnits(10L);

    CreateTableRequest request = new CreateTableRequest().withTableName(TABLENAME)
        .withAttributeDefinitions(attributeDefinitions).withKeySchema(ks)
        .withProvisionedThroughput(provisionedThroughput);

    try
    {
        CreateTableResult createdTableDescription = dynamoDBClient.createTable(request);
        logger.info("Created Table: " + createdTableDescription);
        // Wait for it to become active
        waitForTableToBecomeAvailable(TABLENAME);
    }
    catch (ResourceInUseException e)
    {
        logger.warn("Table already existed", e);
    }
}
项目:plano    文件:PlanoApplicationDynamoDBTests.java   
@Before
public void before() {
    CreateTableResult result = createPlanoRequestsTable();
    Assert.assertEquals(TABLE_NAME, result.getTableDescription().getTableName());
}
项目:plano    文件:DynamoDBRepositoryTests.java   
@Before
public void before() {
    CreateTableResult result = createPlanoRequestsTable();
    Assert.assertEquals(TABLE_NAME, result.getTableDescription().getTableName());
}
项目:aws-doc-sdk-examples    文件:CreateTable.java   
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!");
}
项目:aws-doc-sdk-examples    文件:CreateTableCompositeKey.java   
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!");
}
项目:Camel    文件:AmazonDDBClientMock.java   
@Override
public CreateTableResult createTable(CreateTableRequest createTableRequest) {
    this.createTableRequest = createTableRequest;
    return new CreateTableResult().withTableDescription(
            new TableDescription().withTableStatus(TableStatus.CREATING));
}
项目:spring-security-oauth2-dynamodb    文件:DynamoDBInitializationHelper.java   
public static void createTokenTables(AmazonDynamoDBClient client, DynamoDBTokenSchema schema) {
    GlobalSecondaryIndex gsiAuthenticationIdToken = new GlobalSecondaryIndex() //
            .withIndexName(schema.getAccessIndexAuthenticationId()) //
            .withKeySchema(new KeySchemaElement(schema.getAccessColumnAuthenticationId(), KeyType.HASH)) //
            .withProvisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) //
            .withProjection(new Projection().withProjectionType(ProjectionType.KEYS_ONLY));

    GlobalSecondaryIndex gsiRefreshToken = new GlobalSecondaryIndex() //
            .withIndexName(schema.getAccessIndexRefreshToken()) //
            .withKeySchema(new KeySchemaElement(schema.getAccessColumnRefreshToken(), KeyType.HASH)) //
            .withProvisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) //
            .withProjection(new Projection().withProjectionType(ProjectionType.KEYS_ONLY));

    GlobalSecondaryIndex gsiClientIdAndUserName = new GlobalSecondaryIndex() //
            .withIndexName(schema.getAccessIndexClientIdAndUserName()) //
            .withKeySchema( //
                    new KeySchemaElement(schema.getAccessColumnClientId(), KeyType.HASH), //
                    new KeySchemaElement(schema.getAccessColumnUserName(), KeyType.RANGE) //
            ) //
            .withProvisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) //
            .withProjection(new Projection().withProjectionType(ProjectionType.KEYS_ONLY));

    CreateTableRequest accessTableRequest = new CreateTableRequest() //
            .withTableName(schema.getAccessTableName()) //
            .withKeySchema(new KeySchemaElement(schema.getAccessColumnTokenId(), KeyType.HASH)) //
            .withGlobalSecondaryIndexes(gsiAuthenticationIdToken, gsiRefreshToken, gsiClientIdAndUserName) //
            .withAttributeDefinitions(new AttributeDefinition(schema.getAccessColumnTokenId(), ScalarAttributeType.S), //
                    new AttributeDefinition(schema.getAccessColumnAuthenticationId(), ScalarAttributeType.S), //
                    new AttributeDefinition(schema.getAccessColumnRefreshToken(), ScalarAttributeType.S), //
                    new AttributeDefinition(schema.getAccessColumnClientId(), ScalarAttributeType.S), //
                    new AttributeDefinition(schema.getAccessColumnUserName(), ScalarAttributeType.S) //
            ) //
            .withProvisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) //
    ;

    CreateTableResult accessTableresponse = client.createTable(accessTableRequest);

    CreateTableRequest refreshTableRequest = new CreateTableRequest() //
            .withTableName(schema.getRefreshTableName()) //
            .withKeySchema(new KeySchemaElement(schema.getRefreshColumnTokenId(), KeyType.HASH)) //
            .withAttributeDefinitions(new AttributeDefinition(schema.getRefreshColumnTokenId(), ScalarAttributeType.S) //
            ) //
            .withProvisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) //
    ;

    CreateTableResult refreshTableresponse = client.createTable(refreshTableRequest);
}
项目:metamodel    文件:DynamoDbTableCreationBuilder.java   
@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;
}
项目:jcabi-dynamodb-maven-plugin    文件:InstancesTest.java   
/**
 * 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);
    }
}