类com.amazonaws.services.dynamodbv2.model.GetItemRequest源码实例Demo

下面列出了怎么用com.amazonaws.services.dynamodbv2.model.GetItemRequest的API类实例代码及写法,或者点击链接到github查看源代码。

/**
 * Gets the FragmentCheckpoint item from the table for the specified stream name.
 *
 * @param streamName Input stream name
 * @return FragmentCheckpoint entry. null if any exception is thrown.
 */
public Map<String, AttributeValue> getItem(final String streamName) {
    try {
        final Map<String,AttributeValue> key = new HashMap<>();
        key.put(KVS_STREAM_NAME, new AttributeValue().withS(streamName));
        final GetItemRequest getItemRequest = new GetItemRequest() {{
            setTableName(TABLE_NAME);
            setKey(key);
        }};

        return ddbClient.getItem(getItemRequest).getItem();
    } catch (final AmazonDynamoDBException e) {
        log.warn("Error while getting item from table!", e);
    }
    return null;
}
 
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);
    }

}
 
public static void retrieveItem(String threadId, String replyDateTime) throws IOException {
    HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>();
    key.put("Id", new AttributeValue().withS(threadId));
    key.put("ReplyDateTime", new AttributeValue().withS(replyDateTime));

    GetItemRequest getReplyRequest = new GetItemRequest().withTableName(tableName).withKey(key)
        .withConsistentRead(true);

    GetItemResult getReplyResult = client.getItem(getReplyRequest);

    // Decompress the reply message and print
    Map<String, AttributeValue> reply = getReplyResult.getItem();
    String message = decompressString(reply.get("ExtendedMessage").getB());
    System.out.println("Reply message:\n" + " Id: " + reply.get("Id").getS() + "\n" + " ReplyDateTime: "
        + reply.get("ReplyDateTime").getS() + "\n" + " PostedBy: " + reply.get("PostedBy").getS() + "\n"
        + " Message: " + reply.get("Message").getS() + "\n" + " ExtendedMessage (decompressed): " + message);
}
 
@Test
public void performanceTest() throws Exception {
    NumberAttributeTestClass obj = getUniqueObject();
    DynamoDBMapper mapper = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo);
    mapper.save(obj);
    HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>();
    key.put(KEY_NAME, new AttributeValue().withS(obj.getKey()));
    GetItemResult item = dynamo.getItem(new GetItemRequest()
            .withTableName("aws-java-sdk-util-crypto").withKey(key));
    
    long start = System.currentTimeMillis();
    for (int i = 0; i < 10000; i++) {
        mapper.marshallIntoObject(NumberAttributeTestClass.class, item.getItem());
    }        
    
    long end = System.currentTimeMillis();
    
    System.err.println("time: " + (end - start));
}
 
/**
 * Returns the list of usernames stored in the user table.
 */
public void describeUser(String username, String userTable) {
    HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>();
    key.put("username", new AttributeValue().withS(username));

    GetItemRequest getItemRequest = new GetItemRequest()
            .withTableName(userTable)
            .withKey(key);

    Map<String, AttributeValue> list = ddb.getItem(getItemRequest).getItem();
    if (list.isEmpty()) {
        System.err.println("No record found for username '" + username + "'");
        return;
    }

    for (Entry<String, AttributeValue> entry : list.entrySet()) {
        System.out.println(entry.getKey() + " = " + entry.getValue().getS());
    }
}
 
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);
    }   

}
 
public static void retrieveItem(String threadId, String replyDateTime) throws IOException {
    HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>();
    key.put("Id", new AttributeValue().withS(threadId));
    key.put("ReplyDateTime", new AttributeValue().withS(replyDateTime));
    
    GetItemRequest getReplyRequest = new GetItemRequest()
        .withTableName(tableName)
        .withKey(key)
        .withConsistentRead(true);
    
    GetItemResult getReplyResult = client.getItem(getReplyRequest);
    
    // Decompress the reply message and print
    Map<String, AttributeValue> reply = getReplyResult.getItem();
    String message = decompressString(reply.get("ExtendedMessage").getB());
    System.out.println("Reply message:\n"
        + " Id: " + reply.get("Id").getS() + "\n" 
        + " ReplyDateTime: " + reply.get("ReplyDateTime").getS() + "\n" 
        + " PostedBy: " + reply.get("PostedBy").getS() + "\n"
        + " Message: " + reply.get("Message").getS() + "\n"
        + " ExtendedMessage (decompressed): " + message);
}
 
