如果在父实体上执行插入操作,将计算多少写操作?

时间:2014-07-01 16:53:21

标签: google-app-engine jpa google-cloud-datastore google-cloud-endpoints

我正在使用云端点处理谷歌云数据存储。我使用JPA注释在Department和Employee之间创建了Owned One-to-Many关系。实体是:

Department(Parent)
   String Id
   String Name
   List Employee(@OneToMany)

Employee(Child)
   Key key
   String firstName
   String lastName
   String Address
   Department dept(@ManyToOne)

插入操作的代码是:

    Departmentendpoint dptendpoint=null;
    Departmentendpoint.Builder builder1 = new Departmentendpoint.Builder(AndroidHttp. 
                          newCompatibleTransport(), new JacksonFactory(), null);
    dptendpoint = CloudEndpointUtils.updateBuilder(builder1).build();

    Department dpt = new Department();
    dpt.setId("Dept1");
    dpt.setName("Safety");

    List<Employee> m = new ArrayList<Employee>(); 

    Employee mgr= new Employee();
    mgr.setFirstName("Devwrat");
    mgr.setLastName("Lad");
    mgr.setParentId(dpt.getId());
    mgr.setAddress("Mumbai");
    m.add(mgr);

    Employee mgr2= new Employee();
    mgr2.setFirstName("Avinash");
    mgr2.setLastName("Patel");
    mgr2.setParentId(dpt.getId());
    mgr2.setAddress("Surat");
    m.add(mgr2);

    dpt.setManager(m);
    try{
        dptendpoint.insertDepartment(dpt).execute();
    }catch(IOException e) {
        e.printStackTrace();
    }

问题

如果我进行插入查询&#34; dptendpoint.insertDepartment(dpt).execute()&#34;在父实体上将执行多少写操作?

提前致谢!!!!

1 个答案:

答案 0 :(得分:1)

我向谷歌频道合作伙伴提出了同样的问题并得到了以下回复。

It will be like inserting into two entities.

所以基本上对“”dptendpoint.insertDepartment(dpt).execute()的总写操作“查询将是:20写操作。这解释如下:

For Department Entity:
     1 (for the entity itself) + 1 (for the EntitiesByKind index) + 2 * 3(for indexed property) + 1 * 0 (for composite index) = 8 write operation

For Employee Entity
     1 (for the entity itself) + 1 (for the EntitiesByKind index) + 2 * 5(for indexed property) + 1 * 0 (for composite index) = 12 write operation