/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getItem() != null) sb.append("Item: ").append(getItem()).append(","); if (getConsumedCapacity() != null) sb.append("ConsumedCapacity: ").append(getConsumedCapacity()); sb.append("}"); return sb.toString(); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof GetItemResult == false) return false; GetItemResult other = (GetItemResult) obj; if (other.getItem() == null ^ this.getItem() == null) return false; if (other.getItem() != null && other.getItem().equals(this.getItem()) == false) return false; if (other.getConsumedCapacity() == null ^ this.getConsumedCapacity() == null) return false; if (other.getConsumedCapacity() != null && other.getConsumedCapacity().equals(this.getConsumedCapacity()) == false) return false; return true; }
/** * Returns all the returned attributes as an {@link Item}; or null if the * item doesn't exist. */ public Item getItem() { Map<String, Object> attributes = InternalUtils.toSimpleMapValue(result.getItem()); Item item = Item.fromMap(attributes); return item; }
@Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("readkey: " + key + " from table: " + table); } GetItemRequest req = new GetItemRequest(table, createPrimaryKey(key)); req.setAttributesToGet(fields); req.setConsistentRead(consistentRead); GetItemResult res; try { res = dynamoDB.getItem(req); } catch (AmazonServiceException ex) { LOGGER.error(ex); return Status.ERROR; } catch (AmazonClientException ex) { LOGGER.error(ex); return CLIENT_ERROR; } if (null != res.getItem()) { result.putAll(extractResult(res.getItem())); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Result: " + res.toString()); } } return Status.OK; }
@Override public <T extends Object> T load(T keyObject, DynamoDBMapperConfig config) { @SuppressWarnings("unchecked") Class<T> clazz = (Class<T>) keyObject.getClass(); config = mergeConfig(config); final DynamoDBMapperTableModel<T> model = getTableModel(clazz, config); String tableName = getTableName(clazz, keyObject, config); GetItemRequest rq = new GetItemRequest() .withRequestMetricCollector(config.getRequestMetricCollector()); Map<String, AttributeValue> key = model.convertKey(keyObject); rq.setKey(key); rq.setTableName(tableName); rq.setConsistentRead(config.getConsistentReads() == ConsistentReads.CONSISTENT); GetItemResult item = db.getItem(applyUserAgent(rq)); Map<String, AttributeValue> itemAttributes = item.getItem(); if ( itemAttributes == null ) { return null; } T object = privateMarshallIntoObject( toParameters(itemAttributes, clazz, tableName, config)); return object; }
/** * Returns a string representation of this object; useful for testing and * debugging. * * @return A string representation of this object. * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getItem() != null) sb.append("Item: " + getItem() + ","); if (getConsumedCapacity() != null) sb.append("ConsumedCapacity: " + getConsumedCapacity()); sb.append("}"); return sb.toString(); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof GetItemResult == false) return false; GetItemResult other = (GetItemResult) obj; if (other.getItem() == null ^ this.getItem() == null) return false; if (other.getItem() != null && other.getItem().equals(this.getItem()) == false) return false; if (other.getConsumedCapacity() == null ^ this.getConsumedCapacity() == null) return false; if (other.getConsumedCapacity() != null && other.getConsumedCapacity().equals(this.getConsumedCapacity()) == false) return false; return true; } }
@Override public CompletableFuture<User> getUser(RequestContext context, Object userId) { return CompletableFuture.supplyAsync(() -> { GetItemResult item = dynamoDBClient.getItem("users", ImmutableMap.of( "project", new AttributeValue(context.project), "id", new AttributeValue(userId.toString()) )); Map<String, AttributeValue> attrs = item.getItem().get("properties").getM(); ObjectNode obj = JsonHelper.jsonObject(); for (Entry<String, AttributeValue> entry : attrs.entrySet()) { obj.set(entry.getKey(), getJsonValue(entry.getValue())); } return new User(userId, null, obj); }); }
@Override public Optional<Map<String, Object>> getAttributes(RequestEnvelope envelope) throws PersistenceException { String partitionKey = partitionKeyGenerator.apply(envelope); GetItemRequest request = new GetItemRequest() .withTableName(tableName) .withKey(Collections.singletonMap(partitionKeyName, new AttributeValue().withS(partitionKey))) .withConsistentRead(true); Map<String, AttributeValue> result = null; try { result = dynamoDb.getItem(request).getItem(); } catch (ResourceNotFoundException e) { throw new PersistenceException(String.format("Table %s does not exist or is in the process of being created", tableName), e); } catch (AmazonDynamoDBException e) { throw new PersistenceException("Failed to retrieve attributes from DynamoDB", e); } if (result != null && result.containsKey(attributesKeyName)) { Map<String, Object> attributes = ItemUtils.toSimpleMapValue(result.get(attributesKeyName).getM()); return Optional.of(attributes); } return Optional.empty(); }
@Override public <T> T getConfig(String project, String configName, Class<T> clazz) { Map<String, AttributeValue> item = dynamoDBClient.getItem(new GetItemRequest() .withTableName(tableConfig.getTableName()) .withKey(new SimpleImmutableEntry<>("project", new AttributeValue(project)), new SimpleImmutableEntry<>("id", new AttributeValue(configName))) .withAttributesToGet("value") .withConsistentRead(true)).getItem(); if (item == null) { return null; } String value = item.get("value").getS(); return value == null ? null : JsonHelper.read(value, clazz); }
@Override public MaterializedView getMaterializedView(String project, String tableName) { Map<String, AttributeValue> item = dynamoDBClient.getItem(new GetItemRequest().withTableName(tableConfig.getTableName()) .withAttributesToGet("value") .withKey(of( "project", new AttributeValue(project), "type_table_name", new AttributeValue("materialized_" + tableName)))).getItem(); if (item == null) { throw new NotExistsException("Materialized view"); } return JsonHelper.read(item.get("value").getS(), MaterializedView.class); }
private Document getItem(Key key, GetItemOperationConfig config) { final GetItemRequest request = new GetItemRequest(tableName, key); if (config != null) { request.setConsistentRead(config.isConsistentRead()); if (config.getAttributesToGet() != null && config.getAttributesToGet().size() > 0) { request.setAttributesToGet(config.getAttributesToGet()); } } Table.appendDynamoDBDocumentUserAgentString(request); final GetItemResult response = this.client.getItem(request); final Map<String, AttributeValue> item = response.getItem(); if (item == null || item.size() == 0) { return null; } final Document returnDocument = fromAttributeMap(item); returnDocument.commit(); return returnDocument; }
final Map<String, AttributeValue> itemAttributes = item.getItem(); if (itemAttributes == null) { return null;
/** * Returns all the returned attributes as an {@link Item}; or null if the * item doesn't exist. */ public Item getItem() { Map<String, Object> attributes = InternalUtils.toSimpleMapValue(result.getItem()); Item item = Item.fromMap(attributes); return item; }
private EntryList extractEntriesFromGetItemResult(final GetItemResult result, final StaticBuffer sliceStart, final StaticBuffer sliceEnd, final int limit) { final Map<String, AttributeValue> item = result.getItem(); List<Entry> filteredEntries = Collections.emptyList(); if (null != item) { item.remove(Constants.JANUSGRAPH_HASH_KEY); filteredEntries = new EntryBuilder(item) .slice(sliceStart, sliceEnd) .limit(limit) .buildAll(); } return StaticArrayEntryList.of(filteredEntries); }
/** * Fetches this transaction item from the tx table. Uses consistent read. * * @return the latest copy of the transaction item, or null if it has been completed (and deleted) */ private Map<String, AttributeValue> get() { GetItemRequest getRequest = new GetItemRequest() .withTableName(txManager.getTransactionTableName()) .withKey(txKey) .withConsistentRead(true); return txManager.getClient().getItem(getRequest).getItem(); }