return withNull(attrName); if (val instanceof String) return withString(attrName, (String)val); if (val instanceof Number) return withNumber(attrName, (Number)val);
public static void putItem( String issueId, String title, String description, String createDate, String lastUpdateDate, String dueDate, Integer priority, String status) { Table table = dynamoDB.getTable(tableName); Item item = new Item() .withPrimaryKey("IssueId", issueId) .withString("Title", title) .withString("Description", description) .withString("CreateDate", createDate) .withString("LastUpdateDate", lastUpdateDate) .withString("DueDate", dueDate) .withNumber("Priority", priority) .withString("Status", status); table.putItem(item); }
private static void uploadProduct(String tableName, int productIndex) { Table table = dynamoDB.getTable(tableName); try { System.out.println("Processing record #" + productIndex); Item item = new Item() .withPrimaryKey("Id", productIndex) .withString("Title", "Book " + productIndex + " Title") .withString("ISBN", "111-1111111111") .withStringSet( "Authors", new HashSet<String>(Arrays.asList("Author1"))) .withNumber("Price", 2) .withString("Dimensions", "8.5 x 11.0 x 0.5") .withNumber("PageCount", 500) .withBoolean("InPublication", true) .withString("ProductCategory", "Book"); table.putItem(item); } catch (Exception e) { System.err.println("Failed to create item " + productIndex + " in " + tableName); System.err.println(e.getMessage()); } }
public static void createItem(String threadId, String replyDateTime) throws IOException { Table table = dynamoDB.getTable(tableName); // Craft a long message String messageInput = "Long message to be compressed in a lengthy forum reply"; // Compress the long message ByteBuffer compressedMessage = compressString(messageInput.toString()); table.putItem(new Item() .withPrimaryKey("Id", threadId) .withString("ReplyDateTime", replyDateTime) .withString("Message", "Long message follows") .withBinary("ExtendedMessage", compressedMessage) .withString("PostedBy", "User A")); }
.withString("Title", "Book 120 Title") .withString("ISBN", "120-1111111111") .withStringSet( "Authors", new HashSet<String>(Arrays.asList("Author12", "Author22"))) .withNumber("Price", 20) .withString("Dimensions", "8.5x11.0x.75") .withNumber("PageCount", 500) .withBoolean("InPublication", false) .withString("ProductCategory", "Book"); table.putItem(item); .withString("Title", "Book 121 Title") .withString("ISBN", "121-1111111111") .withStringSet( "Authors", new HashSet<String>(Arrays.asList("Author21", "Author 22"))) .withNumber("Price", 20) .withString("Dimensions", "8.5x11.0x.75") .withNumber("PageCount", 500) .withBoolean("InPublication", true) .withString("ProductCategory", "Book"); table.putItem(item);
.withString("ReplyDateTime", (dateFormatter.format(date3))) .withString("Message", "DynamoDB Thread 1 Reply 1 text") .withString("PostedBy", "User A"); table.putItem(item); .withString("ReplyDateTime", dateFormatter.format(date2)) .withString("Message", "DynamoDB Thread 1 Reply 2 text") .withString("PostedBy", "User B"); table.putItem(item); .withString("ReplyDateTime", dateFormatter.format(date1)) .withString("Message", "DynamoDB Thread 2 Reply 1 text") .withString("PostedBy", "User A"); table.putItem(item); .withString("ReplyDateTime", dateFormatter.format(date0)) .withString("Message", "DynamoDB Thread 2 Reply 2 text") .withString("PostedBy", "User A"); table.putItem(item);
.withString("Title", "Book 101 Title") .withString("ISBN", "111-1111111111") .withStringSet("Authors", new HashSet<String>(Arrays.asList("Author1"))) .withNumber("Price", 2) .withString("Dimensions", "8.5 x 11.0 x 0.5") .withNumber("PageCount", 500) .withBoolean("InPublication", true) .withString("ProductCategory", "Book"); table.putItem(item); .withString("Title", "Book 102 Title") .withString("ISBN", "222-2222222222") .withStringSet("Authors", new HashSet<String>( Arrays.asList("Author1", "Author2"))) .withNumber("Price", 20) .withString("Dimensions", "8.5 x 11.0 x 0.8") .withNumber("PageCount", 600) .withBoolean("InPublication", true) .withString("ProductCategory", "Book"); table.putItem(item); .withString("Title", "Book 103 Title") .withString("ISBN", "333-3333333333") .withStringSet( "Authors", new HashSet<String>( Arrays.asList("Author1", "Author2"))) .withString("Dimensions", "8.5 x 11.0 x 1.5") .withNumber("PageCount", 600)
.withString("ReplyDateTime", (dateFormatter.format(date3))) .withString("Message", "DynamoDB Thread 1 Reply 1 text") .withString("PostedBy", "User A"); table.putItem(item); .withString("ReplyDateTime", dateFormatter.format(date2)) .withString("Message", "DynamoDB Thread 1 Reply 2 text") .withString("PostedBy", "User B"); table.putItem(item); .withString("ReplyDateTime", dateFormatter.format(date1)) .withString("Message", "DynamoDB Thread 2 Reply 1 text") .withString("PostedBy", "User A"); table.putItem(item); .withString("ReplyDateTime", dateFormatter.format(date0)) .withString("Message", "DynamoDB Thread 2 Reply 2 text") .withString("PostedBy", "User A"); table.putItem(item);
.withString("Title", "Book 101 Title") .withString("ISBN", "111-1111111111") .withStringSet("Authors", new HashSet<String>( Arrays.asList("Author1"))) .withNumber("Price", 2) .withString("Dimensions", "8.5 x 11.0 x 0.5") .withNumber("PageCount", 500) .withBoolean("InPublication", true) .withString("ProductCategory", "Book"); table.putItem(item); .withString("Title", "Book 102 Title") .withString("ISBN", "222-2222222222") .withStringSet( "Authors", new HashSet<String>( Arrays.asList("Author1", "Author2"))) .withNumber("Price", 20) .withString("Dimensions", "8.5 x 11.0 x 0.8") .withNumber("PageCount", 600) .withBoolean("InPublication", true) .withString("ProductCategory", "Book"); table.putItem(item); .withString("Title", "Book 103 Title") .withString("ISBN", "333-3333333333") .withStringSet( "Authors", new HashSet<String>( Arrays.asList("Author1", "Author2"))) .withString("Dimensions", "8.5 x 11.0 x 1.5") .withNumber("PageCount", 600)
@Override public void put(String key, String value) { Assert.hasText(key, "'key' must not be empty."); Assert.hasText(value, "'value' must not be empty."); awaitForActive(); Item item = new Item() .withPrimaryKey(KEY, key) .withString(VALUE, value); if (this.timeToLive != null && this.timeToLive > 0) { item = item.withLong(TTL, (System.currentTimeMillis() + this.timeToLive) / 1000); } this.table.putItem(item); }
.withString("Subject", "DynamoDB Thread 1") .withString("Message", "DynamoDB thread 1 message") .withString("LastPostedBy", "User A") .withString("LastPostedDateTime", dateFormatter.format(date2)) .withNumber("Views", 0) .withNumber("Replies", 0) .withString("Subject", "DynamoDB Thread 2") .withString("Message", "DynamoDB thread 2 message") .withString("LastPostedBy", "User A") .withString("LastPostedDateTime", dateFormatter.format(date3)) .withNumber("Views", 0) .withNumber("Replies", 0) .withString("Subject", "S3 Thread 1") .withString("Message", "S3 Thread 3 message") .withString("LastPostedBy", "User A") .withString("LastPostedDateTime", dateFormatter.format(date1)) .withNumber("Views", 0) .withNumber("Replies", 0)
@Override public void put(String key, String value) { Assert.hasText(key, "'key' must not be empty."); Assert.hasText(value, "'value' must not be empty."); awaitForActive(); Item item = new Item() .withPrimaryKey(KEY, key) .withString(VALUE, value); if (this.timeToLive != null && this.timeToLive > 0) { item = item.withLong(TTL, (System.currentTimeMillis() + this.timeToLive) / 1000); } this.table.putItem(item); }
.withString("Subject", "DynamoDB Thread 1") .withString("Message", "DynamoDB thread 1 message") .withString("LastPostedBy", "User A") .withString("LastPostedDateTime", dateFormatter.format(date2)) .withNumber("Views", 0) .withNumber("Replies", 0) .withString("Subject", "DynamoDB Thread 2") .withString("Message", "DynamoDB thread 2 message") .withString("LastPostedBy", "User A") .withString("LastPostedDateTime", dateFormatter.format(date3)) .withNumber("Views", 0) .withNumber("Replies", 0) .withString("Subject", "S3 Thread 1") .withString("Message", "S3 Thread 3 message") .withString("LastPostedBy", "User A") .withString("LastPostedDateTime", dateFormatter.format(date1)) .withNumber("Views", 0) .withNumber("Replies", 0)
@Override public boolean write(Job job) { Timer.Context context = writeTimer.time(); ObjectMapper objectMapper = new ObjectMapper(); Table table = dynamoDB.getTable(tableName); try { String jobJSON = objectMapper.writeValueAsString(job); Item item = new Item() .withPrimaryKey("JobKey", jobIdKey(job)) .withString("UniqueId", job.getUniqueID()) .withString("JobHandle", job.getJobHandle()) .withNumber("When", job.getTimeToRun()) .withString("Priority", job.getPriority().toString()) .withString("JobQueue", job.getFunctionName()) .withString("JSON", jobJSON); table.putItem(item); return true; } catch (JsonProcessingException e) { e.printStackTrace(); } finally { context.stop(); } return false; }
return withNull(attrName); if (val instanceof String) return withString(attrName, (String)val); if (val instanceof Number) return withNumber(attrName, (Number)val);
.withNumber("IsOpen", 1) .withNumber("OrderCreationDate", 20130101) .withString("ProductCategory", "Book") .withString("ProductName", "The Great Outdoors") .withString("OrderStatus", "PACKING ITEMS"); .withNumber("IsOpen", 1) .withNumber("OrderCreationDate", 20130221) .withString("ProductCategory", "Bike") .withString("ProductName", "Super Mountain") .withString("OrderStatus", "ORDER RECEIVED"); .withString("ProductCategory", "Music") .withString("ProductName", "A Quiet Interlude") .withString("OrderStatus", "IN TRANSIT") .withString("ShipmentTrackingId", "176493"); .withString("ProductCategory", "Movie") .withString("ProductName", "Calm Before The Storm") .withString("OrderStatus", "SHIPPING DELAY") .withString("ShipmentTrackingId", "859323"); .withString("ProductCategory", "Music") .withString("ProductName", "E-Z Listening") .withString("OrderStatus", "DELIVERED") .withString("ShipmentTrackingId", "756943"); .withString("ProductCategory", "Music") .withString("ProductName", "Symphony 9")
.withItemsToPut(new Item() .withPrimaryKey("ForumName","Amazon RDS","Subject","Amazon RDS Thread 1") .withString("Message", "ElasticCache Thread 1 message") .withStringSet("Tags", new HashSet<String>( Arrays.asList("cache", "in-memory"))))
private static void loadSampleForums(String tableName) { Table table = dynamoDB.getTable(tableName); try { System.out.println("Adding data to " + tableName); Item item = new Item().withPrimaryKey("Name", "Amazon DynamoDB") .withString("Category", "Amazon Web Services") .withNumber("Threads", 2).withNumber("Messages", 4) .withNumber("Views", 1000); table.putItem(item); item = new Item().withPrimaryKey("Name", "Amazon S3") .withString("Category", "Amazon Web Services") .withNumber("Threads", 0); table.putItem(item); } catch (Exception e) { System.err.println("Failed to create item in " + tableName); System.err.println(e.getMessage()); } }
private static void loadSampleForums(String tableName) { Table table = dynamoDB.getTable(tableName); try { System.out.println("Adding data to " + tableName); Item item = new Item().withPrimaryKey("Name", "Amazon DynamoDB") .withString("Category", "Amazon Web Services") .withNumber("Threads", 2) .withNumber("Messages", 4) .withNumber("Views", 1000); table.putItem(item); item = new Item().withPrimaryKey("Name", "Amazon S3") .withString("Category", "Amazon Web Services") .withNumber("Threads", 0); table.putItem(item); } catch (Exception e) { System.err.println("Failed to create item in " + tableName); System.err.println(e.getMessage()); } }