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

项目:strongbox    文件:GenericDynamoDB.java   
public CreateTableRequest constructCreateTableRequest() {
    ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName(partitionKeyName.toString()).withAttributeType("S"));
    attributeDefinitions.add(new AttributeDefinition().withAttributeName(sortKeyName.toString()).withAttributeType("N"));

    ArrayList<KeySchemaElement> keySchema = new ArrayList<>();
    keySchema.add(new KeySchemaElement().withAttributeName(partitionKeyName.toString()).withKeyType(KeyType.HASH));
    keySchema.add(new KeySchemaElement().withAttributeName(sortKeyName.toString()).withKeyType(KeyType.RANGE));

    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
            .withReadCapacityUnits(1L)
            .withWriteCapacityUnits(1L);
    CreateTableRequest request = new CreateTableRequest()
            .withTableName(tableName)
            .withKeySchema(keySchema)
            .withAttributeDefinitions(attributeDefinitions)
            .withProvisionedThroughput(provisionedThroughput);
    return request;
}
项目:Java-9-Programming-Blueprints    文件:CloudNoticeDAO.java   
private void createRecipientTable() {
    CreateTableRequest request
            = new CreateTableRequest()
                    .withTableName(TABLE_NAME)
                    .withAttributeDefinitions(
                            new AttributeDefinition("_id", ScalarAttributeType.S)
                    )
                    .withKeySchema(
                            new KeySchemaElement("_id", KeyType.HASH)
                    )
                    .withProvisionedThroughput(new ProvisionedThroughput(10L, 10L));

    ddb.createTable(request);
    try {
        TableUtils.waitUntilActive(ddb, TABLE_NAME);
    } catch (InterruptedException  e) {
        throw new RuntimeException(e);
    }
}
项目:orbit-dynamodb    文件:DynamoDBPersistenceTest.java   
@Override
public void closeStorage()
{
    try
    {
        dynamoDBConnection.getDynamoClient().describeTable(getTableName());
        dynamoDBConnection.getDynamoClient().deleteTable(getTableName());
    }
    catch(ResourceNotFoundException e)
    {

    }

    dynamoDBConnection.getDynamoDB().createTable(getTableName(),
            Collections.singletonList(
                    new KeySchemaElement("_id", KeyType.HASH)),
            Collections.singletonList(
                   new AttributeDefinition("_id", ScalarAttributeType.S)),
            new ProvisionedThroughput(1L, 1L));
}
项目:drill-dynamo-adapter    文件:BaseDynamoTest.java   
protected Table createHashAndSortTable(String pk, String sort) throws InterruptedException {
  ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<>();
  ScalarAttributeType type = ScalarAttributeType.S;
  attributeDefinitions.add(new AttributeDefinition()
    .withAttributeName(pk).withAttributeType(type));
  attributeDefinitions
    .add(new AttributeDefinition().withAttributeName(sort).withAttributeType(type));
  ArrayList<KeySchemaElement> keySchema = new ArrayList<>();
  keySchema.add(new KeySchemaElement().withAttributeName(pk).withKeyType(KeyType.HASH));
  keySchema.add(new KeySchemaElement().withAttributeName(sort).withKeyType(KeyType.RANGE));

  CreateTableRequest request = new CreateTableRequest()
    .withKeySchema(keySchema)
    .withAttributeDefinitions(attributeDefinitions);
  return createTable(request);
}
项目:java-translatebot    文件:DatabaseDeployer.java   
public void deploy() {

        final AttributeDefinition idAttr = new AttributeDefinition().withAttributeName("id")
                .withAttributeType(ScalarAttributeType.S);
        final ProvisionedThroughput throughput = new ProvisionedThroughput().withReadCapacityUnits(5L)
                .withWriteCapacityUnits(5L);

        final KeySchemaElement idKey = new KeySchemaElement().withAttributeName("id").withKeyType(KeyType.HASH);

        final CreateTableRequest createTableRequest = new CreateTableRequest().withTableName("TranslateSlack")
                .withAttributeDefinitions(idAttr)
                .withKeySchema(idKey)
                .withProvisionedThroughput(throughput);
        ;
        ;

        ddb.createTable(createTableRequest);

    }
