jointable 的用法

前任从来没有用过jointable, 官方的例子也少得可怜,先贴上一段代码

IDataQuery dq1 = session.createDataQuery();
       dq1.setTarget(session.getObjectDef("PMSF")); 
          dq1.addFilter("hs_is_deleted", SATConstants.SQL_OP_EQUAL, "0");
          IJoinTable jt1 = dq1.addJoinTable("p_prerequirements");
       
       jt1.addDisplayField("hs_uuid");
     
          IDataCollection dc1 = dq1.query(session);
          int test = 0;
         
          while (dc1.next()){
           IBusObject bus = dc1.getObject();
           
           addedreq.add(bus.getStringField("hs_uuid.secondary_obj_uuid.hs_uuid"));
           //System.out.print("PREID:"+bus.getStringField("hs_uuid.secondary_obj_uuid.hs_uuid")+",");
           //test++;
          }
        

p_prerequirements字段为multireference字段,引用了某个sfo。说下关键的:

jt1.addDisplayField("hs_uuid");这个方法最后生成的bo中的对应字段为hs_uuid.secondary_obj_uuid.hs_uuid 这个名称,满怪异的。

即hs_uuid.secondary_obj_uuid.xxxxx这种名称。

 

 single reference  字段的jointable 用法也类似,eg:

IDataQuery dq1 = session.createDataQuery();
       dq1.setTarget(session.getObjectDef("PMSF")); 
          dq1.addFilter("hs_is_deleted", SATConstants.SQL_OP_EQUAL, "0");
          IJoinTable jt1 = dq1.addJoinTable("hs_owner");
       
       jt1.addDisplayField("hs_uuid");
     
          IDataCollection dc1 = dq1.query(session);
那么join user表后的字段为 hs_owner.hs_uuid

 

最后贴上同事写的一段代码结束

  IJoinTable joinTable = dq1.createJoinTable();

                            joinTable.setJoinType(SATConstants.INNER_JOIN);

                            IObjectDef child = session.getObjectDef("S_project");

                            joinTable.setJoinObjectDef(child);

                            joinTable.setMainField("T_project_gid");

                            joinTable.setJoinField("hs_uuid");

                            joinTable.addFilter("hs_is_deleted", SATConstants.SQL_OP_EQUAL, "0");

                         joinTable.addDisplayField("S_project_name","S_project_name"); //这句意思就是select fielda as  XXXX的意思

                            dq1.addJoinTable(joinTable);

 

你可能感兴趣的:(Butterfly,API)