01: package com.db4o.f1.chapter6;
02:
03: import java.io.*;
04:
05: import com.db4o.*;
06: import com.db4o.f1.*;
07: import com.db4o.f1.chapter3.*;
08: import com.db4o.query.*;
09:
10: public class EvaluationExample extends Util {
11: public static void main(String[] args) {
12: new File(Util.DB4OFILENAME).delete();
13: ObjectContainer db = Db4o.openFile(Util.DB4OFILENAME);
14: try {
15: storeCars(db);
16: queryWithEvaluation(db);
17: } finally {
18: db.close();
19: }
20: }
21:
22: public static void storeCars(ObjectContainer db) {
23: Pilot pilot1 = new Pilot("Michael Schumacher", 100);
24: Car car1 = new Car("Ferrari");
25: car1.setPilot(pilot1);
26: car1.snapshot();
27: db.set(car1);
28: Pilot pilot2 = new Pilot("Rubens Barrichello", 99);
29: Car car2 = new Car("BMW");
30: car2.setPilot(pilot2);
31: car2.snapshot();
32: car2.snapshot();
33: db.set(car2);
34: }
35:
36: public static void queryWithEvaluation(ObjectContainer db) {
37: Query query = db.query();
38: query.constrain(Car.class);
39: query.constrain(new EvenHistoryEvaluation());
40: ObjectSet result = query.execute();
41: Util.listResult(result);
42: }
43: }
|