项目:emr-dynamodb-connector    文件:DynamoDBStorageHandler.java   
void checkTableSchemaType(TableDescription tableDescription, Table table) throws MetaException {
  List<FieldSchema> tableSchema = table.getSd().getCols();

  for (FieldSchema fieldSchema : tableSchema) {
    for (AttributeDefinition definition : tableDescription.getAttributeDefinitions()) {
      validateKeySchema(definition.getAttributeName(), definition.getAttributeType(),
          fieldSchema);
    }

    // Check for each field type
    if (HiveDynamoDBTypeFactory.getTypeObjectFromHiveType(fieldSchema.getType()) == null) {
      throw new MetaException("The hive type " + fieldSchema.getType() + " is not supported in "
          + "DynamoDB");
    }
  }
}
项目:emr-dynamodb-connector    文件:DynamoDBRecordReaderTest.java   
private TableDescription getTableDescription(String hashType, String rangeType) {
  List<KeySchemaElement> keySchema = new ArrayList<>();
  List<AttributeDefinition> definitions = new ArrayList<>();

  keySchema.add(new KeySchemaElement().withAttributeName("hashKey").withKeyType(KeyType.HASH));
  definitions.add(new AttributeDefinition().withAttributeName("hashKey").withAttributeType
      (hashType));

  if (rangeType != null) {
    keySchema.add(new KeySchemaElement().withAttributeName("rangeKey").withKeyType(KeyType
        .RANGE));
    definitions.add(new AttributeDefinition().withAttributeName("rangeKey").withAttributeType
        (rangeType));
  }

  TableDescription description = new TableDescription().withKeySchema(keySchema)
      .withAttributeDefinitions(definitions).withProvisionedThroughput(new
          ProvisionedThroughputDescription().withReadCapacityUnits(1000L)
          .withWriteCapacityUnits(1000L));
  return description;
}
项目:fleet-cron    文件:DynamoDbLockerTest.java   
@Before
public void setUp() {
    // Unique table for each run
    tableName = "table" + String.valueOf(tableCount++);
    dynamoDB.getDynamoDbClient().createTable(
        new CreateTableRequest()
            .withTableName(tableName)
            .withKeySchema(new KeySchemaElement("id", "HASH"))
            .withAttributeDefinitions(
                new AttributeDefinition("id", "S")
            )
            .withProvisionedThroughput(
                new ProvisionedThroughput(1L, 1L)
            )
    );

    locker = new DynamoDbLocker(
        new DynamoDB(dynamoDB.getDynamoDbClient()),
        tableName,
        Clock.systemUTC()
    );
}
项目:dynamodb-janusgraph-storage-backend    文件:DynamoDbStore.java   
@Override
public CreateTableRequest getTableSchema() {
    return super.getTableSchema()
        .withAttributeDefinitions(
            new AttributeDefinition()
                .withAttributeName(Constants.JANUSGRAPH_HASH_KEY)
                .withAttributeType(ScalarAttributeType.S),
            new AttributeDefinition()
                .withAttributeName(Constants.JANUSGRAPH_RANGE_KEY)
                .withAttributeType(ScalarAttributeType.S))
        .withKeySchema(
            new KeySchemaElement()
                .withAttributeName(Constants.JANUSGRAPH_HASH_KEY)
                .withKeyType(KeyType.HASH),
            new KeySchemaElement()
                .withAttributeName(Constants.JANUSGRAPH_RANGE_KEY)
                .withKeyType(KeyType.RANGE));
}
项目:amazon-cognito-developer-authentication-sample    文件:UserAuthentication.java   
/**
 * Used to create the Identity Table. This function only needs to be called
 * once.
 */
