2

我想为 dataimporthandler 制作一个自定义转换器。我想访问父实体的行。我怎样才能做到这一点。可能吗?

  @Override
  public Object transformRow(Map<String, Object> row, Context context) {

    LOG.info("##gyk: row: {}",row);

    //******What to do here? ********
    LOG.info("##gyk: PARENT-ROW: {}", ????);


    return row;
  }

更新

我目前的解决方法是使用会话变量

  @Override
  public Object transformRow(Map<String, Object> row, Context context) {

    if (context.isRootEntity()) {

      Object tmp = row.get("Keywords");
      if (tmp == null) return row;

      String[] kwArray = tmp.toString().split(",");

      HashSet<String> kwSet = new HashSet<String>(64);

      for (String kw : kwArray) {
        kwSet.add(kw.trim().toLowerCase());
      }
      LOG.info("##gyk: root entity kw: {}",kwSet);

      context.setSessionAttribute("company-keywords-set", kwSet, "document");

    } else {
      LOG.info("##gyk: row: {}",row);

      HashSet<String> companyKeywordSet = (HashSet<String>)context
          .getParentContext().getParentContext()
          .getSessionAttribute("company-keywords-set", "document");

      if (companyKeywordSet != null) {
        LOG.info("##gyk: keywords from parent: {}", companyKeywordSet);
      }

    }

    return row;
  }

更新

当我尝试记录这个context.getParentContext().getParentContext().getAllEntityFields()时,我得到以下信息: [{multiValued=false, toWrite=true, indexed=true, name=id, column=FIR_NR, boost=1.0, defaultValue=null, stored=true, type=string}, {multiValued=false, toWrite=true, indexed=true, name=fir_name, column=FIR_NAME, boost=1.0, defaultValue=null, stored=true, type=text_general}]

这些只是该实体的字段定义。

4

0 回答 0