使用 isEmpty() 检查 JDO 查询是否安全?什么是“正确的”?方式?

发布于 2025-01-07 20:34:50 字数 584 浏览 5 评论 0原文

根据文档此处(在“唯一结果”下)和这里,一个JDO“默认”查询结果将返回一个List,和一个“ unique”指定的查询如果满足则返回 null是空的。

那么我可以安全地使用 .isEmpty() 来检查我是否获得了正常查询的行吗?同样,对于查询被标记为“唯一”的情况,我是否应该使用 == null

我测试过,空结果确实返回一个 .size()0 的列表。所以看来 NullPointerException 的唯一危险在于“唯一”查询。

我还应该采取哪些其他预防措施(如果有)?我只用这两种类型的支票就能满足我的基本要求吗?几乎正在寻找一些最佳实践建议以及任何潜在的问题。我对 Java 和 JDO/ORM 持久性都很陌生。

谢谢

According to the documentation here (under "unique results") and here, A JDO "default" query result will return a List, and a "unique" specified query returns null if they are empty.

So am I safe to just use .isEmpty() to check that I got rows for a normal query? Likewise for those times that a query is marked "unique", should I just use == null?

I tested and a empty result does indeed return a List with .size() of 0. So it seems my only danger of a NullPointerException lies with a "unique" query.

What other precautions should I take (if any)? Do I cover my bases acceptably with just those two types of checks? Pretty much looking for some best practice advice, and any potential gotcha's. I am pretty novice with both Java and JDO/ORM persistence.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

澜川若宁 2025-01-14 20:34:50

正确的方法?列表就是一个具有 Java 契约 (API) 的列表。 JDO 并没有改变这一点。 JDO 规范(和 DN 文档)还定义了查询的结果形式
http://www.datanucleus.org/products/accessplatform_3_0/jdo/jdoql_result.html

Right way ? A List is a List and that has a Java contract (API). JDO doesn't change that. Also the JDO spec (and DN docs) define what form of result comes from a query
http://www.datanucleus.org/products/accessplatform_3_0/jdo/jdoql_result.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文