List of usage examples for com.amazonaws.services.dynamodbv2.document Table getDescription
public TableDescription getDescription()
From source file:CreateUserLoginTable.java
License:Open Source License
public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider()); DynamoDB dynamoDB = new DynamoDB(client); String tableName = "UserLogin"; try {//from ww w . j a v a 2 s. c o m System.out.println("Attempting to create table; please wait..."); Table table = dynamoDB.createTable(tableName, Arrays.asList(new KeySchemaElement("UserID", KeyType.HASH)), //Partition key Arrays.asList(new AttributeDefinition("UserID", ScalarAttributeType.N)), new ProvisionedThroughput(10L, 10L)); table.waitForActive(); System.out.println("Success. Table status: " + table.getDescription().getTableStatus()); } catch (Exception e) { System.err.println("Unable to create table: "); System.err.println(e.getMessage()); } }
From source file:CreateUserFavoritesTable.java
License:Open Source License
public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider()); DynamoDB dynamoDB = new DynamoDB(client); String tableName = "UserFavorites"; try {/* ww w . j a va 2 s . com*/ System.out.println("Attempting to create table; please wait..."); Table table = dynamoDB.createTable(tableName, Arrays.asList(new KeySchemaElement("UserID", KeyType.HASH)), //Partition key Arrays.asList(new AttributeDefinition("UserID", ScalarAttributeType.N)), new ProvisionedThroughput(10L, 10L)); table.waitForActive(); System.out.println("Success. Table status: " + table.getDescription().getTableStatus()); } catch (Exception e) { System.err.println("Unable to create table: "); System.err.println(e.getMessage()); } }
From source file:CreateUserInfoTable.java
License:Open Source License
public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider()); DynamoDB dynamoDB = new DynamoDB(client); String tableName = "UserInfo"; try {/*from ww w . ja va 2s . com*/ System.out.println("Attempting to create table; please wait..."); Table table = dynamoDB.createTable(tableName, Arrays.asList(new KeySchemaElement("UserID", KeyType.HASH)), //Partition key Arrays.asList(new AttributeDefinition("UserID", ScalarAttributeType.N)), new ProvisionedThroughput(10L, 10L)); table.waitForActive(); System.out.println("Success. Table status: " + table.getDescription().getTableStatus()); } catch (Exception e) { System.err.println("Unable to create table: "); System.err.println(e.getMessage()); } }
From source file:CreateUserRoutesTable.java
License:Open Source License
public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider()); DynamoDB dynamoDB = new DynamoDB(client); String tableName = "UserRoutes"; try {/* w ww . j a va 2 s. c o m*/ System.out.println("Attempting to create table; please wait..."); Table table = dynamoDB.createTable(tableName, Arrays.asList(new KeySchemaElement("UserID", KeyType.HASH)), //Partition key Arrays.asList(new AttributeDefinition("UserID", ScalarAttributeType.N)), new ProvisionedThroughput(10L, 10L)); table.waitForActive(); System.out.println("Success. Table status: " + table.getDescription().getTableStatus()); } catch (Exception e) { System.err.println("Unable to create table: "); System.err.println(e.getMessage()); } }
From source file:com.euclidespaim.dynamodb.CreateTableFunction.java
License:Open Source License
public static void main(String[] args) throws Exception { AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration( new AwsClientBuilder.EndpointConfiguration("https://dynamodb.us-east-1.amazonaws.com", "us-east-1")) .build();//from w w w . java2s . c o m DynamoDB dynamoDB = new DynamoDB(client); String tableName = "Movies"; try { System.out.println("Attempting to create table; please wait..."); Table table = dynamoDB.createTable(tableName, Arrays.asList(new KeySchemaElement("year", KeyType.HASH), // Partition // key new KeySchemaElement("title", KeyType.RANGE)), // Sort key Arrays.asList(new AttributeDefinition("year", ScalarAttributeType.N), new AttributeDefinition("title", ScalarAttributeType.S)), new ProvisionedThroughput(10L, 10L)); table.waitForActive(); System.out.println("Success. Table status: " + table.getDescription().getTableStatus()); } catch (Exception e) { System.err.println("Unable to create table: "); System.err.println(e.getMessage()); } }
From source file:com.intuit.tank.persistence.databases.AmazonDynamoDatabaseDocApi.java
License:Open Source License
private void addItemsToTable(String tableName, final BatchWriteItemRequest request) { boolean shouldRetry; int retries = 0; do {//from www.j av a 2s . c o m shouldRetry = false; try { BatchWriteItemResult result = dynamoDb.batchWriteItem(request); if (result != null) { try { List<ConsumedCapacity> consumedCapacity = result.getConsumedCapacity(); for (ConsumedCapacity cap : consumedCapacity) { logger.info(cap.getCapacityUnits()); } } catch (Exception e) { // ignore this } } } catch (AmazonServiceException e) { if (e instanceof ProvisionedThroughputExceededException) { try { DynamoDB db = new DynamoDB(dynamoDb); Table table = db.getTable(tableName); ProvisionedThroughputDescription oldThroughput = table.getDescription() .getProvisionedThroughput(); logger.info("ProvisionedThroughputExceeded throughput = " + oldThroughput); ProvisionedThroughput newThroughput = new ProvisionedThroughput() .withReadCapacityUnits( table.getDescription().getProvisionedThroughput().getReadCapacityUnits()) .withWriteCapacityUnits(getIncreasedThroughput( table.getDescription().getProvisionedThroughput().getReadCapacityUnits())); if (!oldThroughput.equals(newThroughput)) { logger.info("Updating throughput to " + newThroughput); table.updateTable(newThroughput); table.waitForActive(); } } catch (Exception e1) { logger.error("Error increasing capacity: " + e, e); } } int status = e.getStatusCode(); if (status == HttpStatus.SC_INTERNAL_SERVER_ERROR || status == HttpStatus.SC_SERVICE_UNAVAILABLE) { shouldRetry = true; long delay = (long) (Math.random() * (Math.pow(4, retries++) * 100L)); try { Thread.sleep(delay); } catch (InterruptedException iex) { logger.error("Caught InterruptedException exception", iex); } } else { logger.error("Error writing to DB: " + e.getMessage()); throw new RuntimeException(e); } } } while (shouldRetry && retries < MAX_NUMBER_OF_RETRIES); }