免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2403 | 回复: 0
打印 上一主题 下一主题

DB4O学习(三)对象的查询 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-01-23 10:22 |只看该作者 |倒序浏览

1.三种查询方式
  (1)QBE--只能精确查找
  (2)Simple Object Data Access(SODA)--DB4O的一套查询API
  (3)Native Queries(NQ)--调整查询以达到更高的查询速度

2.三种查询方式的对比


3.QBE的几种方式:
(1)通过构造器指定参数
Person template = new Person();
template.setName("Ben");
ObjectSet res = db.get(template);
(2)通过setter指定参数
Person template = new Person();
template.setName("Ben");
template.setAge(42);
ObjectSet res = db.get(template);
(3)其他方法
Person template = new Person(null, 82);   // match age only Person template = new Person("Ben", 0);   // match name only
Person template = new Person(null, 0);    // ensure an empty template

(4)指定类型
ObjectSet res = db.get(Person.class);   // JAVA
(5)获取全部类型
ObjectSet res = db.get(null);   // JAVA

4.QBE的几个问题
• You can’t use the values that are defined to mean “empty” as constraints. Fields specified
as null, 0, or "" (empty string) are treated as unconstrained, which could be a problem
in some cases. For example, what if you actually want to find Person objects with _age
equal to 0? You can’t when using QBE.
如果想查找age为0的person则不能用QBE.
• You might run into problems if your classes initialize fields when they are declared. For
example, what if the Person class initializes the attribute string _name = "Joe"? In that
case, a query that uses the default constructor to create an “empty” template will only
return “Joe” objects. To get a truly empty template, you would have to explicitly set the
_name attribute to null.
对于类内部初始化的情况要特别注意初始化的值。


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/93829/showart_2158286.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP