protected synchronized DynamoDB getDynamoDB() { if ( dynamoDB == null ) dynamoDB = new DynamoDB(client); return dynamoDB; }
protected synchronized DynamoDB getDynamoDB() { if ( dynamoDB == null ) dynamoDB = new DynamoDB(client); return dynamoDB; }
public DynamoDbMetadataStore(AmazonDynamoDBAsync dynamoDB, String tableName) { Assert.notNull(dynamoDB, "'dynamoDB' must not be null."); Assert.hasText(tableName, "'tableName' must not be empty."); this.dynamoDB = dynamoDB; this.table = new DynamoDB(this.dynamoDB) .getTable(tableName); }
public DynamoDbMetadataStore(AmazonDynamoDBAsync dynamoDB, String tableName) { Assert.notNull(dynamoDB, "'dynamoDB' must not be null."); Assert.hasText(tableName, "'tableName' must not be empty."); this.dynamoDB = dynamoDB; this.table = new DynamoDB(this.dynamoDB) .getTable(tableName); }
static DynamoDB dynamoDB = new DynamoDB(new AmazonDynamoDBClient(new ProfileCredentialsProvider()));
public static DynamoDB getDynamoDBConnection() throws ApplicationSpecificException { try { return new DynamoDB(new AmazonDynamoDBClient( new ProfileCredentialsProvider())); } catch(AmazonServiceException ase) { slf4jLogger.error(ase.getMessage()); slf4jLogger.error(ase.getStackTrace()); slf4jLogger.error(ase); throw new ApplicationSpecificException("some good message", ase); } }
public static void deleteTable(AmazonDynamoDB client, String tableName) throws InterruptedException { new DynamoDB(client).getTable(tableName).delete(); }
public static void deleteTable(AmazonDynamoDB client, String tableName) throws InterruptedException { new DynamoDB(client).getTable(tableName).delete(); }
public static void main(String[] args) { AmazonDynamoDBClient client = new AmazonDynamoDBClient(); client.setEndpoint("http://localhost:8000"); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable("Movies"); table.delete(); System.out.println("Table is being deleted"); } }
DynamoDB dynamoDB = new DynamoDB( new AmazonDynamoDBClient(new ProfileCredentialsProvider())); Table table = dynamoDB.getTable("TableName"); QuerySpec spec = new QuerySpec() .withKeyConditionExpression("Id = :v_id") .withValueMap(new ValueMap() .withString(":v_id", "TheId")); ItemCollection<QueryOutcome> items = table.query(spec); Iterator<Item> iterator = items.iterator(); Item item = null; while (iterator.hasNext()) { item = iterator.next(); System.out.println(item.toJSONPretty()); }
/** * Constructor. * @param accessKeyId * @param secretAccessKey * @param region */ public DynamoDBBackendImpl(String accessKeyId, String secretAccessKey, String region) { BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKeyId, secretAccessKey); AmazonDynamoDBClient client = new AmazonDynamoDBClient(awsCredentials); client.setRegion(Region.getRegion(Regions.fromName(region))); dynamoDB = new DynamoDB(client); } // DynamoDBBackendImpl
public static void main(String[] args) { AmazonDynamoDBClient client = new AmazonDynamoDBClient(); client.setEndpoint("http://localhost:8000"); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable("Movies"); int year = 2015; String title = "The Big New Movie"; try { table.putItem(new Item() .withPrimaryKey("year", year, "title", title) .withJSON("info", "{\"plot\" : \"Something happens.\"}")); System.out.println("PutItem succeeded: " + table.getItem("year", year, "title", title).toJSONPretty()); } catch (Exception e) { System.out.println("PutItem failed"); e.printStackTrace(); } } }
public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient(); client.setEndpoint("http://localhost:8000"); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable("Movies"); JsonParser parser = new JsonFactory() .createParser(new File("moviedata.json")); Iterator<JsonNode> iter = getRootNode(parser).iterator(); ObjectNode currentNode; while (iter.hasNext()) { currentNode = (ObjectNode) iter.next(); int year = getYear(currentNode); String title = getTitle(currentNode); System.out.println("Adding movie: " + year + " " + title); table.putItem(new Item() .withPrimaryKey("year", year, "title", title) .withJSON("info", getInfo(currentNode))); } parser.close(); }
public static void main(String[] args) { AmazonDynamoDBClient client = new AmazonDynamoDBClient(); client.setEndpoint("http://localhost:8000"); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable("Movies"); // Conditional delete (will fail) DeleteItemSpec deleteItemSpec = new DeleteItemSpec() .withPrimaryKey(new PrimaryKey("year", 2015, "title", "The Big New Movie")) .withConditionExpression("info.rating <= :val") .withValueMap(new ValueMap() .withNumber(":val", 5.0)); System.out.println("Attempting a conditional delete..."); try { table.deleteItem(deleteItemSpec); System.out.println("DeleteItem succeeded"); } catch (Exception e) { e.printStackTrace(); System.out.println("DeleteItem failed"); } }
public static void main(String[] args) { AmazonDynamoDBClient client = new AmazonDynamoDBClient(); client.setEndpoint("http://localhost:8000"); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable("Movies"); int year = 2015; String title = "The Big New Movie"; UpdateItemSpec updateItemSpec = new UpdateItemSpec() .withPrimaryKey("year", year, "title", title) .withUpdateExpression("set info.rating = :r, info.plot=:p, info.actors=:a") .withValueMap(new ValueMap() .withNumber(":r", 5.5) .withString(":p", "Everything happens all at once.") .withList(":a", Arrays.asList("Larry","Moe","Curly"))); System.out.println("Updating the item..."); try { table.updateItem(updateItemSpec); System.out.println("UpdateItem succeeded: " + table.getItem("year", year, "title", title).toJSONPretty()); } catch (Exception e) { System.out.println("UpdateItem failed"); e.printStackTrace(); } }
public static void main(String[] args) { AmazonDynamoDBClient client = new AmazonDynamoDBClient(); client.setEndpoint("http://localhost:8000"); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable("Movies"); int year = 2015; String title = "The Big New Movie"; UpdateItemSpec updateItemSpec = new UpdateItemSpec() .withPrimaryKey("year", year, "title", title) .withUpdateExpression("set info.rating = info.rating + :val") .withValueMap(new ValueMap() .withNumber(":val", 1)); System.out.println("Incrementing an atomic counter..."); try { table.updateItem(updateItemSpec); System.out.println("UpdateItem succeeded: " + table.getItem("year", year, "title", title).toJSONPretty()); } catch (Exception e) { System.out.println("UpdateItem failed"); e.printStackTrace(); } }
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); } } }
public static void main(String[] args) { AmazonDynamoDBClient client = new AmazonDynamoDBClient(); client.setEndpoint("http://localhost:8000"); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable("Movies"); ScanSpec scanSpec = new ScanSpec() .withProjectionExpression("#yr, title, info.rating") .withFilterExpression("#yr between :start_yr and :end_yr") .withNameMap(new NameMap().with("#yr", "year")) .withValueMap(new ValueMap().withNumber(":start_yr", 1950).withNumber(":end_yr", 1959)); ItemCollection<ScanOutcome> items = table.scan(scanSpec); Iterator<Item> iter = items.iterator(); while (iter.hasNext()) { Item item = iter.next(); System.out.println(item.toString()); } } }
public static TableDescription createTable(AmazonDynamoDB client, String tableName) throws InterruptedException { CreateTableRequest tableReq = new CreateTableRequest().withTableName(tableName) .withKeySchema(new KeySchemaElement("Id", KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition("Id", ScalarAttributeType.N)) .withProvisionedThroughput(new ProvisionedThroughput(10L, 10L)) .withStreamSpecification(new StreamSpecification().withStreamEnabled(true).withStreamViewType(StreamViewType.NEW_AND_OLD_IMAGES)); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.createTable(tableReq); return table.waitForActive(); }
public static TableDescription createTable(AmazonDynamoDB client, String tableName) throws InterruptedException { CreateTableRequest tableReq = new CreateTableRequest().withTableName(tableName) .withKeySchema(new KeySchemaElement("Id", KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition("Id", ScalarAttributeType.N)) .withProvisionedThroughput(new ProvisionedThroughput(10L, 10L)) .withStreamSpecification(new StreamSpecification().withStreamEnabled(true).withStreamViewType(StreamViewType.NEW_AND_OLD_IMAGES)); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.createTable(tableReq); return table.waitForActive(); }