我正在使用AWS Android SDK与DynamoDB进行通信。我在DynamoDB中定义了以下表:
名称:BeaconPosition HashKey:BeaconKey(String) 属性:BeaconName(String),BeaconAccuracy(Number)
加载到此表的数据工作正常,但我正在努力从我的应用程序中检索此表中的所有行。我浏览了AWS DynamoDB文档并尝试了两种检索表行的方法:
//Initializing dynamoDB client in the constructor of my data mapper.
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
applicationContext, // get the context for the current activity
"us-XXXX-X:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", // Identity Pool ID
Regions.US_EAST_1 //Region
);
AmazonDynamoDBClient ddbClient = new AmazonDynamoDBClient(credentialsProvider);
//1st way of retrieving table rows.
ScanRequest scanRequest = new ScanRequest().withTableName("BeaconPosition");
ScanResult result = ddbClient.scan(scanRequest);
for (Map<String, AttributeValue> item : result.getItems()){
//code to read each item from the table.
}
//2nd way of retrieving table rows.
Condition hashKeyCondition = new Condition().withComparisonOperator(ComparisonOperator.EQ.toString()).withAttributeValueList(new AttributeValue().withS("BeaconKeyXXXXX-XXXXX"));
Map<String, Condition> keyConditions = new HashMap<String, Condition>();
keyConditions.put("BeaconKey", hashKeyCondition);
Map<String, AttributeValue> lastEvaluatedKey = null;
do {
QueryResult queryResult=null;
QueryRequest queryRequest = new QueryRequest().withTableName("BeaconPosition").withKeyConditions(keyConditions).withExclusiveStartKey(lastEvaluatedKey);
queryResult = ddbClient.query(queryRequest);
for (Map<String, AttributeValue> item : queryResult.getItems()) {
//Code to read item and load domain object.
}
lastEvaluatedKey = queryResult.getLastEvaluatedKey();
} while (lastEvaluatedKey != null);
问题:我正在调试此代码块,并观察到系统以上述两种方式挂起在下面的代码行上。调试器永远不会从执行此代码行返回。我尝试过清理,重建,重新启动Android Studio,在我的设备上卸载/重新安装应用程序,但没有任何帮助。我已经验证了表名和属性是否已正确指定。我也试过提供一个不正确/不可用的表名,但行为保持原样。
第一种方式:
ScanResult result = ddbClient.scan(scanRequest);
第二种方式:
queryResult = ddbClient.query(queryRequest);
更新:我在后台线程中执行此数据检索逻辑。