源代码8 项目: dynamodb-geo   文件: DynamoDBManager.java
public GetPointResult getPoint(GetPointRequest getPointRequest) {
	long geohash = S2Manager.generateGeohash(getPointRequest.getGeoPoint());
	long hashKey = S2Manager.generateHashKey(geohash, config.getHashKeyLength());

	GetItemRequest getItemRequest = getPointRequest.getGetItemRequest();
	getItemRequest.setTableName(config.getTableName());

	AttributeValue hashKeyValue = new AttributeValue().withN(String.valueOf(hashKey));
	getItemRequest.getKey().put(config.getHashKeyAttributeName(), hashKeyValue);
	getItemRequest.getKey().put(config.getRangeKeyAttributeName(), getPointRequest.getRangeKeyValue());

	GetItemResult getItemResult = config.getDynamoDBClient().getItem(getItemRequest);
	GetPointResult getPointResult = new GetPointResult(getItemResult);

	return getPointResult;
}
 
@Test
public void getItemWithDelete() {
    Transaction t1 = manager.newTransaction();
    Map<String, AttributeValue> getResult1 = t1.getItem(new GetItemRequest().withTableName(INTEG_HASH_TABLE_NAME).withKey(key0)).getItem();
    assertEquals(getResult1, item0);
    assertItemLocked(INTEG_HASH_TABLE_NAME, key0, item0, t1.getId(), false, false);
    
    t1.deleteItem(new DeleteItemRequest().withTableName(INTEG_HASH_TABLE_NAME).withKey(key0));
    assertItemLocked(INTEG_HASH_TABLE_NAME, key0, item0, t1.getId(), false, false);
    
    Map<String, AttributeValue> getResult2 = t1.getItem(new GetItemRequest().withTableName(INTEG_HASH_TABLE_NAME).withKey(key0)).getItem();
    assertNull(getResult2);
    assertItemLocked(INTEG_HASH_TABLE_NAME, key0, item0, t1.getId(), false, false);
    
    t1.commit();
}
 
@Test
public void getFilterAttributesToGet() {
    Transaction t1 = manager.newTransaction();
    
    Map<String, AttributeValue> item1 = new HashMap<String, AttributeValue>();
    item1.put("s_someattr", item0.get("s_someattr"));
    
    Map<String, AttributeValue> getResult1 = t1.getItem(new GetItemRequest()
        .withTableName(INTEG_HASH_TABLE_NAME)
        .withAttributesToGet("s_someattr", "notexists")
        .withKey(key0)).getItem();
    assertEquals(item1, getResult1);
    assertItemLocked(INTEG_HASH_TABLE_NAME, key0, t1.getId(), false, false);
    
    t1.commit();
    
    assertItemNotLocked(INTEG_HASH_TABLE_NAME, key0, item0, true);
}
 
@Test
public void getItemNotExists() {
    Transaction t1 = manager.newTransaction();
    Map<String, AttributeValue> key1 = newKey(INTEG_HASH_TABLE_NAME);
    
    Map<String, AttributeValue> getResult1 = t1.getItem(new GetItemRequest().withTableName(INTEG_HASH_TABLE_NAME).withKey(key1)).getItem();
    assertNull(getResult1);
    assertItemLocked(INTEG_HASH_TABLE_NAME, key1, t1.getId(), true, false);
    
    Map<String, AttributeValue> getResult2 = t1.getItem(new GetItemRequest().withTableName(INTEG_HASH_TABLE_NAME).withKey(key1)).getItem();
    assertNull(getResult2);
    assertItemLocked(INTEG_HASH_TABLE_NAME, key1, t1.getId(), true, false);
    
    t1.commit();
    
    assertItemNotLocked(INTEG_HASH_TABLE_NAME, key1, false);
}
 