protected void createIdentityTable() throws DataAccessException {
    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
            .withReadCapacityUnits(10L)
            .withWriteCapacityUnits(5L);

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

    ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
    tableKeySchema.add(new KeySchemaElement().withAttributeName(ATTRIBUTE_USERNAME).withKeyType(KeyType.HASH));

    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(USER_TABLE)
            .withProvisionedThroughput(provisionedThroughput)
            .withAttributeDefinitions(attributeDefinitions)
            .withKeySchema(tableKeySchema);

    try {
        ddb.createTable(createTableRequest);
    } catch (AmazonClientException e) {
        throw new DataAccessException("Failed to create table: " + USER_TABLE, e);
    }
}
项目:amazon-cognito-developer-authentication-sample    文件:DeviceAuthentication.java   
/**
 * Used to create the device table. This function only needs to be called
 * once.
 */
protected void createDeviceTable() throws DataAccessException {
    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
            .withReadCapacityUnits(10L)
            .withWriteCapacityUnits(5L);

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

    ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
    tableKeySchema.add(new KeySchemaElement().withAttributeName(ATTRIBUTE_UID)
            .withKeyType(KeyType.HASH));

    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(DEVICE_TABLE)
            .withProvisionedThroughput(provisionedThroughput)
            .withAttributeDefinitions(attributeDefinitions)
            .withKeySchema(tableKeySchema);

    try {
        ddb.createTable(createTableRequest);
    } catch (AmazonClientException e) {
        throw new DataAccessException("Failed to create table: " + DEVICE_TABLE, e);
    }
}
项目: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;
}
项目:ColumnStoreUnifier    文件:DynamoDbQueryHandler.java   
/**
 * Create a table with the given hashKey as row id
 * 
 * @param tableName
 * @param primaryKey
 */
public static void createTable(String tableName, String primaryKey) {
    ArrayList<KeySchemaElement> ks = new ArrayList<KeySchemaElement>();
    ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();

    ks.add(new KeySchemaElement().withAttributeName(primaryKey)
            .withKeyType(KeyType.HASH));
    attributeDefinitions.add(new AttributeDefinition().withAttributeName(
            primaryKey).withAttributeType("S"));

    CreateTableRequest request = new CreateTableRequest()
            .withTableName(tableName).withKeySchema(ks)
            .withProvisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT);

    request.setAttributeDefinitions(attributeDefinitions);
    try {
        DynamoDbHandler.CLIENT.createTable(request);
    } catch (ResourceInUseException e) {
        //System.err.println("Table '" + tableName + "' already exists");
    }
}
项目:amazon-kinesis-aggregators    文件:InventoryModel.java   
protected void init() throws Exception {
    List<AttributeDefinition> attributes = new ArrayList<AttributeDefinition>() {
        {
            add(new AttributeDefinition().withAttributeName(InventoryModel.AGGREGATOR).withAttributeType(
                    "S"));
            add(new AttributeDefinition().withAttributeName(InventoryModel.SHARD_ID).withAttributeType(
                    "S"));
        }
    };

    List<KeySchemaElement> key = new ArrayList<KeySchemaElement>() {
        {
            add(new KeySchemaElement().withAttributeName(InventoryModel.AGGREGATOR).withKeyType(
                    KeyType.HASH));
            add(new KeySchemaElement().withAttributeName(InventoryModel.SHARD_ID).withKeyType(
                    KeyType.RANGE));
        }
    };

    DynamoUtils.initTable(dynamoClient, InventoryModel.TABLE_NAME,
            InventoryModel.READ_CAPACITY, InventoryModel.WRITE_CAPACITY, attributes, key, null);

    online = true;
}
项目:para    文件:AWSDynamoUtils.java   
/**
 * Creates a table in AWS DynamoDB.
 * @param appid name of the {@link com.erudika.para.core.App}
 * @param readCapacity read capacity
 * @param writeCapacity write capacity
 * @return true if created
 */
