/** * Issue the query to get the version marker, with throttling for overloaded * DDB tables. * @param versionMarkerKey key to look up * @return the marker * @throws IOException failure */ @Retries.RetryTranslated private Item queryVersionMarker(final PrimaryKey versionMarkerKey) throws IOException { return readOp.retry("getVersionMarkerItem", VERSION_MARKER, true, () -> table.getItem(versionMarkerKey)); }
private static void retrieveItem() { Table table = dynamoDB.getTable(tableName); try { Item item = table.getItem("Id", 120, "Id, ISBN, Title, Authors", null); System.out.println("Printing item after retrieving it...."); System.out.println(item.toJSONPretty()); } catch (Exception e) { System.err.println("GetItem failed."); System.err.println(e.getMessage()); } }
private static void getBook(int id, String tableName) { Table table = dynamoDB.getTable(tableName); Item item = table.getItem("Id", // attribute name id, // attribute value "Id, ISBN, Title, Authors", // projection expression null); // name map - don't need this System.out.println("GetItem: printing results..."); System.out.println(item.toJSONPretty()); }
@Override public String get(String key) { Assert.hasText(key, "'key' must not be empty."); awaitForActive(); Item item = this.table.getItem(KEY, key); return getValueIfAny(item); }
@Override public String get(String key) { Assert.hasText(key, "'key' must not be empty."); awaitForActive(); Item item = this.table.getItem(KEY, key); return getValueIfAny(item); }
@Override public boolean contains(final Object key) { // This method will be invoked by the PersistenceManager to determine if the loader contains the specified key. // The implementation should be as fast as possible, e.g. it should strive to transfer the least amount of data possible // from the external storage to perform the check. Also, if possible, make sure the field is indexed on the external storage // so that its existence can be determined as quickly as possible. // // Note that keys 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("[DS0106] DynamoDB store: Checking {} cache key {}", getCacheName(), key); Timer.Context timerCtx = timers.getTimer.time(); try { return table.getItem(requestFactory.resolveGetItemSpec(key)) != null; } catch (Exception e) { Loggers.DYNAMODB_LOG.error("[DS0107] {}: {}", e.getMessage(), e); throw new PersistenceException(e.getMessage(), e); } finally { timerCtx.stop(); } }
@Override public Job findJob(String functionName, String uniqueID) { Table table = dynamoDB.getTable(tableName); Item item = table.getItem("JobKey", jobIdKey(functionName, uniqueID)); return jobFromItem(item); }
/** * Get a consistent view of an item. * @param path path to look up in the database * @param path entry * @return the result * @throws IOException failure */ @Retries.RetryTranslated private Item getConsistentItem(final Path path) throws IOException { PrimaryKey key = pathToKey(path); final GetItemSpec spec = new GetItemSpec() .withPrimaryKey(key) .withConsistentRead(true); // strictly consistent read return readOp.retry("get", path.toString(), true, () -> table.getItem(spec)); }
item = table.getItem(requestFactory.resolveGetItemSpec(key));
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) { 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 retrieveItem(String threadId, String replyDateTime) throws IOException { Table table = dynamoDB.getTable(tableName); GetItemSpec spec = new GetItemSpec() .withPrimaryKey("Id", threadId, "ReplyDateTime", replyDateTime) .withConsistentRead(true); Item item = table.getItem(spec); // Uncompress the reply message and print String uncompressed = uncompressString(ByteBuffer.wrap(item.getBinary("ExtendedMessage"))); System.out.println("Reply message:\n" + " Id: " + item.getString("Id") + "\n" + " ReplyDateTime: " + item.getString("ReplyDateTime") + "\n" + " PostedBy: " + item.getString("PostedBy") + "\n" + " Message: " + item.getString("Message") + "\n" + " ExtendedMessage (uncompressed): " + uncompressed + "\n"); }
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(); } }
try { table.putItem(putItemSpec); System.out.println("PutItem succeeded: " + table.getItem("year", year, "title", title).toJSONPretty()); } catch (ConditionalCheckFailedException e) { e.printStackTrace(System.err);
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"; // Conditional update (will fail) UpdateItemSpec updateItemSpec = new UpdateItemSpec() .withPrimaryKey(new PrimaryKey("year", 2015, "title", "The Big New Movie")) .withUpdateExpression("remove info.actors[0]") .withConditionExpression("size(info.actors) > :num") .withValueMap(new ValueMap().withNumber(":num", 3)); System.out.println("Attempting a conditional update..."); try { table.updateItem(updateItemSpec); System.out.println("UpdateItem succeeded: " + table.getItem("year", year, "title", title).toJSONPretty()); } catch (ConditionalCheckFailedException e) { e.printStackTrace(); System.out.println("UpdateItem failed"); } } }