简体   繁体   English

db4o和对象标识

[英]Db4o and object identity

I'm learning db4o data base, I'm planing to use it 3-tier project. 我正在学习db4o数据库,我打算将其用于3层项目。

I don't fully understand the concept of object identity in db4o. 我不完全了解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. 我从数据库中加载了类型为User的对象,并将其所有成员更改为新实例。 How Db4o will determine what to do with members, when to update (replace) and when to store new instance of them? Db4o将如何确定如何处理成员,何时更新(替换)以及何时存储成员的新实例?

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 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? 我们可以假定它删除了孤立的对象(任何人都没有引用过),但是对于root用户对象,任何人都没有引用过,如果我存储了纯DateTime对象或Int32对象呢? Will it flag such explicitly stored object from beeing "GarbageCollected"? 是否会从“ 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. db4o使用对象标识来确定何时需要插入/更新对象。 Basically it keeps a list of all objects seen during a session (using RuntimeHelpers.GetHashCode() ). 基本上,它保留了会话期间可见的所有对象列表 (使用RuntimeHelpers.GetHashCode() )。 When Store() is called db4o simply scan this list looking for a match; 当调用Store()db4o时,只需扫描此列表以查找匹配项; 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. 关于有关“孤立”对象的问题, db4o没有 “垃圾收集器”,因此由开发人员决定删除不再使用的对象。

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; 专门讨论您在问题中提到的类型,字符串和日期时间将被嵌入在父插槽中(它们没有ID),因此在删除其父级时将收回存储它们所需的空间; TimeSpan objects will be stored normally (ie, will have id and so developers need to remove them). TimeSpan对象将正常存储(即具有ID,因此开发人员需要删除它们)。

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 :). 基本上,db4o将嵌入所有原始类型以及通过类型处理程序编组的任何类型,该类型处理程序在对象的父插槽中实现IValueTypeHandler(这不是漏洞,而是一个很好的近似方法:)。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM