Db4o adds additional flexibility to its reference system allowing the user to re-associate an object with its stored instance or to replace an object in database:
Java:
ExtObjectContainer#bind(object,id)
Typical usecases could be:
The following requirements should be met:
Calling ExtObjectContainer#bind(object,id) does not have any impact on persisted objects. It only attaches the new object to the database identity. ObjectContainer#set(object) should be used to persist the change.
Let's look how it works in practice.
01private static void testBind(){ 02
setObjects(); 03
ObjectContainer container = Db4o.openFile(DB4O_FILE_NAME); 04
try { 05
Query q = container.query(); 06
q.constrain(Car.class); 07
q.descend("model").constrain("Ferrari"); 08
ObjectSet result = q.execute(); 09
Car car1 = (Car)result.get(0); 10
long IdCar1 = container.ext().getID(car1); 11
Car car2 = new Car("BMW", new Pilot("Rubens Barrichello")); 12
container.ext().bind(car2,IdCar1); 13
container.set(car2); 14
15
result = container.query(Car.class); 16
listResult(result); 17
} finally { 18
container.close(); 19
} 20
}
So this method gives you control over internal object storage. But its usage is potentially dangerous and normally should be avoided. Use ExtObjectContainer#bind(object,id) only for short-lived objects and in controlled situations where no other references exist.