Data Preparation

First of all we will need to prepare some data for the report. Let's use a simple Pilot class:

Pilot.java
01public class Pilot { 02 private String name; 03 private int points; 04 05 public Pilot(String name, int points){ 06 this.name = name; 07 this.points = points; 08 } 09 10 public String getName(){ 11 return name; 12 } 13 14 public int getPoints(){ 15 return points; 16 } 17 18}

The following method should be called to fill up the database with some sample data:

Db4oModule.java: storeData
01public void storeData() { 02 new File(DB_FILE).delete(); 03 ObjectContainer container = Db4o.openFile(DB_FILE); 04 try { 05 Pilot pilot = new Pilot("Michael Schumacher", 100); 06 container.set(pilot); 07 pilot = new Pilot("Rubens Barrichello", 99); 08 container.set(pilot); 09 pilot = new Pilot("Kimi Raikonnen", 100); 10 container.set(pilot); 11 } finally { 12 container.close(); 13 } 14 }

For the table representation we will need a list of values:

Db4oModule.java: readData
01public List readData() { 02 ObjectContainer container = Db4o.openFile(DB_FILE); 03 List result = new ArrayList(); 04 try { 05 ObjectSet pilots = container.query(Pilot.class); 06 while (pilots.hasNext()) { 07 Pilot pilot = (Pilot) pilots.next(); 08 result.add(new String[] { pilot.getName(), 09 String.format("%3d", pilot.getPoints()) }); 10 } 11 } finally { 12 container.close(); 13 } 14 return (result); 15 }