- 论坛徽章:
- 0
|
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 |
|