List of usage examples for com.amazonaws.services.dynamodbv2.model KeySchemaElement KeySchemaElement
public KeySchemaElement()
From source file:whgHelper.java
License:Open Source License
public static void setTable(AmazonDynamoDBClient dynamoDB, String tableName) { // Create table if it does not exist yet if (Tables.doesTableExist(dynamoDB, tableName)) { System.out.println("Table " + tableName + " is already ACTIVE"); } else {//from ww w . jav a2 s .c o m // Create a table with a primary hash key named 'name', which holds a string CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName) .withKeySchema(new KeySchemaElement().withAttributeName("alertId").withKeyType(KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition().withAttributeName("alertId") .withAttributeType(ScalarAttributeType.S)) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L)); TableDescription createdTableDescription = dynamoDB.createTable(createTableRequest) .getTableDescription(); System.out.println("Created Table: " + createdTableDescription); // Wait for it to become active System.out.println("Waiting for " + tableName + " to become ACTIVE..."); Tables.waitForTableToBecomeActive(dynamoDB, tableName); } return; }
From source file:AmazonDynamoDBSample_PutThrottled.java
License:Open Source License
public static void main(String[] args) throws Exception { init();//from w ww.ja va2 s . co m try { String tableName = "my-favorite-movies-table"; // Create a table with a primary hash key named 'name', which holds // a string CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName) .withKeySchema(new KeySchemaElement().withAttributeName("name").withKeyType(KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition().withAttributeName("name") .withAttributeType(ScalarAttributeType.S)) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L)); // Create table if it does not exist yet TableUtils.createTableIfNotExists(dynamoDB, createTableRequest); // wait for the table to move into ACTIVE state TableUtils.waitUntilActive(dynamoDB, tableName); // Describe our new table DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable(); System.out.println("Table Description: " + tableDescription); // Add an item Map<String, AttributeValue> item = newItem("Bill & Ted's Excellent Adventure", 1989, "****", "James", "Sara"); PutItemRequest putItemRequest = new PutItemRequest(tableName, item); PutItemResult putItemResult = dynamoDB.putItem(putItemRequest); System.out.println("Result: " + putItemResult); // Add another item item = newItem("Airplane", 1980, "*****", "James", "Billy Bob"); putItemRequest = new PutItemRequest(tableName, item); putItemResult = dynamoDB.putItem(putItemRequest); System.out.println("Result: " + putItemResult); Thread[] thrds = new Thread[16]; for (int i = 0; i < thrds.length; i++) { thrds[i] = newItemCreationThread(tableName, i); thrds[i].start(); } for (Thread thrd : thrds) { thrd.join(); } // Scan items for movies with a year attribute greater than 1985 HashMap<String, Condition> scanFilter = new HashMap<String, Condition>(); Condition condition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString()) .withAttributeValueList(new AttributeValue().withN("1985")); scanFilter.put("year", condition); ScanRequest scanRequest = new ScanRequest(tableName).withScanFilter(scanFilter); ScanResult scanResult = dynamoDB.scan(scanRequest); System.out.println("Result: " + scanResult); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to AWS, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with AWS, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:TableCreator.java
License:Open Source License
public static void main(String[] args) throws Exception { init();//from w ww. j a v a 2s .com long readCapacity = Long.valueOf(args[0]); long writeCapacity = Long.valueOf(args[1]); try { String tableName = "messages"; // DeleteTableRequest deleteTableRequest = new DeleteTableRequest(tableName); // dynamoDB.deleteTable(deleteTableRequest); // // waitForTableToBecomeAvailable(tableName); // Create a table with a primary hash key named 'name', which holds a string CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName) .withKeySchema(new KeySchemaElement().withAttributeName("messageId").withKeyType(KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition().withAttributeName("messageId") .withAttributeType(ScalarAttributeType.S)) .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(readCapacity) .withWriteCapacityUnits(writeCapacity)); TableDescription createdTableDescription = dynamoDB.createTable(createTableRequest) .getTableDescription(); System.out.println("Created Table: " + createdTableDescription); // Wait for it to become active waitForTableToBecomeAvailable(tableName); // Describe our new table DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable(); System.out.println("Table Description: " + tableDescription); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to AWS, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with AWS, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:DynamoDB.java
License:Open Source License
public void createTable() throws InterruptedException { // Create table if it does not exist yet if (Tables.doesTableExist(dynamoDB, tableName)) { System.out.println("Table " + tableName + " is already ACTIVE"); } else {//w w w.ja v a 2s. c o m // Create a table with a primary hash key named 'name', which holds a string CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName) .withKeySchema(new KeySchemaElement().withAttributeName("Id").withKeyType(KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition().withAttributeName("Id") .withAttributeType(ScalarAttributeType.S)) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L)); TableDescription createdTableDescription = dynamoDB.createTable(createTableRequest) .getTableDescription(); System.out.println("Created Table: " + createdTableDescription); // Wait for it to become active System.out.println("Waiting for " + tableName + " to become ACTIVE..."); Tables.awaitTableToBecomeActive(dynamoDB, tableName); } }
From source file:AmazonDynamoDBSample.java
License:Open Source License
public static void main(String[] args) throws Exception { init();// ww w. j a v a2 s. com try { String tableName = "storyTable"; // Create table if it does not exist yet if (Tables.doesTableExist(dynamoDB, tableName)) { System.out.println("Table " + tableName + " is already ACTIVE"); } else { // Create a table with a primary hash key named 'name', which holds a string CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName) .withKeySchema( new KeySchemaElement().withAttributeName("storyID").withKeyType(KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition().withAttributeName("storyID") .withAttributeType(ScalarAttributeType.N)) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L)); TableDescription createdTableDescription = dynamoDB.createTable(createTableRequest) .getTableDescription(); System.out.println("Created Table: " + createdTableDescription); // Wait for it to become active System.out.println("Waiting for " + tableName + " to become ACTIVE..."); Tables.awaitTableToBecomeActive(dynamoDB, tableName); } // Describe our new table DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable(); System.out.println("Table Description: " + tableDescription); Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime()); System.out.println(currentTimestamp); ByteBuffer b = createBody(); int id1 = 1; int id2 = 2; double d1 = 0; double d2 = 1; Timestamp inputTimestamp = currentTimestamp; // Add an item Map<String, AttributeValue> item = newItem(id1, "JAM", "This is JAM", b, inputTimestamp, inputTimestamp, d1, d2); System.out.println("here"); PutItemRequest putItemRequest = new PutItemRequest(tableName, item); System.out.println("here2"); System.out.println(item); System.out.println(putItemRequest); PutItemResult putItemResult = dynamoDB.putItem(putItemRequest); System.out.println("here3"); System.out.println("Result: " + putItemResult); // Add another item item = newItem(id2, "JAM2", "This is JAM2", b, inputTimestamp, inputTimestamp, d1, d2); putItemRequest = new PutItemRequest(tableName, item); putItemResult = dynamoDB.putItem(putItemRequest); System.out.println("Result: " + putItemResult); // Scan items for movies with a year attribute greater than 1985 // HashMap<String, Condition> scanFilter = new HashMap<String, Condition>(); // Condition condition = new Condition() // .withComparisonOperator(ComparisonOperator.GT) // .withAttributeValueList(new AttributeValue()); // scanFilter.put("year", condition); // ScanRequest scanRequest = new ScanRequest(tableName).withScanFilter(scanFilter); // ScanResult scanResult = dynamoDB.scan(scanRequest); // System.out.println("Result: " + scanResult); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to AWS, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with AWS, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:MonitorTableCreator.java
License:Open Source License
public static void main(String[] args) throws Exception { init();//from w w w . j av a 2s. c om long readCapacity = 2L; long writeCapacity = 2L; try { String tableName = "monitor"; // DeleteTableRequest deleteTableRequest = new DeleteTableRequest(tableName); // dynamoDB.deleteTable(deleteTableRequest); // // waitForTableToBecomeAvailable(tableName); // Create a table with a primary hash key named 'name', which holds a string CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName) .withKeySchema(new KeySchemaElement().withAttributeName("id").withKeyType(KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition().withAttributeName("id") .withAttributeType(ScalarAttributeType.N)) .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(readCapacity) .withWriteCapacityUnits(writeCapacity)); TableDescription createdTableDescription = dynamoDB.createTable(createTableRequest) .getTableDescription(); System.out.println("Created Table: " + createdTableDescription); // Wait for it to become active waitForTableToBecomeAvailable(tableName); // Describe our new table DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable(); System.out.println("Table Description: " + tableDescription); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to AWS, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with AWS, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:amazon.dynamodb.util.GeoTableUtil.java
License:Open Source License
/** * <p>//from www.ja v a 2s.c o m * Construct a create table request object based on GeoDataManagerConfiguration. The users can update any aspect of * the request and call it. * </p> * Example: * * <pre> * AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(new ClasspathPropertiesFileCredentialsProvider()); * Region usWest2 = Region.getRegion(Regions.US_WEST_2); * ddb.setRegion(usWest2); * * CreateTableRequest createTableRequest = GeoTableUtil.getCreateTableRequest(config); * CreateTableResult createTableResult = ddb.createTable(createTableRequest); * </pre> * * @return Generated create table request. */ public static CreateTableRequest getCreateTableRequest(GeoDataManagerConfiguration config) { CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(config.getTableName()) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(10L).withWriteCapacityUnits(5L)) .withKeySchema( new KeySchemaElement().withKeyType(KeyType.HASH) .withAttributeName(config.getHashKeyAttributeName()), new KeySchemaElement().withKeyType(KeyType.RANGE) .withAttributeName(config.getRangeKeyAttributeName())) .withAttributeDefinitions( new AttributeDefinition().withAttributeType(ScalarAttributeType.N) .withAttributeName(config.getHashKeyAttributeName()), new AttributeDefinition().withAttributeType(ScalarAttributeType.S) .withAttributeName(config.getRangeKeyAttributeName()), new AttributeDefinition().withAttributeType(ScalarAttributeType.N) .withAttributeName(config.getGeohashAttributeName())) .withLocalSecondaryIndexes(new LocalSecondaryIndex().withIndexName(config.getGeohashIndexName()) .withKeySchema( new KeySchemaElement().withKeyType(KeyType.HASH) .withAttributeName(config.getHashKeyAttributeName()), new KeySchemaElement().withKeyType(KeyType.RANGE) .withAttributeName(config.getGeohashAttributeName())) .withProjection(new Projection().withProjectionType(ProjectionType.ALL))); return createTableRequest; }
From source file:awslabs.lab22.SolutionCode.java
License:Open Source License
@Override public void buildTable(AmazonDynamoDBClient ddbClient, String tableName) { System.out.println("Creating table."); CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName); createTableRequest.setAttributeDefinitions(new ArrayList<AttributeDefinition>()); // Define attributes createTableRequest.getAttributeDefinitions() .add(new AttributeDefinition().withAttributeName("Company").withAttributeType("S")); createTableRequest.getAttributeDefinitions() .add(new AttributeDefinition().withAttributeName("Email").withAttributeType("S")); // Define key schema createTableRequest.setKeySchema(new ArrayList<KeySchemaElement>()); createTableRequest.getKeySchema()/*from w ww .ja va2 s. com*/ .add(new KeySchemaElement().withAttributeName("Company").withKeyType("HASH")); createTableRequest.getKeySchema() .add(new KeySchemaElement().withAttributeName("Email").withKeyType("RANGE")); // Define provisioned throughput createTableRequest.setProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(10L).withWriteCapacityUnits(5L)); // Submit create request ddbClient.createTable(createTableRequest); // Pause until the table is active waitForStatus(ddbClient, tableName, "ACTIVE"); System.out.println("Table created and active."); }
From source file:awslabs.lab51.SolutionCode.java
License:Open Source License
@Override public void buildTable(AmazonDynamoDBClient ddbClient, String tableName) { CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName); createTableRequest.setAttributeDefinitions(new ArrayList<AttributeDefinition>()); // Define attributes createTableRequest.getAttributeDefinitions() .add(new AttributeDefinition().withAttributeName("Key").withAttributeType("S")); createTableRequest.getAttributeDefinitions() .add(new AttributeDefinition().withAttributeName("Bucket").withAttributeType("S")); // Define key schema createTableRequest.setKeySchema(new ArrayList<KeySchemaElement>()); createTableRequest.getKeySchema().add(new KeySchemaElement().withAttributeName("Key").withKeyType("HASH")); createTableRequest.getKeySchema()//from w w w . ja v a2 s . c om .add(new KeySchemaElement().withAttributeName("Bucket").withKeyType("RANGE")); // Define provisioned throughput createTableRequest.setProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(5L).withWriteCapacityUnits(5L)); // Submit create request ddbClient.createTable(createTableRequest); // Pause until the table is active waitForStatus(ddbClient, tableName, "ACTIVE"); labController.logMessageToPage("Table created and active."); }
From source file:br.com.faccilitacorretor.middleware.dynamo.AmazonDynamoDBSample.java
License:Open Source License
public static void main(String[] args) throws Exception { init();//from w w w . ja va2s . c o m try { String tableName = "my-favorite-movies-table"; // Create table if it does not exist yet if (Tables.doesTableExist(dynamoDB, tableName)) { System.out.println("Table " + tableName + " is already ACTIVE"); } else { // Create a table with a primary hash key named 'name', which holds a string CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName) .withKeySchema(new KeySchemaElement().withAttributeName("name").withKeyType(KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition().withAttributeName("name") .withAttributeType(ScalarAttributeType.S)) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L)); TableDescription createdTableDescription = dynamoDB.createTable(createTableRequest) .getTableDescription(); System.out.println("Created Table: " + createdTableDescription); // Wait for it to become active System.out.println("Waiting for " + tableName + " to become ACTIVE..."); Tables.awaitTableToBecomeActive(dynamoDB, tableName); } // Describe our new table DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable(); System.out.println("Table Description: " + tableDescription); // Add an item Map<String, AttributeValue> item = newItem("Bill & Ted's Excellent Adventure", 1989, "****", "James", "Sara"); PutItemRequest putItemRequest = new PutItemRequest(tableName, item); PutItemResult putItemResult = dynamoDB.putItem(putItemRequest); System.out.println("Result: " + putItemResult); // Add another item item = newItem("Airplane", 1980, "*****", "James", "Billy Bob"); putItemRequest = new PutItemRequest(tableName, item); putItemResult = dynamoDB.putItem(putItemRequest); System.out.println("Result: " + putItemResult); // Scan items for movies with a year attribute greater than 1985 HashMap<String, Condition> scanFilter = new HashMap<String, Condition>(); Condition condition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString()) .withAttributeValueList(new AttributeValue().withN("1985")); scanFilter.put("year", condition); ScanRequest scanRequest = new ScanRequest(tableName).withScanFilter(scanFilter); ScanResult scanResult = dynamoDB.scan(scanRequest); System.out.println("Result: " + scanResult); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to AWS, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with AWS, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }