Refine search
if (String.class == getTypeOf(attrName)) { String b64 = getString(attrName); Base64.decode(b64); } else { Set<String> b64s = getStringSet(attrName); for (String b64: b64s) Base64.decode(b64); if (String.class == getTypeOf(attrName)) { String b64 = getString(attrName); byte[] bytes = Base64.decode(b64); withBinary(attrName, bytes); } else { Set<String> b64s = getStringSet(attrName); Set<byte[]> binarySet = new LinkedHashSet<byte[]>(b64s.size()); for (String b64: b64s) binarySet.add(Base64.decode(b64)); withBinarySet(attrName, binarySet);
tableWriteItems.addItemToPut(new Item().withKeyComponent(hashKeyName, hashKeyValue) .withJSON(jsonDocument, IOUtils.toString(baos.toByteArray(), charset))); } else { tableWriteItems.addItemToPut(new Item().withKeyComponent(hashKeyName, hashKeyValue) .withKeyComponent(rangeKeyName, rangeKeyValue) .withJSON(jsonDocument, IOUtils.toString(baos.toByteArray(), charset))); BatchWriteItemOutcome outcome = dynamoDB.batchWriteItem(tableWriteItems);
return withNull(attrName); if (val instanceof String) return withString(attrName, (String)val); if (val instanceof Number) return withNumber(attrName, (Number)val); if (val instanceof byte[]) return withBinary(attrName, (byte[])val); if (val instanceof ByteBuffer) return withBinary(attrName, (ByteBuffer)val); if (val instanceof Boolean) return withBoolean(attrName, (Boolean)val); if (val instanceof List) return withList(attrName, (List<?>)val); if (val instanceof Map) { @SuppressWarnings("unchecked") Map<String,?> map = (Map<String,?>)val; return withMap(attrName, map); @SuppressWarnings("unchecked") Set<String> ss = (Set<String>)val; return withStringSet(attrName, ss); @SuppressWarnings("unchecked") Set<String> ss = (Set<String>)val; return withStringSet(attrName, ss); return withNumberSet(attrName, ns); return withBinarySet(attrName, bs);
/** * Convenient factory method - instantiates an <code>Item</code> from the * given map. * * @param attributes * simple Java types; not the DyanmoDB types */ public static Item fromMap(Map<String, Object> attributes) { if (attributes == null) return null; Item item = new Item(); for (Map.Entry<String, Object> e : attributes.entrySet()) item.with(e.getKey(), e.getValue()); return item; }
/** * Returns the value of the specified attribute in the current item as a * <code>double</code>. * * @see #isNull(String) #isNull(String) to check if the attribute value is * null. * @see #isPresent(String) #isPresent(String) to check if the attribute * value is present. * * @throws NumberFormatException * if the attribute value is null or not a valid representation * of a {@code BigDecimal}. */ public double getDouble(String attrName) { BigDecimal bd = getNumber(attrName); if (bd == null) throw new NumberFormatException ("value of " + attrName + " is null"); return bd.doubleValue(); }
/** * Returns the value of the specified attribute in the current item as an * <code>int</code>. * * @see #isNull(String) #isNull(String) to check if the attribute value is * null. * @see #isPresent(String) #isPresent(String) to check if the attribute * value is present. * * @throws NumberFormatException * if the attribute value is null or not a valid representation * of a {@code BigDecimal}. */ public int getInt(String attrName) { BigDecimal bd = getNumber(attrName); if (bd == null) throw new NumberFormatException ("value of " + attrName + " is null"); return bd.intValue(); }
/** * Returns the value of the specified attribute in the current item as an * <code>long</code>. * * @see #isNull(String) #isNull(String) to check if the attribute value is * null. * @see #isPresent(String) #isPresent(String) to check if the attribute * value is present. * * @throws NumberFormatException * if the attribute value is null or not a valid representation * of a {@code BigDecimal}. */ public long getLong(String attrName) { BigDecimal bd = getNumber(attrName); if (bd == null) throw new NumberFormatException ("value of " + attrName + " is null"); return bd.longValue(); }
/** * Returns the value of the specified attribute in the current item as an * <code>BigInteger</code>; or null if the attribute doesn't exist. * * @see #isNull(String) #isNull(String) to check if the attribute value is * null. * @see #isPresent(String) #isPresent(String) to check if the attribute * value is present. * * @throws NumberFormatException * if the attribute value is null or not a valid representation * of a {@code BigDecimal}. */ public BigInteger getBigInteger(String attrName) { BigDecimal bd = getNumber(attrName); return bd == null ? null : bd.toBigInteger(); }
/** * Returns the value of the specified attribute in the current item as a * <code>float</code>. * * @see #isNull(String) #isNull(String) to check if the attribute value is * null. * @see #isPresent(String) #isPresent(String) to check if the attribute * value is present. * * @throws NumberFormatException * if the attribute value is null or not a valid representation * of a {@code BigDecimal}. */ public float getFloat(String attrName) { BigDecimal bd = getNumber(attrName); if (bd == null) throw new NumberFormatException ("value of " + attrName + " is null"); return bd.floatValue(); }
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); }
/** * Returns the value of the specified attribute in the current item as a * <code>short</code>. * * @see #isNull(String) #isNull(String) to check if the attribute value is * null. * @see #isPresent(String) #isPresent(String) to check if the attribute * value is present. * * @throws NumberFormatException * if the attribute value is null or not a valid representation * of a {@code BigDecimal}. */ public short getShort(String attrName) { BigDecimal bd = getNumber(attrName); if (bd == null) throw new NumberFormatException ("value of " + attrName + " is null"); return bd.shortValue(); }
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(); } } }
DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable("Movies"); infoMap.put("plot", "Nothing happens at all."); infoMap.put("rating", 0.0); Item item = new Item() .withPrimaryKey(new PrimaryKey("year", year, "title", title)) .withMap("info", infoMap); 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) 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(); }
DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable("Movies"); .withValueMap(valueMap); ItemCollection<QueryOutcome> items = table.query(querySpec); while (iterator.hasNext()) { item = iterator.next(); System.out.println(item.getNumber("year") + ": " + item.getString("title")); .withValueMap(valueMap); items = table.query(querySpec); iterator = items.iterator(); while (iterator.hasNext()) { item = iterator.next(); System.out.println(item.toString());
@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); }
.withItemsToPut(new Item() .withPrimaryKey("Name", "Amazon RDS") .withNumber("Threads", 0)); .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")))) .withHashAndRangeKeysToDelete("ForumName","Subject", "Amazon S3", "S3 Thread 100"); BatchWriteItemOutcome outcome = dynamoDB.batchWriteItem(forumTableWriteItems, threadTableWriteItems); } else { System.out.println("Retrieving the unprocessed items"); outcome = dynamoDB.batchWriteItemUnprocessed(unprocessedItems);
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"); }
/** * The version marker has a primary key whose PARENT is {@code name}; * this MUST NOT be a value which represents an absolute path. * @param name name of the version marker * @param version version number * @param timestamp creation timestamp * @return an item representing a version marker. */ static Item createVersionMarker(String name, int version, long timestamp) { return new Item().withPrimaryKey(createVersionMarkerPrimaryKey(name)) .withInt(TABLE_VERSION, version) .withLong(TABLE_CREATED, timestamp); }
/** * Converts a {@link DDBPathMetadata} to a DynamoDB item. * * Can ignore {@code IS_AUTHORITATIVE} flag if {@code ignoreIsAuthFlag} is * true. * * @param meta {@link DDBPathMetadata} to convert * @param ignoreIsAuthFlag if true, ignore the authoritative flag on item * @return {@code meta} converted to DynamoDB item */ static Item pathMetadataToItem(DDBPathMetadata meta, boolean ignoreIsAuthFlag) { Preconditions.checkNotNull(meta); final FileStatus status = meta.getFileStatus(); final Item item = new Item().withPrimaryKey(pathToKey(status.getPath())); if (status.isDirectory()) { item.withBoolean(IS_DIR, true); if (!ignoreIsAuthFlag) { item.withBoolean(IS_AUTHORITATIVE, meta.isAuthoritativeDir()); } } else { item.withLong(FILE_LENGTH, status.getLen()) .withLong(MOD_TIME, status.getModificationTime()) .withLong(BLOCK_SIZE, status.getBlockSize()); } item.withBoolean(IS_DELETED, meta.isDeleted()); return item; }