开发者

Db4o and object identity

I'm learning db4o data base, I'm planing to use it 3-tier project.

I don't fully understand the concept of object identity in db4o.

Suppose we have a class like this:

public class User
{
    public Guid Id;
    public String SomeString;
    public Int64 SomeInt;
    public DateTime SomeDate;
    public DateTimeOffset SomeDateOffset;
    public TimeSpan SomeTimeSpan;
    public User SomeUser;
}

I have load object of type User from the DB and changed all it's members to new instances. How Db4o will determine what to do with members, when to update (replace) and when to store new instance of them?

According to manual and identity concept, my root object reference remains the same so the root object is updates, all member objects have a new reference so it inserts new instances of them, but in开发者_StackOverflow this case we have a space leak, old instances of types String, DateTime, TimeSpan, User etc remains in DB.

We can assume that it deletes objects that get orphaned (is not referenced by anyone), but what about root User object it's not referenced by anyone, what if I have stored pure DateTime object or Int32 object? Will it flag such explicitly stored object from beeing "GarbageCollected"? This is all just my assumtions, can someone explain how this actually all works?


db4o uses object identity to figure out whenever it needs to insert/update objects. Basically it keeps a list of all objects seen during a session (using RuntimeHelpers.GetHashCode()). When Store() is called db4o simply scan this list looking for a match; if a match is found then the object is updated, otherwise a new object is stored. Note that this operation will be executed recursively (up to the configured update depth).

Regarding your question about "orphan" objects, db4o does not have a "garbage collector" so its up to the developer to delete objects that are not used anymore.

Talking specifically about the types you mentioned in your question, string and DateTime will be stored embedded in the parent slot (they will not have an id), so the space required to store them will be reclaimed when it's parent is deleted; TimeSpan objects will be stored normally (i.e, will have id and so developers need to remove them).

Basically db4o will embed all primitive types plus any type marshalled through a typehandler that implements IValueTypeHandler in the object's parent slot (this is not the hole story but is a good approximation :).

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