Refine search
/** * Simplified method form for invoking the GetItem operation. * * @see #getItemAsync(GetItemRequest) */ @Override public java.util.concurrent.Future<GetItemResult> getItemAsync(String tableName, java.util.Map<String, AttributeValue> key, Boolean consistentRead) { return getItemAsync(new GetItemRequest().withTableName(tableName).withKey(key).withConsistentRead(consistentRead)); }
@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 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; }
/** * Constructs a new GetItemRequest object. Callers should use the setter or fluent setter (with...) methods to * initialize any additional object members. * * @param tableName * The name of the table containing the requested item. * @param key * A map of attribute names to <code>AttributeValue</code> objects, representing the primary key of the item * to retrieve.</p> * <p> * For the primary key, you must provide all of the attributes. For example, with a simple primary key, you * only need to provide a value for the partition key. For a composite primary key, you must provide values * for both the partition key and the sort key. */ public GetItemRequest(String tableName, java.util.Map<String, AttributeValue> key) { setTableName(tableName); setKey(key); }
/** * Simplified method form for invoking the GetItem operation. * * @see #getItemAsync(GetItemRequest) */ @Override public java.util.concurrent.Future<GetItemResult> getItemAsync(String tableName, java.util.Map<String, AttributeValue> key) { return getItemAsync(new GetItemRequest().withTableName(tableName).withKey(key)); }
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 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; }
/** * Makes a GetItemRequest for a given attribute. * @param attr Attribute name * @return GetItemRequest */ private GetItemRequest makeItemRequestFor(final String attr) { final GetItemRequest request = new GetItemRequest(); request.setTableName(this.name); request.setAttributesToGet(Collections.singletonList(attr)); request.setKey(this.attributes.only(this.keys)); request.setReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL); request.setConsistentRead(true); return request; }
@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 static void retrieveItem() { try { HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>(); key.put("Id", new AttributeValue().withN("120")); GetItemRequest getItemRequest = new GetItemRequest() .withTableName(tableName) .withKey(key) .withProjectionExpression("Id, ISBN, Title, Authors"); GetItemResult result = client.getItem(getItemRequest); // Check the response. System.out.println("Printing item after retrieving it...."); printItem(result.getItem()); } catch (AmazonServiceException ase) { System.err.println("Failed to retrieve item in " + tableName); } }
@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); }
GetItemRequest greq = new GetItemRequest(table, createPrimaryKey(startkey)); greq.setAttributesToGet(fields); if (null != gres.getItem()) { result.add(extractResult(gres.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; }
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); }
Boolean consistentRead) throws AmazonServiceException, AmazonClientException { GetItemRequest getItemRequest = new GetItemRequest(); getItemRequest.setTableName(tableName); getItemRequest.setKey(key); getItemRequest.setConsistentRead(consistentRead); return getItem(getItemRequest);
protected GetItemRequest createGetItemRequest() { return new GetItemRequest() .withTableName(tableName) .withConsistentRead(forceConsistentRead) .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL); }
public GetItemSpec() { super(new GetItemRequest()); }
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(getTablNameForAppid(appid), Collections.singletonMap(Config._KEY, new AttributeValue(key))); GetItemResult res = client().getItem(getItemRequest); if (res != null && res.getItem() != null && !res.getItem().isEmpty()) { row = res.getItem(); } } catch (Exception e) { logger.error(null, e); } return (row == null || row.isEmpty()) ? null : row; }
GetItemRequest getItemRequest = new GetItemRequest(); getItemRequest.setTableName(tableName); getItemRequest.setKey(key); return getItem(getItemRequest);
/** * Constructs a new GetItemRequest object. Callers should use the setter or fluent setter (with...) methods to * initialize any additional object members. * * @param tableName * The name of the table containing the requested item. * @param key * A map of attribute names to <code>AttributeValue</code> objects, representing the primary key of the item * to retrieve.</p> * <p> * For the primary key, you must provide all of the attributes. For example, with a simple primary key, you * only need to provide a value for the partition key. For a composite primary key, you must provide values * for both the partition key and the sort key. * @param consistentRead * Determines the read consistency model: If set to <code>true</code>, then the operation uses strongly * consistent reads; otherwise, the operation uses eventually consistent reads. */ public GetItemRequest(String tableName, java.util.Map<String, AttributeValue> key, Boolean consistentRead) { setTableName(tableName); setKey(key); setConsistentRead(consistentRead); }