Chinaunix首页 | 论坛 | 博客
  • 博客访问: 188232
  • 博文数量: 106
  • 博客积分: 3810
  • 博客等级: 中校
  • 技术积分: 1007
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-18 13:35
文章分类

全部博文(106)

文章存档

2014年(17)

2011年(5)

2010年(75)

2009年(9)

我的朋友

分类: Java

2010-01-23 10:22:15

1.三种查询方式

  (1)QBE--只能精确查找

  (2)Simple Object Data Access(SODA)--DB4O的一套查询API

  (3)Native Queries(NQ)--调整查询以达到更高的查询速度

 

2.三种查询方式的对比

image

 

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.

对于类内部初始化的情况要特别注意初始化的值。

阅读(315) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~