@Test
public void getItemAfterPutItemInsert() {
    Transaction t1 = manager.newTransaction();
    Map<String, AttributeValue> key1 = newKey(INTEG_HASH_TABLE_NAME);
    Map<String, AttributeValue> item1 = new HashMap<String, AttributeValue>(key1);
    item1.put("asdf", new AttributeValue("wef"));
    
    Map<String, AttributeValue> getResult1 = t1.getItem(new GetItemRequest().withTableName(INTEG_HASH_TABLE_NAME).withKey(key1)).getItem();
    assertNull(getResult1);
    assertItemLocked(INTEG_HASH_TABLE_NAME, key1, t1.getId(), true, false);
    
    Map<String, AttributeValue> putResult1 = t1.putItem(new PutItemRequest()
        .withTableName(INTEG_HASH_TABLE_NAME)
        .withItem(item1)
        .withReturnValues(ReturnValue.ALL_OLD)).getAttributes();
    assertItemLocked(INTEG_HASH_TABLE_NAME, key1, item1, t1.getId(), true, true);
    assertNull(putResult1);
    
    Map<String, AttributeValue> getResult2 = t1.getItem(new GetItemRequest().withTableName(INTEG_HASH_TABLE_NAME).withKey(key1)).getItem();
    assertEquals(getResult2, item1);
    assertItemLocked(INTEG_HASH_TABLE_NAME, key1, item1, t1.getId(), true, true);
    
    t1.commit();
    
    assertItemNotLocked(INTEG_HASH_TABLE_NAME, key1, item1, true);
}
 
@Test
public void getItemAfterPutItemOverwrite() {
    Transaction t1 = manager.newTransaction();
    Map<String, AttributeValue> item1 = new HashMap<String, AttributeValue>(item0);
    item1.put("asdf", new AttributeValue("wef"));
    
    Map<String, AttributeValue> getResult1 = t1.getItem(new GetItemRequest().withTableName(INTEG_HASH_TABLE_NAME).withKey(key0)).getItem();
    assertEquals(getResult1, item0);
    assertItemLocked(INTEG_HASH_TABLE_NAME, key0, item0, t1.getId(), false, false);
    
    Map<String, AttributeValue> putResult1 = t1.putItem(new PutItemRequest()
        .withTableName(INTEG_HASH_TABLE_NAME)
        .withItem(item1)
        .withReturnValues(ReturnValue.ALL_OLD)).getAttributes();
    assertItemLocked(INTEG_HASH_TABLE_NAME, key0, item1, t1.getId(), false, true);
    assertEquals(putResult1, item0);
    
    Map<String, AttributeValue> getResult2 = t1.getItem(new GetItemRequest().withTableName(INTEG_HASH_TABLE_NAME).withKey(key0)).getItem();
    assertEquals(getResult2, item1);
    assertItemLocked(INTEG_HASH_TABLE_NAME, key0, item1, t1.getId(), false, true);
    
    t1.commit();
    
    assertItemNotLocked(INTEG_HASH_TABLE_NAME, key0, item1, true);
}
 
@Test
public void getThenUpdateNewItem() {
    Transaction t1 = manager.newTransaction();
    Map<String, AttributeValue> key1 = newKey(INTEG_HASH_TABLE_NAME);
    
    Map<String, AttributeValue> item1 = new HashMap<String, AttributeValue>(key1);
    item1.put("asdf", new AttributeValue("didn't exist"));
    
    Map<String, AttributeValueUpdate> updates1 = new HashMap<String, AttributeValueUpdate>();
    updates1.put("asdf", new AttributeValueUpdate(new AttributeValue("didn't exist"), AttributeAction.PUT));
    
    Map<String, AttributeValue> getResult = t1.getItem(new GetItemRequest().withTableName(INTEG_HASH_TABLE_NAME).withKey(key1)).getItem();
    assertItemLocked(INTEG_HASH_TABLE_NAME, key1, t1.getId(), true, false);
    assertNull(getResult);
    
    Map<String, AttributeValue> updateResult = t1.updateItem(new UpdateItemRequest().withTableName(INTEG_HASH_TABLE_NAME).withKey(key1)
            .withAttributeUpdates(updates1).withReturnValues(ReturnValue.ALL_NEW)).getAttributes();
    assertItemLocked(INTEG_HASH_TABLE_NAME, key1, item1, t1.getId(), true, true);
    assertEquals(item1, updateResult);
    
    t1.commit();
    
    assertItemNotLocked(INTEG_HASH_TABLE_NAME, key1, item1, true);
}
 
@Test
public void getThenUpdateExistingItem() {
    Transaction t1 = manager.newTransaction();
    
    Map<String, AttributeValue> item0a = new HashMap<String, AttributeValue>(item0);
    item0a.put("wef", new AttributeValue("new attr"));
    
    Map<String, AttributeValueUpdate> updates1 = new HashMap<String, AttributeValueUpdate>();
    updates1.put("wef", new AttributeValueUpdate(new AttributeValue("new attr"), AttributeAction.PUT));
    
    Map<String, AttributeValue> getResult = t1.getItem(new GetItemRequest().withTableName(INTEG_HASH_TABLE_NAME).withKey(key0)).getItem();
    assertItemLocked(INTEG_HASH_TABLE_NAME, key0, item0, t1.getId(), false, false);
    assertEquals(item0, getResult);
    
    Map<String, AttributeValue> updateResult = t1.updateItem(new UpdateItemRequest().withTableName(INTEG_HASH_TABLE_NAME).withKey(key0)
            .withAttributeUpdates(updates1).withReturnValues(ReturnValue.ALL_NEW)).getAttributes();
    assertItemLocked(INTEG_HASH_TABLE_NAME, key0, item0a, t1.getId(), false, true);
    assertEquals(item0a, updateResult);
    
    t1.commit();
    
    assertItemNotLocked(INTEG_HASH_TABLE_NAME, key0, item0a, true);
}
 
@Test
public void getItemUncommittedInsert() {
    Transaction t1 = manager.newTransaction();
    
    Map<String, AttributeValue> key1 = newKey(INTEG_HASH_TABLE_NAME);
    Map<String, AttributeValue> item1 = new HashMap<String, AttributeValue>(key1);
    item1.put("asdf", new AttributeValue("wef"));
    
    t1.putItem(new PutItemRequest()
        .withTableName(INTEG_HASH_TABLE_NAME)
        .withItem(item1));
    
    assertItemLocked(INTEG_HASH_TABLE_NAME, key1, item1, t1.getId(), true, true);
    
    Map<String, AttributeValue> item = manager.getItem(new GetItemRequest()
        .withTableName(INTEG_HASH_TABLE_NAME)
        .withKey(key1), IsolationLevel.UNCOMMITTED).getItem();
    assertNoSpecialAttributes(item);
    assertEquals(item1, item);
    assertItemLocked(INTEG_HASH_TABLE_NAME, key1, item1, t1.getId(), true, true);
    
    t1.rollback();
}
 
@Test
public void getItemUncommittedDeleted() {
    Transaction t1 = manager.newTransaction();
    
    t1.deleteItem(new DeleteItemRequest()
        .withTableName(INTEG_HASH_TABLE_NAME)
        .withKey(key0));
    
    assertItemLocked(INTEG_HASH_TABLE_NAME, key0, item0, t1.getId(), false, false);
    
    Map<String, AttributeValue> item = manager.getItem(new GetItemRequest()
        .withTableName(INTEG_HASH_TABLE_NAME)
        .withKey(key0), IsolationLevel.UNCOMMITTED).getItem();
    assertNoSpecialAttributes(item);
    assertEquals(item0, item);
    assertItemLocked(INTEG_HASH_TABLE_NAME, key0, item0, t1.getId(), false, false);
    
    t1.rollback();
}
 
@Test
public void getItemCommittedInsert() {
    Transaction t1 = manager.newTransaction();
    
    Map<String, AttributeValue> key1 = newKey(INTEG_HASH_TABLE_NAME);
    Map<String, AttributeValue> item1 = new HashMap<String, AttributeValue>(key1);
    item1.put("asdf", new AttributeValue("wef"));
    
    t1.putItem(new PutItemRequest()
        .withTableName(INTEG_HASH_TABLE_NAME)
        .withItem(item1));
    
    assertItemLocked(INTEG_HASH_TABLE_NAME, key1, item1, t1.getId(), true, true);
    
    Map<String, AttributeValue> item = manager.getItem(new GetItemRequest()
        .withTableName(INTEG_HASH_TABLE_NAME)
        .withKey(key1), IsolationLevel.COMMITTED).getItem();
    assertNull(item);
    assertItemLocked(INTEG_HASH_TABLE_NAME, key1, item1, t1.getId(), true, true);
    
    t1.rollback();
}
 