public static boolean createTable(String appid, long readCapacity, long writeCapacity) {
    if (StringUtils.isBlank(appid)) {
        return false;
    } else if (StringUtils.containsWhitespace(appid)) {
        logger.warn("DynamoDB table name contains whitespace. The name '{}' is invalid.", appid);
        return false;
    } else if (existsTable(appid)) {
        logger.warn("DynamoDB table '{}' already exists.", appid);
        return false;
    }
    try {
        String table = getTableNameForAppid(appid);
        getClient().createTable(new CreateTableRequest().withTableName(table).
                withKeySchema(new KeySchemaElement(Config._KEY, KeyType.HASH)).
                withAttributeDefinitions(new AttributeDefinition(Config._KEY, ScalarAttributeType.S)).
                withProvisionedThroughput(new ProvisionedThroughput(readCapacity, writeCapacity)));
        logger.info("Created DynamoDB table '{}'.", table);
    } catch (Exception e) {
        logger.error(null, e);
        return false;
    }
    return true;
}
项目:gora    文件:DynamoDBUtils.java   
/**
 * Builds the necessary requests to create tables
 * 
 * @param tableName
 * @param keySchema
 * @param proThrou
 * @param attrs 
 * @return
 */
public static CreateTableRequest buildCreateTableRequest(String tableName,
    ArrayList<KeySchemaElement> keySchema, ProvisionedThroughput proThrou, Map<String, String> attrs) {
  CreateTableRequest createTableRequest = new CreateTableRequest();
  createTableRequest.setTableName(tableName);
  createTableRequest.setKeySchema(keySchema);
  ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
  for (KeySchemaElement kEle : keySchema) {
    AttributeDefinition attrDef = new AttributeDefinition();
    attrDef.setAttributeName(kEle.getAttributeName());
    attrDef.setAttributeType(attrs.get(kEle.getAttributeName()));
    attributeDefinitions.add(attrDef);
  }
  createTableRequest.setAttributeDefinitions(attributeDefinitions);
  createTableRequest.setProvisionedThroughput(proThrou);
  return createTableRequest;
}
项目: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);  
        }
    }
}
项目:aws-dynamodb-examples    文件:LowLevelTableExample.java   
static void createExampleTable() {


    // Provide the initial provisioned throughput values as Java long data types
    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
        .withReadCapacityUnits(5L)
        .withWriteCapacityUnits(6L);
    CreateTableRequest request = new CreateTableRequest()
        .withTableName(tableName)
        .withProvisionedThroughput(provisionedThroughput);

    ArrayList<AttributeDefinition> attributeDefinitions= new ArrayList<AttributeDefinition>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName("Id").withAttributeType("N"));
    request.setAttributeDefinitions(attributeDefinitions);

    ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
    tableKeySchema.add(new KeySchemaElement().withAttributeName("Id").withKeyType(KeyType.HASH));
    request.setKeySchema(tableKeySchema);

    client.createTable(request);

    waitForTableToBecomeAvailable(tableName); 

    getTableInformation();

}
项目:aws-dynamodb-examples    文件:MoviesCreateTable.java   
public static void main(String[] args) throws Exception {

        AmazonDynamoDBClient client = new AmazonDynamoDBClient();

        client.setEndpoint("http://localhost:8000");
        DynamoDB dynamoDB = new DynamoDB(client);

        String tableName = "Movies";
        Table table = dynamoDB.createTable(tableName,
                Arrays.asList(
                        new KeySchemaElement("year", KeyType.HASH),
                        new KeySchemaElement("title", KeyType.RANGE)), 
                Arrays.asList(
                        new AttributeDefinition("year", ScalarAttributeType.N),
                        new AttributeDefinition("title", ScalarAttributeType.S)), 
                new ProvisionedThroughput(10L, 10L));

        try {
            TableUtils.waitUntilActive(client, tableName);
            System.out.println("Table status: " + table.getDescription().getTableStatus());
        } catch (AmazonClientException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
项目: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);
}
项目:reinvent2013-mobile-photo-share    文件:DeviceAuthentication.java   
/**
 * Used to create the device table. This function only needs to be called
 * once.
 */
