當前位置: 首頁>>代碼示例>>Java>>正文


Java AmazonDynamoDBClient.createTable方法代碼示例

本文整理匯總了Java中com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.createTable方法的典型用法代碼示例。如果您正苦於以下問題:Java AmazonDynamoDBClient.createTable方法的具體用法?Java AmazonDynamoDBClient.createTable怎麽用?Java AmazonDynamoDBClient.createTable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient的用法示例。


在下文中一共展示了AmazonDynamoDBClient.createTable方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getDynamoClient

import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; //導入方法依賴的package包/類
private AmazonDynamoDBClient getDynamoClient(String tableName) {
    AWSCredentialsProvider credentials = new AWSCredentialsProviderChain(new StaticCredentialsProvider(new BasicAWSCredentials("test", "test")));
    AmazonDynamoDBClient amazonDynamoDBClient = new AmazonDynamoDBClient(credentials);
    amazonDynamoDBClient.setEndpoint("http://localhost:8000");

    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
            .withReadCapacityUnits(5L)
            .withWriteCapacityUnits(10L);
    CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName).withProvisionedThroughput(provisionedThroughput);
    ArrayList<AttributeDefinition> attributeDefinitions= new ArrayList<AttributeDefinition>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName("id").withAttributeType("S"));
    createTableRequest.setAttributeDefinitions(attributeDefinitions);

    ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
    tableKeySchema.add(new KeySchemaElement().withAttributeName("id").withKeyType(KeyType.HASH));
    createTableRequest.setKeySchema(tableKeySchema);
    amazonDynamoDBClient.createTable(createTableRequest);
    return amazonDynamoDBClient;

}
 
開發者ID:kzwang,項目名稱:elasticsearch-river-dynamodb,代碼行數:21,代碼來源:DynamoDbRiverTests.java

示例2: createSessionTable

import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; //導入方法依賴的package包/類
public static void createSessionTable(AmazonDynamoDBClient dynamo,
                                      String tableName,
                                      long readCapacityUnits,
                                      long writeCapacityUnits) {
    CreateTableRequest request = new CreateTableRequest().withTableName(tableName);

    request.withKeySchema(new KeySchemaElement().withAttributeName(DynamoSessionItem.SESSION_ID_ATTRIBUTE_NAME)
            .withKeyType(KeyType.HASH));

    request.withAttributeDefinitions(
            new AttributeDefinition().withAttributeName(DynamoSessionItem.SESSION_ID_ATTRIBUTE_NAME)
                    .withAttributeType(ScalarAttributeType.S));

    request.setProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(readCapacityUnits)
            .withWriteCapacityUnits(writeCapacityUnits));

    dynamo.createTable(request);
}
 
開發者ID:amazon-archives,項目名稱:aws-dynamodb-session-tomcat,代碼行數:19,代碼來源:DynamoUtils.java

示例3: createTable

import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; //導入方法依賴的package包/類
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();
    }
}
 
開發者ID:gnethercutt,項目名稱:dynamodb-streams-kafka,代碼行數:30,代碼來源:StreamAdapterDemoHelper.java

示例4: createHashTable

import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; //導入方法依賴的package包/類
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);
    }
 
開發者ID:Vivastream,項目名稱:spring-security-oauth2-dynamodb,代碼行數:13,代碼來源:DynamoDBInitializationHelper.java

示例5: createTable

import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; //導入方法依賴的package包/類
/**
 * @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();
    }
}
 
開發者ID:awslabs,項目名稱:aws-dynamodb-examples,代碼行數:33,代碼來源:StreamsAdapterDemoHelper.java

示例6: CreateDonationDataTable

import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; //導入方法依賴的package包/類
protected void CreateDonationDataTable (AmazonDynamoDBClient client) {

        ArrayList<AttributeDefinition> attributeDefinitions= new ArrayList<AttributeDefinition>();
        attributeDefinitions.add(new AttributeDefinition().withAttributeName("DonorId").withAttributeType("N"));
        attributeDefinitions.add(new AttributeDefinition().withAttributeName("Category").withAttributeType("S"));

        ArrayList<KeySchemaElement> ks = new ArrayList<KeySchemaElement>();
        ks.add(new KeySchemaElement().withAttributeName("DonorId").withKeyType(KeyType.HASH));
        ks.add(new KeySchemaElement().withAttributeName("Category").withKeyType(KeyType.RANGE));

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

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

        CreateTableResult result = client.createTable(request);

        //wait until the table is Active
        try {
        DescribeTableResult describeTableResult = client.describeTable(new DescribeTableRequest(doantionDataTableName));
        while (describeTableResult.getTable().getTableStatus()!="ACTIVE")
        {
            Thread.sleep(500);
        }
        }
        catch (Exception e)
        {
            throw new RuntimeException();
        }
    }
 
開發者ID:aws-reinvent-hackathon-2013-team,項目名稱:UnitedWayRESTBackend,代碼行數:36,代碼來源:DataAccess.java

示例7: createTable

import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; //導入方法依賴的package包/類
public static void createTable() {

        Log.d(TAG, "Create table called");

        AmazonDynamoDBClient ddb = UserPreferenceDemoActivity.clientManager
                .ddb();

        KeySchemaElement kse = new KeySchemaElement().withAttributeName(
                "userNo").withKeyType(KeyType.HASH);
        AttributeDefinition ad = new AttributeDefinition().withAttributeName(
                "userNo").withAttributeType(ScalarAttributeType.N);
        ProvisionedThroughput pt = new ProvisionedThroughput()
                .withReadCapacityUnits(10l).withWriteCapacityUnits(5l);

        CreateTableRequest request = new CreateTableRequest()
                .withTableName(Constants.TEST_TABLE_NAME)
                .withKeySchema(kse).withAttributeDefinitions(ad)
                .withProvisionedThroughput(pt);

        try {
            Log.d(TAG, "Sending Create table request");
            ddb.createTable(request);
            Log.d(TAG, "Create request response successfully recieved");
        } catch (AmazonServiceException ex) {
            Log.e(TAG, "Error sending create table request", ex);
            UserPreferenceDemoActivity.clientManager
                    .wipeCredentialsOnAuthError(ex);
        }
    }
 
開發者ID:awslabs,項目名稱:aws-sdk-android-samples,代碼行數:30,代碼來源:DynamoDBManager.java

示例8: createTokenTables

import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; //導入方法依賴的package包/類
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);
}
 
開發者ID:Vivastream,項目名稱:spring-security-oauth2-dynamodb,代碼行數:48,代碼來源:DynamoDBInitializationHelper.java


注:本文中的com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.createTable方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。