/** * PUT a single item to the table. * @param item item to put * @return the outcome. */ @Retries.OnceRaw private PutItemOutcome putItem(Item item) { LOG.debug("Putting item {}", item); return table.putItem(item); }
@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); }
@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); }
@Override public void write(final MarshalledEntry<? extends K, ? extends V> marshalledEntry) { // The CacheWriter should write the specified entry to the external storage. // // The PersistenceManager uses MarshalledEntry as the default format so that CacheWriters can efficiently store data coming // from a remote node, thus avoiding any additional transformation steps. // // Note that keys and values will be in the cache's native format, which means that if the cache is being used by a remoting protocol // such as HotRod or REST and compatibility mode has not been enabled, then they will be encoded in a byte[]. Loggers.DYNAMODB_LOG.trace("[DS0115] DynamoDB store: Writing {} cache entry {}", getCacheName(), marshalledEntry); Timer.Context timerCtx = timers.putTimer.time(); try { table.putItem(requestFactory.resolveItem( new InfinispanEntry<>( marshalledEntry.getKey(), marshalledEntry.getValue(), marshalledEntry.getMetadata()))); } catch (Exception e) { Loggers.DYNAMODB_LOG.error("[DS0117] {}: {}", e.getMessage(), e); throw new PersistenceException(e.getMessage(), e); } finally { timerCtx.stop(); } }
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()); } }
.withString("Message", "DynamoDB Thread 1 Reply 1 text") .withString("PostedBy", "User A"); table.putItem(item); .withString("Message", "DynamoDB Thread 1 Reply 2 text") .withString("PostedBy", "User B"); table.putItem(item); .withString("Message", "DynamoDB Thread 2 Reply 1 text") .withString("PostedBy", "User A"); table.putItem(item); .withString("Message", "DynamoDB Thread 2 Reply 2 text") .withString("PostedBy", "User A"); table.putItem(item);
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()); } }
.withString("Message", "DynamoDB Thread 1 Reply 1 text") .withString("PostedBy", "User A"); table.putItem(item); .withString("Message", "DynamoDB Thread 1 Reply 2 text") .withString("PostedBy", "User B"); table.putItem(item); .withString("Message", "DynamoDB Thread 2 Reply 1 text") .withString("PostedBy", "User A"); table.putItem(item); .withString("Message", "DynamoDB Thread 2 Reply 2 text") .withString("PostedBy", "User A"); 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 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(); }
.withStringSet( "Tags", new HashSet<String>( Arrays.asList("index", "primarykey", "table"))); table.putItem(item); .withStringSet( "Tags", new HashSet<String>( Arrays.asList("index", "primarykey", "rangekey"))); table.putItem(item); .withStringSet( "Tags", new HashSet<String>( Arrays.asList("largeobjects", "multipart upload"))); table.putItem(item);
.withStringSet( "Tags", new HashSet<String>( Arrays.asList("index", "primarykey", "table"))); table.putItem(item); .withStringSet( "Tags", new HashSet<String>( Arrays.asList("index", "primarykey", "rangekey"))); table.putItem(item); .withStringSet( "Tags", new HashSet<String>( Arrays.asList("largeobjects", "multipart upload"))); table.putItem(item);
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")); }
path.toString(), idempotent, () -> table.putItem(item)); } else { PrimaryKey key = pathToKey(path);
table.putItem(putItemSpec); System.out.println("PutItem succeeded: " + table.getItem("year", year, "title", title).toJSONPretty()); } catch (ConditionalCheckFailedException e) {
@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; }
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); }
PutItemOutcome putItemOutcome = table.putItem(item); putItemOutcome = table.putItem(item); .withString("ShipmentTrackingId", "176493"); putItemOutcome = table.putItem(item); .withString("ShipmentTrackingId", "859323"); putItemOutcome = table.putItem(item); .withString("ShipmentTrackingId", "756943"); putItemOutcome = table.putItem(item); .withString("ShipmentTrackingId", "645193"); putItemOutcome = table.putItem(item); putItemOutcome = table.putItem(item); putItemOutcome = table.putItem(item); putItemOutcome = table.putItem(item); putItemOutcome = table.putItem(item); assert putItemOutcome != null;