private GetItemOutcome doLoadItem(GetItemSpec spec) { String tableName = getTable().getTableName(); // Set up the key attributes GetItemRequest req = spec.getRequest() .withTableName(tableName) .withKey(InternalUtils.toAttributeValueMap(spec.getKeyComponents())) .withExpressionAttributeNames(spec.getNameMap()); GetItemResult result = getClient().getItem(req); return new GetItemOutcome(result); }
@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; }
@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(); }
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; }
rq.setConsistentRead(config.getConsistentReads() == ConsistentReads.CONSISTENT); final GetItemResult item = db.getItem(applyUserAgent(rq)); final Map<String, AttributeValue> itemAttributes = item.getItem(); if (itemAttributes == null) {
@Override public GetItemResult getItem(String tableName, Map<String, AttributeValue> key, Boolean consistentRead) throws AmazonServiceException, AmazonClientException { return getBackend().getItem(tableName, key, consistentRead); }
@Override public GetItemResult getItem(GetItemRequest request) throws AmazonServiceException, AmazonClientException { return getBackend().getItem(request); }
@Override public GetItemResult getItem(String tableName, Map<String, AttributeValue> key) throws AmazonServiceException, AmazonClientException { return getBackend().getItem(tableName, key); }
@Override public String apply(String key) { final GetItemRequest request = new GetItemRequest() .withTableName(tableName) .withKey(ImmutableMap.of(partitionKeyName, new AttributeValue(key))) .withReturnConsumedCapacity(returnConsumedCapacity) .withConsistentRead(consistentRead); try { return Optional.ofNullable(dynamoDB.getItem(request)) .map(this::measureConsumedCapacity) .map(GetItemResult::getItem) .map(Map::toString) .orElse(null); } catch (AmazonServiceException ase) { throw amazonServiceException(ase); } catch (AmazonClientException ace) { throw amazonClientException(ace); } }
private Map<String, AttributeValue> readRow(String key, String appid) { if (StringUtils.isBlank(key) || StringUtils.isBlank(appid)) { return null; } Map<String, AttributeValue> row = null; try { GetItemRequest getItemRequest = new GetItemRequest(getTableNameForAppid(appid), Collections.singletonMap(Config._KEY, new AttributeValue(getKeyForAppid(key, appid)))); GetItemResult res = client().getItem(getItemRequest); if (res != null && res.getItem() != null && !res.getItem().isEmpty()) { row = res.getItem(); } } catch (Exception e) { logger.error("Could not read row from DB - appid={}, key={}", appid, key, e); } return (row == null || row.isEmpty()) ? null : row; }
private Map<String, AttributeValue> readRow(String key, String appid) { if (StringUtils.isBlank(key) || StringUtils.isBlank(appid)) { return null; } Map<String, AttributeValue> row = null; try { GetItemRequest getItemRequest = new GetItemRequest(getTableNameForAppid(appid), Collections.singletonMap(Config._KEY, new AttributeValue(getKeyForAppid(key, appid)))); GetItemResult res = client().getItem(getItemRequest); if (res != null && res.getItem() != null && !res.getItem().isEmpty()) { row = res.getItem(); } } catch (Exception e) { logger.error("Could not read row from DB - appid={}, key={}", appid, key, e); } return (row == null || row.isEmpty()) ? null : row; }
@Override protected Row executePrimaryKeyLookupQuery(Table table, List<SelectItem> selectItems, Column primaryKeyColumn, Object keyValue) { final List<String> attributeNames = new ArrayList<>(); for (SelectItem selectItem : selectItems) { attributeNames.add(selectItem.getColumn().getName()); } final GetItemRequest getItemRequest = new GetItemRequest(table.getName(), Collections.singletonMap( primaryKeyColumn.getName(), DynamoDbUtils.toAttributeValue(keyValue))).withAttributesToGet( attributeNames); final GetItemResult item = _dynamoDb.getItem(getItemRequest); final Object[] values = new Object[selectItems.size()]; for (int i = 0; i < values.length; i++) { final AttributeValue attributeValue = item.getItem().get(attributeNames.get(i)); values[i] = DynamoDbUtils.toValue(attributeValue); } return new DefaultRow(new SimpleDataSetHeader(selectItems), values); }
private Map<String, AttributeValue> ddbGet(final Map<String, AttributeValue> ddbKey) { return ddb.getItem( new GetItemRequest().withTableName(tableName).withConsistentRead(true) .withKey(ddbKey)).getItem(); }
private Map<String, AttributeValue> ddbGet(final Map<String, AttributeValue> ddbKey) { return ddb.getItem( new GetItemRequest().withTableName(tableName).withConsistentRead(true) .withKey(ddbKey)).getItem(); }
protected static Map<String, AttributeValue> getValue( final AmazonDynamoDB dynamoClient, final String tableName, final UpdateKey key) { GetItemRequest req = new GetItemRequest().withTableName(tableName) .withKey(getTableKey(key)); return dynamoClient.getItem(req).getItem(); }
protected static Map<String, AttributeValue> getItem(TransactionManager txManager, String tableName, Map<String, AttributeValue> key) { GetItemRequest getRequest = new GetItemRequest() .withTableName(tableName) .withConsistentRead(true) .withKey(key); GetItemResult getResult = txManager.getClient().getItem(getRequest); return getResult.getItem(); }
public GetItemResult getItem(GetItemRequest request, IsolationLevel isolationLevel) { if (request.getAttributesToGet() != null) { Set<String> attributesToGet = new HashSet<String>(request.getAttributesToGet()); attributesToGet.addAll(Transaction.SPECIAL_ATTR_NAMES); request.setAttributesToGet(attributesToGet); } GetItemResult result = getClient().getItem(request); Map<String, AttributeValue> item = getReadIsolationHandler(isolationLevel).handleItem(result.getItem(), request.getAttributesToGet(), request.getTableName()); Transaction.stripSpecialAttributes(item); result.setItem(item); return result; }
/** * 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(); }
GetItemResult getItem(final GetItemRequest request) throws BackendException { setUserAgent(request); GetItemResult result; timedReadThrottle(GET_ITEM, request.getTableName(), estimateCapacityUnits(GET_ITEM, request.getTableName())); final Timer.Context apiTimerContext = getTimerContext(GET_ITEM, request.getTableName()); try { result = client.getItem(request); } catch (Exception e) { throw processDynamoDbApiException(e, GET_ITEM, request.getTableName()); } finally { apiTimerContext.stop(); } meterConsumedCapacity(GET_ITEM, result.getConsumedCapacity()); return result; }
private GetItemOutcome doLoadItem(GetItemSpec spec) { String tableName = getTable().getTableName(); // Set up the key attributes GetItemRequest req = spec.getRequest() .withTableName(tableName) .withKey(InternalUtils.toAttributeValueMap(spec.getKeyComponents())) .withExpressionAttributeNames(spec.getNameMap()); GetItemResult result = getClient().getItem(req); return new GetItemOutcome(result); }