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


Java CreateTableResult类代码示例

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


CreateTableResult类属于com.amazonaws.services.dynamodbv2.model包,在下文中一共展示了CreateTableResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCreateTableWithWait

import com.amazonaws.services.dynamodbv2.model.CreateTableResult; //导入依赖的package包/类
@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);
}
 
开发者ID:schibsted,项目名称:strongbox,代码行数:20,代码来源:GenericDynamoDBTest.java

示例2: createTable

import com.amazonaws.services.dynamodbv2.model.CreateTableResult; //导入依赖的package包/类
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;
}
 
开发者ID:bizo,项目名称:aws-java-sdk-stubs,代码行数:23,代码来源:AmazonDynamoDBStubTest.java

示例3: safeCreateTable

import com.amazonaws.services.dynamodbv2.model.CreateTableResult; //导入依赖的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

示例4: scan

import com.amazonaws.services.dynamodbv2.model.CreateTableResult; //导入依赖的package包/类
/***
 * 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);
		}			
	}
}
 
开发者ID:shagwood,项目名称:micro-genie,代码行数:36,代码来源:DynamoAdmin.java

示例5: createTable

import com.amazonaws.services.dynamodbv2.model.CreateTableResult; //导入依赖的package包/类
/***
 * 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;
}
 
开发者ID:shagwood,项目名称:micro-genie,代码行数:31,代码来源:DynamoAdmin.java

示例6: createTableTest

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

示例7: createTable

import com.amazonaws.services.dynamodbv2.model.CreateTableResult; //导入依赖的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

示例8: setup

import com.amazonaws.services.dynamodbv2.model.CreateTableResult; //导入依赖的package包/类
/**
 * 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());
}
 
开发者ID:duraspace,项目名称:lambdora,代码行数:13,代码来源:IntegrationTestBase.java

示例9: createTable

import com.amazonaws.services.dynamodbv2.model.CreateTableResult; //导入依赖的package包/类
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);
}
 
开发者ID:duraspace,项目名称:lambdora,代码行数:41,代码来源:IntegrationTestBase.java

示例10: create

import com.amazonaws.services.dynamodbv2.model.CreateTableResult; //导入依赖的package包/类
@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();
    }
}
 
开发者ID:schibsted,项目名称:strongbox,代码行数:15,代码来源:GenericDynamoDB.java

示例11: createPlanoRequestsTable

import com.amazonaws.services.dynamodbv2.model.CreateTableResult; //导入依赖的package包/类
private CreateTableResult createPlanoRequestsTable() {
    CreateTableRequest request = mapper.generateCreateTableRequest(DynamoDBPlanoRequest.class)
            .withProvisionedThroughput(new ProvisionedThroughput()
                    .withReadCapacityUnits(5L)
                    .withWriteCapacityUnits(6L));

    CreateTableResult createTableResult = dynamoDB.createTable(request);

    return createTableResult;
}
 
开发者ID:milton0825,项目名称:plano,代码行数:11,代码来源:PlanoApplicationDynamoDBTests.java

示例12: createPlanoRequestsTable

import com.amazonaws.services.dynamodbv2.model.CreateTableResult; //导入依赖的package包/类
private CreateTableResult createPlanoRequestsTable() {
    CreateTableRequest request = sDynamoDBMapper.generateCreateTableRequest(DynamoDBPlanoRequest.class)
            .withProvisionedThroughput(new ProvisionedThroughput()
                    .withReadCapacityUnits(5L)
                    .withWriteCapacityUnits(6L));

    CreateTableResult createTableResult = sDynamoDB.createTable(request);

    return createTableResult;
}
 
开发者ID:milton0825,项目名称:plano,代码行数:11,代码来源:DynamoDBRepositoryTests.java

示例13: createTable

import com.amazonaws.services.dynamodbv2.model.CreateTableResult; //导入依赖的package包/类
/**
 * 
 * @{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);
    }
}
 
开发者ID:intuit,项目名称:Tank,代码行数:40,代码来源:AmazonDynamoDatabaseDocApi.java

示例14: createTable

import com.amazonaws.services.dynamodbv2.model.CreateTableResult; //导入依赖的package包/类
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;
}
 
开发者ID:awslabs,项目名称:dynamodb-janusgraph-storage-backend,代码行数:14,代码来源:DynamoDbDelegate.java

示例15: createTable

import com.amazonaws.services.dynamodbv2.model.CreateTableResult; //导入依赖的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


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