views:

44

answers:

1

I have a data model with a skeleton (metadata) and large data objects. I'd like to keep the skeleton in memory and hold weak references to the data objects. I understand how I would implement this with plain Java, how I would create a WeakHashMap and clean up etc. But I'm wondering what would be the best way to resurrect the data objects after they have been GC'd?

Should I add a technical key to my map which I assign to a field in the data object, so I can find it again? Or should I call db.ext().getId() and use this ID as the technical key? If so, how would I get these keys when loading the parent? What do you suggest?

A: 

I would add a technical key to your large data-object. Then you store this technical key in your meta-data-class. Now on when you get the large data-object you get it by it's technical key. That quite a simple solution.

Db4o actually uses weak references to return the same object and avoid unnecessary deserialisation. So when you ask for a object and hasn’t been collected by the GC, db4o will return the same object.

Gamlor
Just to make sure: that means I can't use some magic relation between the metadata and the children (like "find all items which once were in this list")?
Aaron Digulla
As far as I know there isn't such a thing. I think it’s possible to build something like this. But I haven’t tried I yet. The idea is to implement a db4o-aware class which represents such a reference. With some clever tricks with callbacks and activation you could achieve it.
Gamlor