简体   繁体   English

数据存储-具有自己类型的Java类

[英]Datastore - Java class having its own type

I want to create a class type that has n-children of same type and one parent of same type as members. 我想创建一个具有n个相同类型的子代和一个相同类型的父代作为成员的类类型。 Every child class will have n-children and one parent. 每个孩子班将有n个孩子和一个父母。 If I persist this model in datastore, will it be costly resource wise? 如果我将这种模型保存在数据存储区中,会不会是昂贵的资源明智的选择? Because each child has n-children and so on. 因为每个孩子都有n个孩子,依此类推。

Say, 说,

@PersistenceCapable
public class Human {

    @Persistent
    List<Human> children;

    @Persistent
    Human parent;

    //the getters and setters
    //null checks
    //add child to list
    //add parent
}

public class Test {
    public static void main(String[] args){
    Human parentHuman = new Human();
    Human childHuman = new Human();

    parentHuman.addChild(childHuman);
    childHuman.addParent(parentHuman);

    Human newChildHuman = new Human();
    newChildHuman.addParent(childHuman);
    newChildHuman.addChild(//another child);
    }
}

I must also be able to get the number of children a human object has at any point of time and also the number of children of their children. 我还必须能够获得在任何时间点物体所拥有的孩子数量,以及他们孩子的孩子数量。

So will storing this type in Datastore create new entities for every child or will it refer to entity of the human object and reuse it? 那么,将这种类型存储在数据存储区中会为每个孩子创建新的实体,还是会引用人类对象的实体并重用它?

If my question is not explanatory enough I can put some more light into my question. 如果我的问题不够解释,我可以进一步阐明我的问题。 Any help/suggestion would be much appreciated. 任何帮助/建议将不胜感激。 Thanks 谢谢

The answer, in general, is that no, as long as you are using keys to establish relationships between entities, you will be safe from unnecessary inline duplication. 答案通常是,不,只要您使用密钥在实体之间建立关系,就可以避免不必要的内联重复。 Always use keys for entity relationships. 始终对实体关系使用键。 For JDO, the specifics can be found here. 对于JDO,可以在此处找到详细信息。

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

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