@Test
public void getItemCommittedDeleted() {
    Transaction t1 = manager.newTransaction();
    
    t1.deleteItem(new DeleteItemRequest()
        .withTableName(INTEG_HASH_TABLE_NAME)
        .withKey(key0));
    
    assertItemLocked(INTEG_HASH_TABLE_NAME, key0, item0, t1.getId(), false, false);
    
    Map<String, AttributeValue> item = manager.getItem(new GetItemRequest()
        .withTableName(INTEG_HASH_TABLE_NAME)
        .withKey(key0), IsolationLevel.COMMITTED).getItem();
    assertNoSpecialAttributes(item);
    assertEquals(item0, item);
    assertItemLocked(INTEG_HASH_TABLE_NAME, key0, item0, t1.getId(), false, false);
    
    t1.rollback();
}
 
源代码20 项目: dynamodb-transactions   文件: TransactionItem.java
/**
 * Retrieves the old copy of the item, with any item image saving specific attributes removed
 * 
 * @param rid
 * @return
 */
public Map<String, AttributeValue> loadItemImage(int rid) {
    txAssert(rid > 0, txId, "Expected rid > 0");
    
    Map<String, AttributeValue> key = new HashMap<String, AttributeValue>(1);
    key.put(AttributeName.IMAGE_ID.toString(), new AttributeValue(txId + "#" + rid));
    
    Map<String, AttributeValue> item = txManager.getClient().getItem(new GetItemRequest()
        .withTableName(txManager.getItemImageTableName())
        .withKey(key)
        .withConsistentRead(true)).getItem();
    
    if(item != null) {
        item.remove(AttributeName.IMAGE_ID.toString());
    }
    
    return item;
}
 
/**
 * Create a GetItemRequest for an item (in the event that you need to get the item again).
 * @param tableName The table that holds the item
 * @param item The item to get
 * @return the request
 */
protected GetItemRequest createGetItemRequest(
        final String tableName,
        final Map<String, AttributeValue> item) {
    Map<String, AttributeValue> key = txManager.createKeyMap(tableName, item);

    /*
     * Set the request to consistent read the next time around, since we may have read while locking tx
     * was cleaning up or read a stale item that is no longer locked
     */
    GetItemRequest request = new GetItemRequest()
            .withTableName(tableName)
            .withKey(key)
            .withConsistentRead(true);
    return request;
}
 
源代码22 项目: dynamodb-transactions   文件: RequestTest.java
@Test
public void roundTripGetString() {
    GetItem r1 = new GetItem();
    Map<String, AttributeValue> item = new HashMap<String, AttributeValue>();
    item.put(HASH_ATTR_NAME, new AttributeValue("a"));
    r1.setRequest(new GetItemRequest()
        .withTableName(TABLE_NAME)
        .withKey(item));
    byte[] r1Bytes = Request.serialize("123", r1).array();
    Request r2 = Request.deserialize("123", ByteBuffer.wrap(r1Bytes));
    byte[] r2Bytes = Request.serialize("123", r2).array();
    assertArrayEquals(r1Bytes, r2Bytes);
}
 
源代码23 项目: pocket-etl   文件: DynamoDbFunctionalTest.java
private GetItemResult getThingFromDdb(String key) {
    final HashMap<String, AttributeValue> requestItems = new HashMap<>();
    requestItems.put("pk", new AttributeValue(key));
    final GetItemRequest getItemRequest = new GetItemRequest();
    getItemRequest.withTableName(tableName).withKey(requestItems);
    return ddb.getItem(getItemRequest);
}
 
@Override
public final Response getItem(final Request request) {

    final HashMap<String, AttributeValue> primaryKey = new HashMap<>();
    primaryKey.put(request.getPartitionKey(), new AttributeValue(request.getPartitionKeyValue()));
    primaryKey.put(request.getSortKey(), new AttributeValue().withN(request.getSortKeyValue()));

    final GetItemResult getItemResult = dynamoDBClient.getItem(new GetItemRequest()
            .withTableName(request.getTableName())
            .withKey(primaryKey));

    return new Response("PK of Item read using get-item (V2): "
            + prepareKeyStr(getItemResult.getItem(), request), null);
}
 
