当前位置: 首页>>代码示例>>Java>>正文


Java AmazonDynamoDB.createTable方法代码示例

本文整理汇总了Java中com.amazonaws.services.dynamodbv2.AmazonDynamoDB.createTable方法的典型用法代码示例。如果您正苦于以下问题:Java AmazonDynamoDB.createTable方法的具体用法?Java AmazonDynamoDB.createTable怎么用?Java AmazonDynamoDB.createTable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.amazonaws.services.dynamodbv2.AmazonDynamoDB的用法示例。


在下文中一共展示了AmazonDynamoDB.createTable方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTable

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
private static void createTable(AmazonDynamoDB dynamodb, String tableName, String tableKeyFieldName) {
        List<AttributeDefinition> attributeDefinitions= new ArrayList<>();
        attributeDefinitions.add(new AttributeDefinition().withAttributeName(tableKeyFieldName).withAttributeType("S"));

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

        CreateTableRequest request = new CreateTableRequest()
                .withTableName(tableName)
                .withKeySchema(keySchema)
                .withAttributeDefinitions(attributeDefinitions)
                .withProvisionedThroughput(new ProvisionedThroughput()
                        .withReadCapacityUnits(1L)
                        .withWriteCapacityUnits(1L));

        dynamodb.createTable(request);
//TODO: just to look at the result, if needed
//        TableDescription table = dynamodb.describeTable(tableName).getTable();
    }
 
开发者ID:satr,项目名称:aws-amazon-shopping-bot-lambda-func,代码行数:20,代码来源:TestRepositoryHelper.java

示例2: safeCreateTable

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
/**
 * 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;
		}
	}
}
 
开发者ID:awslabs,项目名称:amazon-kinesis-aggregators,代码行数:35,代码来源:DynamoUtils.java

示例3: createTable

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
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);
}
 
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:19,代码来源:DynamoDBEmbeddedTest.java

示例4: create

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
/**
 * Create table.
 * @throws InterruptedException If something fails
 */
public void create() throws InterruptedException {
    final AmazonDynamoDB aws = this.region.aws();
    final String name = this.request.getTableName();
    aws.createTable(this.request);
    Logger.info(this, "DynamoDB table '%s' creation requested...", name);
    final DescribeTableRequest req = new DescribeTableRequest()
        .withTableName(name);
    while (true) {
        final DescribeTableResult result = aws.describeTable(req);
        if ("ACTIVE".equals(result.getTable().getTableStatus())) {
            Logger.info(
                this,
                "DynamoDB table '%s' is %s",
                name, result.getTable().getTableStatus()
            );
            break;
        }
        Logger.info(
            this,
            "waiting for DynamoDB table '%s': %s",
            name, result.getTable().getTableStatus()
        );
        TimeUnit.SECONDS.sleep((long) Tv.TEN);
    }
}
 
开发者ID:jcabi,项目名称:jcabi-dynamo,代码行数:30,代码来源:MadeTable.java

示例5: createTable

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
/**
 * 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);

}
 
开发者ID:awslabs,项目名称:aws-dynamodb-encryption-java,代码行数:13,代码来源:MetaStore.java

示例6: open

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
private void open(boolean batchLoading)
{
    if(type == GraphDatabaseType.TITAN_DYNAMODB && config.getDynamodbPrecreateTables()) {
        List<CreateTableRequest> requests = new LinkedList<>();
        long wcu = config.getDynamodbTps();
        long rcu = Math.max(1, config.dynamodbConsistentRead() ? wcu : (wcu / 2));
        for(String store : Constants.REQUIRED_BACKEND_STORES) {
            final String tableName = config.getDynamodbTablePrefix() + "_" + store;
            if(BackendDataModel.MULTI == config.getDynamodbDataModel()) {
                requests.add(DynamoDBStore.createTableRequest(tableName,
                    rcu, wcu));
            } else if(BackendDataModel.SINGLE == config.getDynamodbDataModel()) {
                requests.add(DynamoDBSingleRowStore.createTableRequest(tableName, rcu, wcu));
            }
        }
        //TODO is this autocloseable?
        final AmazonDynamoDB client =
            new AmazonDynamoDBClient(Client.createAWSCredentialsProvider(config.getDynamodbCredentialsFqClassName(),
                config.getDynamodbCredentialsCtorArguments() == null ? null : config.getDynamodbCredentialsCtorArguments().split(",")));
        client.setEndpoint(config.getDynamodbEndpoint());
        for(CreateTableRequest request : requests) {
            try {
                client.createTable(request);
            } catch(ResourceInUseException ignore) {
                //already created, good
            }
        }
        client.shutdown();
    }
    titanGraph = buildTitanGraph(type, dbStorageDirectory, config, batchLoading);
}
 
开发者ID:socialsensor,项目名称:graphdb-benchmarks,代码行数:32,代码来源:TitanGraphDatabase.java

示例7: main

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
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!");
}
 
开发者ID:awsdocs,项目名称:aws-doc-sdk-examples,代码行数:42,代码来源:CreateTable.java

示例8: main

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
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!");
}
 
开发者ID:awsdocs,项目名称:aws-doc-sdk-examples,代码行数:44,代码来源:CreateTableCompositeKey.java

示例9: execute

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的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;
}
 
开发者ID:apache,项目名称:metamodel,代码行数:52,代码来源:DynamoDbTableCreationBuilder.java

示例10: startsAndStops

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:jcabi,项目名称:jcabi-dynamodb-maven-plugin,代码行数:53,代码来源:InstancesTest.java


注:本文中的com.amazonaws.services.dynamodbv2.AmazonDynamoDB.createTable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。