我们有一个围绕 QueryRequest 构建的框架。但是我们的框架是在 12-18 个月前构建的。当我阅读开发人员指南等当前文档时,我没有看到对 QueryRequest 的引用。本文档 ( Querying Tables Using the AWS SDK for Java Document API ) 中的示例使用了 QuerySpec,这对我来说是全新的。在同一文档的后面,有更多使用 Table.query 的示例。还有关于使用对象持久性模型的引用。
QueryRequest 是否已过时或计划弃用?当您有哈希键、rangeKeyConditions、FilterExpressions 等时,Table.query 目前是推荐使用的方法吗?
仅供引用,我们目前正在使用 setSelect()、setTableName()、setKeyConditions()、setQueryFilter() 等构建我们的 queryRequest。但是新用例看起来需要更复杂的 AND 和 OR 组合条件,所以看起来我们需要开始使用 FilterExpressions。
最佳答案
com.amazonaws.services.dynamodbv2.model.QueryRequest
没有被弃用,而且它看起来不像是有针对性的。 com.amazonaws.services.dynamodb.model.QueryRequest
(注意没有 v2)已弃用,我相信已在 1.9 AWS Java SDK 版本中删除。
DynamoDB 发布了另一个构建在低级 Java 客户端之上的库,称为 Document API . AWS Developer Blog 发布了一篇解释其用法的博客(Part 1 和 Part 2),并提到了其背后的原因,但它本质上使代码更易于编写和阅读。引自 Part 1 :
As you see, the new Document API allows the direct use of plain old Java data types and has less boilerplate. In fact, the Dynamo Document API can be used to entirely subsume what you can do with the low level client (i.e. AmazonDynamoDBClient) but with a much cleaner programming model and less code.
As you can see, saving JSON as a structured document in Amazon DynamoDB, or updating, retrieving and converting the document back into JSON is as easy as 1-2-3. :) You can find more examples in the A-Z Document API quick-start folder at GitHub. Happy coding until next time!
这主要取决于您希望如何编写代码,但我会说使用文档 API 比使用低级 Java 客户端更容易读写。
关于java - 何时将 QueryRequest 与适用于 AWS 的 Java SDK 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28684565/