@Override
public void beforeRequest(Request<?> request) {

    /* Things to do just before a request is executed */
    if (request.getOriginalRequest() instanceof PutItemRequest) {

        /* Throw throughput exceeded exception for 50% of put requests */
        if (rnd.nextInt(2) == 0) {

            logger.info("Injecting ProvisionedThroughputExceededException");
            throw new ProvisionedThroughputExceededException("Injected Error");
        }
    }

    /* Add latency to some Get requests */
    if (request.getOriginalRequest() instanceof GetItemRequest) {

        /* Delay 50% of GetItem requests by 500 ms */
        if (rnd.nextInt(2) == 0) {
            /*
             * Delay on average 50% of the requests from client perspective
             */
            try {

                logger.info("Injecting 500 ms delay");
                Thread.sleep(500);
            }
            catch (InterruptedException ie) {
                logger.info(ie);
                throw new RuntimeException(ie);
            }
        }
    }
}
 
@Override
public void afterResponse(Request<?> request, Response<?> response) {
    /*
     * The following is a hit and miss for multi-threaded clients as the
     * cache size is only 50 entries
     */
    String awsRequestId = dynamoDBClient.getCachedResponseMetadata(request.getOriginalRequest()).getRequestId();
    logger.info("AWS RequestID: " + awsRequestId);

    /*
     * Here you could inspect and alter the response object to see how your
     * application behaves for specific data
     */
    if (request.getOriginalRequest() instanceof GetItemRequest) {
        GetItemResult result = (GetItemResult) response.getAwsResponse();

        Map<String, AttributeValue> item = result.getItem();

        if (item.get("name").getS().equals("Airplane")) {

            // Alter the item
            item.put("name", new AttributeValue("newAirplane"));
            item.put("new attr", new AttributeValue("new attr"));

            // Add some delay
            try {
                Thread.sleep(500);
            }
            catch (InterruptedException ie) {
                logger.info(ie);
                throw new RuntimeException(ie);
            }
        }
    }
}
 
/**
 * Get user info for the username
 * 
 * @param username
 *            Unique user identifier
 * @return UserInfo for the user, null otherwise
 */
public UserInfo getUserInfo(String username) throws DataAccessException {
    HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>();
    key.put(ATTRIBUTE_USERNAME, new AttributeValue().withS(username));

    GetItemRequest getItemRequest = new GetItemRequest()
            .withTableName(USER_TABLE)
            .withKey(key);

    try {
        return UserInfo.fromData(ddb.getItem(getItemRequest).getItem());
    } catch (AmazonClientException e) {
        throw new DataAccessException("Failed to get item username: " + username, e);
    }
}
 
/**
 * Returns device info for given device ID (UID)
 * 
 * @param uid
 *            Unique device identifier
 * @return device info for the given uid
 */
public DeviceInfo getDeviceInfo(String uid) throws DataAccessException {
    HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>();
    key.put(ATTRIBUTE_UID, new AttributeValue().withS(uid));

    GetItemRequest getItemRequest = new GetItemRequest()
            .withTableName(DEVICE_TABLE)
            .withKey(key);

    try {
        return DeviceInfo.fromData(ddb.getItem(getItemRequest).getItem());
    } catch (AmazonClientException e) {
        throw new DataAccessException("Failed to get device: " + uid, e);
    }
}
 
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;
}
 
@Override
public EntryList getSlice(final KeySliceQuery query, final StoreTransaction txh) throws BackendException {
    log.debug("Entering getSliceKeySliceQuery table:{} query:{} txh:{}", getTableName(), encodeForLog(query), txh);
    final GetItemRequest request = super.createGetItemRequest().withKey(new ItemBuilder().hashKey(query.getKey()).build());
    final GetItemResult result = new ExponentialBackoff.GetItem(request, client.getDelegate()).runWithBackoff();

    final List<Entry> filteredEntries = extractEntriesFromGetItemResult(result, query.getSliceStart(), query.getSliceEnd(), query.getLimit());
    log.debug("Exiting getSliceKeySliceQuery table:{} query:{} txh:{} returning:{}", getTableName(), encodeForLog(query), txh,
              filteredEntries.size());
    return StaticArrayEntryList.of(filteredEntries);
}
 
 类方法
 同包方法