Java 类com.amazonaws.services.dynamodbv2.util.Tables 实例源码

项目:Doradus    文件:DynamoDBService.java   
@Override
public void createStoreIfAbsent(String storeName, boolean bBinaryValues) {
    String tableName = storeToTableName(storeName);
    if (!Tables.doesTableExist(m_ddbClient, tableName)) {
        // Create a table with a primary hash key named '_key', which holds a string
        m_logger.info("Creating table: {}", tableName);
        CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName)
            .withKeySchema(new KeySchemaElement()
                .withAttributeName(ROW_KEY_ATTR_NAME)
                .withKeyType(KeyType.HASH))
            .withAttributeDefinitions(new AttributeDefinition()
                .withAttributeName(ROW_KEY_ATTR_NAME)
                .withAttributeType(ScalarAttributeType.S))
            .withProvisionedThroughput(new ProvisionedThroughput()
                .withReadCapacityUnits(READ_CAPACITY_UNITS)
                .withWriteCapacityUnits(WRITE_CAPACITY_UNITS));
        m_ddbClient.createTable(createTableRequest).getTableDescription();
        try {
            Tables.awaitTableToBecomeActive(m_ddbClient, tableName);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);  
        }
    }
}
项目:Doradus    文件:DynamoDBService2.java   
@Override
public void createNamespace() {
    String table = getTenant().getName();
    if(Tables.doesTableExist(m_client, table)) return;
    m_logger.info("Creating table: {}", table);
    CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(table)
        .withKeySchema(
            new KeySchemaElement()
             .withAttributeName("key")
             .withKeyType(KeyType.HASH),
            new KeySchemaElement()
             .withAttributeName("column")
             .withKeyType(KeyType.RANGE))
        .withAttributeDefinitions(
            new AttributeDefinition()
             .withAttributeName("key")
             .withAttributeType(ScalarAttributeType.S),
            new AttributeDefinition()
             .withAttributeName("column")
             .withAttributeType(ScalarAttributeType.S))
        .withProvisionedThroughput(new ProvisionedThroughput()
            .withReadCapacityUnits(m_readCapacityUnits)
            .withWriteCapacityUnits(m_writeCapacityUnits));
    m_client.createTable(createTableRequest);
    try {
        Tables.awaitTableToBecomeActive(m_client, table);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);  
    }
}
项目:aws-dynamodb-session-tomcat    文件:DynamoDBSessionManager.java   
private void initDynamoTable(AmazonDynamoDBClient dynamo) {
    boolean tableExists = Tables.doesTableExist(dynamo, this.tableName);

    if (!tableExists && !createIfNotExist) {
        throw new AmazonClientException("Session table '" + tableName + "' does not exist, "
                + "and automatic table creation has been disabled in context.xml");
    }

    if (!tableExists) {
        DynamoUtils.createSessionTable(dynamo, this.tableName, this.readCapacityUnits, this.writeCapacityUnits);
    }

    Tables.waitForTableToBecomeActive(dynamo, this.tableName);
}
项目:aws-dynamodb-session-tomcat    文件:SessionStorageIntegrationTestBase.java   
@BeforeClass
public static final void baseSetupFixture() throws Exception {
    setUpCredentials();
    dynamoClient = new AmazonDynamoDBClient(credentials);
    tableName = getUniqueTableName();
    DynamoUtils.createSessionTable(dynamoClient, tableName, 10L, 10L);
    Tables.waitForTableToBecomeActive(dynamoClient, tableName);
    dynamoMapper = DynamoUtils.createDynamoMapper(dynamoClient, tableName);
}
项目:amazon-cloudengine    文件:DynamoDBService.java   
private static void createTable() throws Exception {
        try {
            // Create table if it does not exist yet
            if (Tables.doesTableExist(dynamoDB, TABLE_NAME)) {
                //System.out.println("Table " + TABLE_NAME + " is already ACTIVE");
            } else {
                // Create a table with a primary hash key named 'taskID', which holds a string
                CreateTableRequest createTableRequest = new CreateTableRequest()
                    .withTableName(TABLE_NAME)
                    .withKeySchema(new KeySchemaElement().withAttributeName("taskID").withKeyType(KeyType.HASH))
                    .withAttributeDefinitions(new AttributeDefinition().withAttributeName("taskID").withAttributeType(ScalarAttributeType.S))
                    .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L));

                TableDescription tableDescription = dynamoDB.createTable(createTableRequest).getTableDescription();
                //System.out.println("Created Table: " + tableDescription);

                // Wait for it to become active
                //System.out.println("Waiting for " + TABLE_NAME + " to become ACTIVE...");
                Tables.waitForTableToBecomeActive(dynamoDB, TABLE_NAME);
            }

            // Describe our new table
//            DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(TABLE_NAME);
//            TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable();
//            System.out.println("Table Description: " + tableDescription);
        } catch (AmazonServiceException ase) {
            System.out.println("Caught an AmazonServiceException, which means your request made it "
                    + "to AWS, but was rejected with an error response for some reason.");
            System.out.println("Error Message:    " + ase.getMessage());
            System.out.println("HTTP Status Code: " + ase.getStatusCode());
            System.out.println("AWS Error Code:   " + ase.getErrorCode());
            System.out.println("Error Type:       " + ase.getErrorType());
            System.out.println("Request ID:       " + ase.getRequestId());
        } catch (AmazonClientException ace) {
            System.out.println("Caught an AmazonClientException, which means the client encountered "
                    + "a serious internal problem while trying to communicate with AWS, "
                    + "such as not being able to access the network.");
            System.out.println("Error Message: " + ace.getMessage());
        }

    }