> -----Original Message-----
> From: Matthew Toseland [mailto:toad at amphibian.dyndns.org]
> Sent: Tuesday, December 16, 2008 4:55 PM
> To: xor
> Subject: Re: I need help with Db4o / Freetalk
>
> On Tuesday 16 December 2008 12:10, you wrote:
> >
> > Okay I did the following:
> >
> > - Remove the code which enables cascade on update. It is
> disabled by
> > default, right?
>
> Yes IIRC.
> >
> > - Make all Freetalk objects store() their non-primitive
> member objects
> > on their own.
>
> Yes.
> >
> > - class Message does not store(mAuthor) because the identities are
> > stored by the WoTIdentityManager. It does store(this) which should
> > store the mAuthor reference but not the referenced object
> itself, right?
>
> It should store both the first time if the author object
> hasn't been stored.
Authors are received by a separate thread, i.e. message retrieval happens
when authors are already stored. This is necessary because due to the
web of trust we need to know the author so we can download messages of
him.
> After that, it won't store updates to the author object
> (unless the pointer itself changes to point to a new author).
> >
> > - Add the following code to class Message:
> >
> > public void store() {
> > /* FIXME: Check for duplicates */
> > if(db.ext().isStored(this) && !db.ext().isActive(this))
> > throw new RuntimeException("Trying to store a
> non-active Message
> > object");
> >
> > if(mAuthor == null)
> > throw new RuntimeException("Trying to store a
> message with mAuthor
> > == null");
> >
> > .......
> > ...
> > }
>
> You always call Message.store() when storing an author?
The author is passed to the constructor of the message, construction
of messages without author is not possible. So the answer is yes.
> > public FTIdentity getAuthor() {
> > db.activate(this, 3);
> > if(mAuthor == null)
> > throw new RuntimeException("mAuthor == null");
> > .....
> > ...
> > }
> >
> > Now the following happens: None of the RuntimeException in
> store() is
> > thrown, so the Message objects are definitely stored with
> mAuthor != null.
> > However, getAuthor() throws because mAuthor == null.
> >
> > Now this is weird!
>
> Indeed! Implement the callback I mentioned, it should make
> things clear:
>
> public void objectOnUpdate(ObjectContainer db) { if(mAuthor
> == null) throw new RuntimeException("Argh!"); }
>
> public void objectOnNew(ObjectContainer db) { objectOnUpdate(db); }
I added the callbacks to the messages, they do not throw exceptions
so mAuthor is not null and they DO get called, I added logging for that.
WEIRD.