Working With Structured Objects

In real world objects are referenced by each other creating deep reference structures.

This chapter will give you an overview of how db4o deals with structured objects.

For an example we will use a simple model, where Pilot class is referenced from Car class.

Pilot.java
01package com.db4odoc.f1.structured; 02 03 04public class Pilot { 05 private String name; 06 private int points; 07 08 public Pilot(String name,int points) { 09 this.name=name; 10 this.points=points; 11 } 12 13 public int getPoints() { 14 return points; 15 } 16 17 public void addPoints(int points) { 18 this.points+=points; 19 } 20 21 public String getName() { 22 return name; 23 } 24 25 public String toString() { 26 return name+"/"+points; 27 } 28}
Car.java
01package com.db4odoc.f1.structured; 02 03public class Car { 04 private String model; 05 private Pilot pilot; 06 07 public Car(String model) { 08 this.model=model; 09 this.pilot=null; 10 } 11 12 public Pilot getPilot() { 13 return pilot; 14 } 15 16 public void setPilot(Pilot pilot) { 17 this.pilot = pilot; 18 } 19 20 public String getModel() { 21 return model; 22 } 23 24 public String toString() { 25 return model+"["+pilot+"]"; 26 } 27}