Refine search
@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 int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getItem() == null) ? 0 : getItem().hashCode()); hashCode = prime * hashCode + ((getConsumedCapacity() == null) ? 0 : getConsumedCapacity().hashCode()); return hashCode; }
public GetItemResult unmarshall(JsonUnmarshallerContext context) throws Exception { GetItemResult getItemResult = new GetItemResult(); if (context.testExpression("Item", targetDepth)) { context.nextToken(); getItemResult.setItem(new MapUnmarshaller<String, AttributeValue>(context.getUnmarshaller(String.class), AttributeValueJsonUnmarshaller .getInstance()).unmarshall(context)); getItemResult.setConsumedCapacity(ConsumedCapacityJsonUnmarshaller.getInstance().unmarshall(context));
@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 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(); }
final GetItemRequest request = this.makeItemRequestFor(attr); final long start = System.currentTimeMillis(); final GetItemResult result = aws.getItem(request); has = result.getItem().get(attrib) != null; Logger.info( this, "#has('%s'): %B from DynamoDB, %s, in %[ms]s", attr, has, new PrintableConsumedCapacity( result.getConsumedCapacity() ).print(), System.currentTimeMillis() - start ); } finally { aws.shutdown();
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; }
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()));
/** * 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; }
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; }
/** * Method which returns the update information for an Aggregator process. * * @param streamName The Stream name which is being aggregated. * @param applicationName The application which is hosting the aggregator. * @param workerId The worker ID which is running an aggregator instance. * @return Tuple of Last Write Time (String), Last Low Sequence, and Last * High Sequence */ public InventoryStatus getLastUpdate(final String streamName, final String applicationName, final String namespace, final String shardId) { GetItemResult response = dynamoClient.getItem(InventoryModel.TABLE_NAME, getKey(streamName, applicationName, namespace, shardId)); if (response.getItem() != null) { Map<String, AttributeValue> item = response.getItem(); AttributeValue lastTime, lowSeq, highSeq = null; lastTime = item.get(InventoryModel.LAST_WRITE_TIME); lowSeq = item.get(InventoryModel.LAST_LOW_SEQ); highSeq = item.get(InventoryModel.LAST_HIGH_SEQ); return new InventoryStatus(lastTime == null ? null : lastTime.getS(), lowSeq == null ? null : lowSeq.getS(), highSeq == null ? null : highSeq.getS()); } else { return null; } } }
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; }
request = createGetItemRequest(tableName, item); currentItem = txManager.getClient().getItem(request).getItem(); request = createGetItemRequest(tableName, item); return getOldCommittedItem(lockingTx, tableName, request.getKey()); } catch (UnknownCompletedTransactionException e2) { LOG.debug("Could not find item image. Transaction must have already completed.", e2);
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; }
when(mockAmazonDynamoDBClient.getItem(isA(GetItemRequest.class))).thenAnswer(new Answer<GetItemResult>() { @Override public GetItemResult answer(InvocationOnMock invocation) throws Throwable { GetItemResult result = new GetItemResult(); result.setItem( testResultItem ); return result; } });
/** * <p> * A map of attribute names to <code>AttributeValue</code> objects, as specified by * <code>ProjectionExpression</code>. * </p> * * @param item * A map of attribute names to <code>AttributeValue</code> objects, as specified by * <code>ProjectionExpression</code>. * @return Returns a reference to this object so that method calls can be chained together. */ public GetItemResult withItem(java.util.Map<String, AttributeValue> item) { setItem(item); return this; }
@Override public GetItemResult measureConsumedCapacity(GetItemResult result) { ConsumedCapacity consumedCapacity = result.getConsumedCapacity(); if (consumedCapacity != null && consumedCapacity.getCapacityUnits() != null) { consumed.addAndGet(result.getConsumedCapacity().getCapacityUnits()); } return result; } }