protected void createDeviceTable() throws DataAccessException {
    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
            .withReadCapacityUnits(10L)
            .withWriteCapacityUnits(5L);

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

    ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
    tableKeySchema.add(new KeySchemaElement().withAttributeName(ATTRIBUTE_UID)
            .withKeyType(KeyType.HASH));

    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(DEVICE_TABLE)
            .withProvisionedThroughput(provisionedThroughput)
            .withAttributeDefinitions(attributeDefinitions)
            .withKeySchema(tableKeySchema);

    try {
        ddb.createTable(createTableRequest);
    } catch (AmazonClientException e) {
        throw new DataAccessException("Failed to create table: " + DEVICE_TABLE, e);
    }
}
项目:reinvent2013-mobile-photo-share    文件:UserAuthentication.java   
/**
 * Used to create the Identity Table. This function only needs to be called
 * once.
 */
protected void createIdentityTable() throws DataAccessException {
    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
            .withReadCapacityUnits(10L)
            .withWriteCapacityUnits(5L);

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

    ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
    tableKeySchema.add(new KeySchemaElement().withAttributeName(ATTRIBUTE_USERNAME).withKeyType(KeyType.HASH));

    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(USER_TABLE)
            .withProvisionedThroughput(provisionedThroughput)
            .withAttributeDefinitions(attributeDefinitions)
            .withKeySchema(tableKeySchema);

    try {
        ddb.createTable(createTableRequest);
    } catch (AmazonClientException e) {
        throw new DataAccessException("Failed to create table: " + USER_TABLE, e);
    }
}
项目:reinvent2013-mobile-photo-share    文件:DeviceAuthentication.java   
/**
 * Used to create the device table. This function only needs to be called
 * once.
 */
protected void createDeviceTable() throws DataAccessException {
    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
            .withReadCapacityUnits(10L)
            .withWriteCapacityUnits(5L);

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

    ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
    tableKeySchema.add(new KeySchemaElement().withAttributeName(ATTRIBUTE_UID)
            .withKeyType(KeyType.HASH));

    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(DEVICE_TABLE)
            .withProvisionedThroughput(provisionedThroughput)
            .withAttributeDefinitions(attributeDefinitions)
            .withKeySchema(tableKeySchema);

    try {
        ddb.createTable(createTableRequest);
    } catch (AmazonClientException e) {
        throw new DataAccessException("Failed to create table: " + DEVICE_TABLE, e);
    }
}
项目:quartz-dynamodb    文件:DynamoDbJobStore.java   
private void initializeHashAndRangeTable(String name, String hashName, String rangeName) {
    String tableName = quartzPrefix + name;

    if (!tableExists(tableName)) {
        log.info(String.format("Creating table '%s' with hash and range index.", tableName));
        CreateTableRequest request = new CreateTableRequest()
                .withTableName(tableName)
                .withKeySchema(
                        new KeySchemaElement().withKeyType(KeyType.HASH).withAttributeName(hashName),
                        new KeySchemaElement().withKeyType(KeyType.RANGE).withAttributeName(rangeName))
                .withAttributeDefinitions(
                        new AttributeDefinition(hashName, ScalarAttributeType.S),
                        new AttributeDefinition(rangeName, ScalarAttributeType.S))
                .withProvisionedThroughput(new ProvisionedThroughput(1L, 1L));

        client.createTable(request);

        waitForTable(tableName);
    } else {
        log.info(String.format("Table '%s' already exists.", tableName));
    }
}
项目:quartz-dynamodb    文件:DynamoDbJobStore.java   
private void initializeHashTable(String name, String hashName) {
    String tableName = quartzPrefix + name;

    if (!tableExists(tableName)) {
        log.info(String.format("Creating table '%s' with hash index.", tableName));
        CreateTableRequest request = new CreateTableRequest()
                .withTableName(tableName)
                .withKeySchema(
                        new KeySchemaElement().withKeyType(KeyType.HASH).withAttributeName(hashName))
                .withAttributeDefinitions(
                        new AttributeDefinition(hashName, ScalarAttributeType.S))
                .withProvisionedThroughput(new ProvisionedThroughput(1L, 1L));

        client.createTable(request);

        waitForTable(tableName);
    } else {
        log.info(String.format("Table '%s' already exists.", tableName));
    }
}
项目:aws-dynamodb-session-tomcat    文件:DynamoUtils.java   
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);
}
项目: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);
}
项目:cas-5.1.0    文件:DynamoDbTicketRegistryFacilitator.java   
/**
 * Create ticket tables.
 *
 * @param deleteTables the delete tables
 */
