/** * Creates the table in DynamoDB. The hash+range key is: * * Hash (String) | Range (String) * File Path File Name * Example: s3n://netflix/data test.xml * * The table also includes one attribute for epoch (time created), but * that is only defined during the put operation (see add()). * */ private void createTable() { log.info("Creating table in DynamoDB: " + tableName); CreateTableRequest createRequest = new CreateTableRequest(); createRequest.withTableName(tableName); //Key KeySchemaElement pathKey = new KeySchemaElement().withAttributeName(HASH_KEY).withAttributeType(ScalarAttributeType.S); KeySchemaElement fileKey = new KeySchemaElement().withAttributeName(RANGE_KEY).withAttributeType(ScalarAttributeType.S); KeySchema schema = new KeySchema(); schema.setHashKeyElement(pathKey); schema.setRangeKeyElement(fileKey); createRequest.setKeySchema(schema); //Throughput ProvisionedThroughput tp = new ProvisionedThroughput(); tp.setReadCapacityUnits(readUnits); tp.setWriteCapacityUnits(writeUnits); createRequest.setProvisionedThroughput(tp); db.createTable(createRequest); }
/** * Constructor for DynamoDBMapping * @param tables Tables mapped. * @param tablesToKeySchemas KeySchemas used within tables mapped. * @param provisionedThroughput Provisioned throughput used within tables mapped. */ public DynamoDBMapping(Map<String, List<Map<String, String>>> tables, Map<String, KeySchema> tablesToKeySchemas, Map<String, ProvisionedThroughput> provisionedThroughput) { this.tablesToItems = tables; this.tablesToKeySchemas = tablesToKeySchemas; this.tablesToPrTh = provisionedThroughput; }
/** * Builds the necessary requests to create tables * @param tableName * @param keySchema * @param proThrou * @return */ private CreateTableRequest getCreateTableRequest(String tableName, KeySchema keySchema, ProvisionedThroughput proThrou){ CreateTableRequest createTableRequest = new CreateTableRequest(); createTableRequest.setTableName(tableName); createTableRequest.setKeySchema(keySchema); createTableRequest.setProvisionedThroughput(proThrou); return createTableRequest; }
/** * Gets the provisioned throughput from a specific table * @param tableName Table name to determine which provisioned throughput to get * @return */ public ProvisionedThroughput getProvisionedThroughput(String tableName){ return tablesToPrTh.get(tableName); }
/** * Sets the provisioned throughput for the specified table * @param tableName * @param readCapUnits * @param writeCapUnits */ public void setProvisionedThroughput(String tableName, long readCapUnits, long writeCapUnits){ ProvisionedThroughput ptDesc = new ProvisionedThroughput().withReadCapacityUnits(readCapUnits).withWriteCapacityUnits(writeCapUnits); tablesToPrTh.put(tableName, ptDesc); }