- 論壇徽章:
- 0
|
1.三種查詢方式
(1)QBE--只能精確查找
(2)Simple Object Data Access(SODA)--DB4O的一套查詢API
(3)Native Queries(NQ)--調整查詢以達到更高的查詢速度
2.三種查詢方式的對比
![]()
3.QBE的幾種方式:
(1)通過構造器指定參數(shù)
Person template = new Person();
template.setName("Ben");
ObjectSet res = db.get(template);
(2)通過setter指定參數(shù)
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 |
|