public void createTicketTables(final boolean deleteTables) {
    final Collection<TicketDefinition> metadata = this.ticketCatalog.findAll();
    metadata.forEach(Unchecked.consumer(r -> {
        final CreateTableRequest request = new CreateTableRequest()
                .withAttributeDefinitions(new AttributeDefinition(ColumnNames.ID.getName(), ScalarAttributeType.S))
                .withKeySchema(new KeySchemaElement(ColumnNames.ID.getName(), KeyType.HASH))
                .withProvisionedThroughput(new ProvisionedThroughput(dynamoDbProperties.getReadCapacity(),
                        dynamoDbProperties.getWriteCapacity()))
                .withTableName(r.getProperties().getStorageName());


        if (deleteTables) {
            final DeleteTableRequest delete = new DeleteTableRequest(r.getProperties().getStorageName());
            LOGGER.debug("Sending delete request [{}] to remove table if necessary", delete);
            TableUtils.deleteTableIfExists(amazonDynamoDBClient, delete);
        }
        LOGGER.debug("Sending delete request [{}] to create table", request);
        TableUtils.createTableIfNotExists(amazonDynamoDBClient, request);

        LOGGER.debug("Waiting until table [{}] becomes active...", request.getTableName());
        TableUtils.waitUntilActive(amazonDynamoDBClient, request.getTableName());

        final DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(request.getTableName());
        LOGGER.debug("Sending request [{}] to obtain table description...", describeTableRequest);

        final TableDescription tableDescription = amazonDynamoDBClient.describeTable(describeTableRequest).getTable();
        LOGGER.debug("Located newly created table with description: [{}]", tableDescription);
    }));
}
项目:cas-5.1.0    文件:DynamoDbServiceRegistryFacilitator.java   
/**
 * Create tables.
 *
 * @param deleteTables the delete tables
 */
