The following methods will delete a car with a pilot having 5 points from each database:
SQLiteDatabase db = database(); db.delete(DB_TABLE_CAR, "pilot in (select id from pilot where points = ?)", new String[]{"5"});
ObjectContainer db = database(); ObjectSet<Car> cars = db.query(new Predicate<Car>() { public boolean match(Car car) { return car.getPilot().getPoints()==5; } }); for(Car car : cars){ db.delete(car); }
In this example db4o code looks much longer. But should we consider it a disadvantage? My opinion is - No. Of course, SQLite seems to handle the whole operation in just one statement: db.delete(). But if you look attentively you will see that basically this statement just transfers all the difficult job to SQL: SQL statement should select a pilot with a given condition, then find a car. Using SQL can look shorter but it has a great disadvantage - it uses strings. So what will happen if the statement is wrong? You will never notice it till somebody in the running application will cause this statement to execute. Even then you might not see the reason immediately. The same applies to the schema changes - you may not even notice that you are using wrong tables and fields.
db4o helps to avoid all the above mentioned problems: query syntax is completely compile-checked and schema evolution will be spotted immediately by the compiler, so that you would not need to rely on code search and replace tools.