public void createServicesTable(final boolean deleteTables) {
    try {
        final CreateTableRequest request = new CreateTableRequest()
                .withAttributeDefinitions(new AttributeDefinition(ColumnNames.ID.getName(), ScalarAttributeType.S))
                .withKeySchema(new KeySchemaElement(ColumnNames.ID.getName(), KeyType.HASH))
                .withProvisionedThroughput(new ProvisionedThroughput(dynamoDbProperties.getReadCapacity(),
                        dynamoDbProperties.getWriteCapacity()))
                .withTableName(TABLE_NAME);

        if (deleteTables) {
            final DeleteTableRequest delete = new DeleteTableRequest(request.getTableName());
            LOGGER.debug("Sending delete request [{}] to remove table if necessary", delete);
            TableUtils.deleteTableIfExists(amazonDynamoDBClient, delete);
        }
        LOGGER.debug("Sending delete request [{}] to create table", request);
        TableUtils.createTableIfNotExists(amazonDynamoDBClient, request);

        LOGGER.debug("Waiting until table [{}] becomes active...", request.getTableName());
        TableUtils.waitUntilActive(amazonDynamoDBClient, request.getTableName());

        final DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(request.getTableName());
        LOGGER.debug("Sending request [{}] to obtain table description...", describeTableRequest);

        final TableDescription tableDescription = amazonDynamoDBClient.describeTable(describeTableRequest).getTable();
        LOGGER.debug("Located newly created table with description: [{}]", tableDescription);
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
项目:cas-5.1.0    文件:DynamoDbCloudConfigBootstrapConfiguration.java   
private static void createSettingsTable(final AmazonDynamoDBClient amazonDynamoDBClient, final boolean deleteTables) {
    try {
        final CreateTableRequest request = new CreateTableRequest()
                .withAttributeDefinitions(new AttributeDefinition(ColumnNames.ID.getName(), ScalarAttributeType.S))
                .withKeySchema(new KeySchemaElement(ColumnNames.ID.getName(), KeyType.HASH))
                .withProvisionedThroughput(new ProvisionedThroughput(PROVISIONED_THROUGHPUT, PROVISIONED_THROUGHPUT))
                .withTableName(TABLE_NAME);

        if (deleteTables) {
            final DeleteTableRequest delete = new DeleteTableRequest(request.getTableName());
            LOGGER.debug("Sending delete request [{}] to remove table if necessary", delete);
            TableUtils.deleteTableIfExists(amazonDynamoDBClient, delete);
        }
        LOGGER.debug("Sending delete request [{}] to create table", request);
        TableUtils.createTableIfNotExists(amazonDynamoDBClient, request);

        LOGGER.debug("Waiting until table [{}] becomes active...", request.getTableName());
        TableUtils.waitUntilActive(amazonDynamoDBClient, request.getTableName());

        final DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(request.getTableName());
        LOGGER.debug("Sending request [{}] to obtain table description...", describeTableRequest);

        final TableDescription tableDescription = amazonDynamoDBClient.describeTable(describeTableRequest).getTable();
        LOGGER.debug("Located newly created table with description: [{}]", tableDescription);
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
项目:outland    文件:DynamoCreateGroupsTableTask.java   
private void createAppsTable(String tableName) {
  final AttributeDefinition appKey =
      new AttributeDefinition().withAttributeName(HASH_KEY).withAttributeType(
          ScalarAttributeType.S);

  final ArrayList<AttributeDefinition>
      tableAttributeDefinitions = Lists.newArrayList(appKey);

  final ArrayList<KeySchemaElement> tableKeySchema = Lists.newArrayList();
  tableKeySchema.add(
      new KeySchemaElement().withAttributeName(HASH_KEY).withKeyType(KeyType.HASH));

  final ProvisionedThroughput tableProvisionedThroughput =
      new ProvisionedThroughput()
          .withReadCapacityUnits(10L)
          .withWriteCapacityUnits(10L);

  final CreateTableRequest createTableRequest =
      new CreateTableRequest()
          .withTableName(tableName)
          .withKeySchema(tableKeySchema)
          .withAttributeDefinitions(tableAttributeDefinitions)
          .withProvisionedThroughput(tableProvisionedThroughput);

  final TableDescription tableDescription =
      amazonDynamoDB.createTable(createTableRequest).getTableDescription();

  logger.info("created_table {}", tableDescription);

  final DescribeTableRequest describeTableRequest =
      new DescribeTableRequest().withTableName(tableName);

  final TableDescription description =
      amazonDynamoDB.describeTable(describeTableRequest).getTable();

  logger.info("table_description: " + description);
}
项目:orbit-dynamodb    文件:DynamoDBUtils.java   
private static CreateTableRequest createCreateTableRequest(final String tableName)
{
    final List<KeySchemaElement> keySchema = new ArrayList<>();
    final List<AttributeDefinition> tableAttributes = new ArrayList<>();

    keySchema.add(new KeySchemaElement(FIELD_NAME_PRIMARY_ID, KeyType.HASH));
    tableAttributes.add(new AttributeDefinition(FIELD_NAME_PRIMARY_ID, ScalarAttributeType.S));


    return new CreateTableRequest()
            .withTableName(tableName)
            .withKeySchema(keySchema)
            .withAttributeDefinitions(tableAttributes)
            .withProvisionedThroughput(new ProvisionedThroughput(1L, 1L));
}
项目:drill-dynamo-adapter    文件:BaseDynamoTest.java   
protected Table createHashTable() throws InterruptedException {
  // single hash PK
  ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<>();
  attributeDefinitions.add(new AttributeDefinition()
    .withAttributeName(PK).withAttributeType("S"));
  ArrayList<KeySchemaElement> keySchema = new ArrayList<>();
  keySchema.add(new KeySchemaElement().withAttributeName(PK).withKeyType(KeyType.HASH));

  CreateTableRequest request = new CreateTableRequest()
    .withKeySchema(keySchema)
    .withAttributeDefinitions(attributeDefinitions);
  return createTable(request);
}
项目:emr-dynamodb-connector    文件:DynamoDBStorageHandlerTest.java   
private TableDescription getHashRangeTable() {
  TableDescription description = new TableDescription().withKeySchema(Arrays.asList(new
      KeySchemaElement().withAttributeName("hashKey"), new KeySchemaElement().withAttributeName
      ("rangeKey"))).withAttributeDefinitions(Arrays.asList(new AttributeDefinition("hashKey",
      ScalarAttributeType.S), new AttributeDefinition("rangeKey", ScalarAttributeType.N)));
  return description;
}
项目:java-persistence    文件:DdbSchema.java   
private static List<AttributeDefinition> toAttributeDefinitions(Map<String, AttrType> attrTypes) {
    return attrTypes.entrySet().stream()
        .map((entry) -> new AttributeDefinition()
             .withAttributeName(entry.getKey())
             .withAttributeType(toScalarAttributeType(entry.getValue())))
        .collect(Collectors.toList());
}
项目:java-persistence    文件:DdbSchema.java   
@Override
protected void createIndex(String tableName, IndexDescription index) {
    // We ALWAYS create these as GSI's, since you can't add a LSI:
    CreateGlobalSecondaryIndexAction createAction = new CreateGlobalSecondaryIndexAction()
        .withIndexName(index.getIndexName())
        .withKeySchema(toKeySchema(tableName, index))
        .withProvisionedThroughput(
            new ProvisionedThroughput()
            .withReadCapacityUnits(index.getReadCapacity())
            .withWriteCapacityUnits(index.getWriteCapacity()))
        .withProjection(new Projection().withProjectionType(ProjectionType.ALL));

    AttributeDefinition hashKey = new AttributeDefinition()
        .withAttributeName(index.getHashKey().getAttrName())
        .withAttributeType(toScalarAttributeType(index.getHashKey().getAttrType()));

    if ( null == index.getRangeKey() ) {
        _dynamodb.getTable(getTableName(tableName))
            .createGSI(createAction, hashKey);
    } else {
        AttributeDefinition rangeKey = new AttributeDefinition()
            .withAttributeName(index.getRangeKey().getAttrName())
            .withAttributeType(toScalarAttributeType(index.getRangeKey().getAttrType()));

        _dynamodb.getTable(getTableName(tableName))
            .createGSI(createAction, hashKey, rangeKey);
    }
}
项目: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    文件:DynamoDbSingleRowStore.java   
@Override
public CreateTableRequest getTableSchema() {
    return super.getTableSchema()
        .withAttributeDefinitions(
            new AttributeDefinition()
                .withAttributeName(Constants.JANUSGRAPH_HASH_KEY)
                .withAttributeType(ScalarAttributeType.S))
        .withKeySchema(
            new KeySchemaElement()
                .withAttributeName(Constants.JANUSGRAPH_HASH_KEY)
                .withKeyType(KeyType.HASH));
}
项目: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();
    }
}
项目:dynamodb-online-index-violation-detector    文件:TableHelper.java   
public String getTableHashKeyType() {
    String hashKeyName = getTableHashKeyName();
    List<AttributeDefinition> definitions = tableDescription.getAttributeDefinitions();
    for (AttributeDefinition attributeDef : definitions) {
        if (attributeDef.getAttributeName().endsWith(hashKeyName)) {
            return attributeDef.getAttributeType();
        }
    }
    return null;
}