protected Object lookupRefValue(String _sRef, Object _oKey, String _sForeignKey)
      throws Exception {
    if (_oKey == null) return null;

    // to analyze
    int nPos = _sRef.indexOf('.');
    String sRefTable = _sRef.substring(0, nPos);
    String sRefField = _sRef.substring(nPos + 1);

    // to construct SQL
    String fk =
        (_sForeignKey != null && (_sForeignKey = _sForeignKey.trim()).length() > 0)
            ? _sForeignKey
            : "ID";
    String strSQL = "SELECT " + sRefField + " AS VALUE FROM " + sRefTable + " WHERE " + fk + "=";
    if (_oKey instanceof String) {
      strSQL += "'" + ((String) _oKey).trim() + "'";
    } else {
      strSQL += _oKey.toString().trim();
    }

    // to execute query
    ISession session = this.getSession();
    IStatement query = session.createQuery(strSQL, DolphinObject.class, 1);
    IObjects results = query.executeQuery();

    // to fetch the result
    DolphinObject result = results.next();
    results.clear();
    query.clear();

    // to return
    return result == null ? null : result.getProperty("VALUE");
  }
 private static void update0(int _nProductForm) throws PureException {
   IStatement query = null;
   IObjects result = null;
   try {
     int[] aValues = { //
       //            1964,//
       //                    1978, 1979,//
       //                    1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989,//
       1990,
       1991,
       1992,
       1993,
       1994,
       1995,
       1996,
       1997,
       1998,
       1999, //
       2000,
       2001,
       2002,
       2003,
       2004,
       2005,
       2006 //
     };
     IProductMgr mgr = (IProductMgr) ArkContentHelper.getContentMgrOf(Product.class);
     String strSQL =
         "SELECT {this.id},{this.serialNo},{this.publishDate} FROM {this}0 WHERE {this.productForm}="
             + _nProductForm
             + " AND year({this.publishDate})=?";
     for (int j = 0; j < aValues.length; j++) {
       query = mgr.createQuery(strSQL, 0);
       query.setInt(0, aValues[j]);
       result = query.executeQuery();
       int max =
           getMaxSerialNo(
               "SELECT MAX({this.serialNo}) AS _MAX FROM {this} WHERE {this.productForm}="
                   + _nProductForm
                   + " AND year({this.publishDate})="
                   + aValues[j]);
       //                int max=2005608586;
       int i = max;
       for (Iterator iter = result.iterator(); iter.hasNext(); i++) {
         Product product = (Product) iter.next();
         int nSerialNo = 0;
         if (max > 1) {
           nSerialNo = i;
         } else {
           nSerialNo = aValues[j] * 1000000 + 100000 * _nProductForm + i;
         }
         System.out.println(product.getId() + " : " + nSerialNo);
         product.setProperty("serialNo", nSerialNo);
         mgr.saveToTemp(product, false);
       }
     }
   } finally {
     DolphinHelper.clear(result, query);
   }
 }
  /**
   * @see com.pureinfo.importer.ref.IImportorRef#convert(com.pureinfo.dolphin.model.DolphinObject,
   *     com.pureinfo.dolphin.model.DolphinObject, java.lang.String, java.lang.String,
   *     com.pureinfo.dolphin.persister.ISession, com.pureinfo.dolphin.persister.ISession,
   *     com.pureinfo.dolphin.mapping.EntityMetadata, java.lang.String, java.lang.String)
   */
  public Object convert(
      DolphinObject _old,
      DolphinObject _new,
      String _sFromProperty,
      String _sToProperty,
      ISession _fromSession,
      ISession _toSession,
      EntityMetadata _metadata,
      String _sKey,
      String _sToTable)
      throws PureException {
    String sPrjNumber = _old.getStrProperty(_sFromProperty);
    Project project = null;
    IObjects projects = null;
    IStatement query = null;
    try {
      IProjectMgr mgr = (IProjectMgr) ArkContentHelper.getContentMgrOf(Project.class);
      query = mgr.createQuery("SELECT * FROM {this} WHERE {this.projectNumber}=?", 1);
      query.setString(0, sPrjNumber);
      projects = query.executeQuery();
      project = (Project) projects.next();
    } finally {
      DolphinHelper.clear(projects, query);
    }

    if (project != null) {
      _new.setProperty("bigChecked", true);
      return "1";
    }
    _new.setProperty("bigChecked", false);
    return "0";
  }
  /** Shows object list in page. */
  protected ActionForward doList() throws PureException {
    SearchForm thisform = (SearchForm) form;

    List colInfos = null;
    IObjects iobjs = null;
    List objList = null;
    Pager pager = new Pager();

    // 1. to fetch the objects in current page
    try {
      pager.setPageSize(thisform.getPageSize());
      pager.setCurrPageIndex(thisform.getPage());

      int nMaxSize = pager.getPageSize() * (pager.getCurrPageIndex() + 1);
      iobjs = getIObjects(nMaxSize);

      if (iobjs == null) {
        pager.setItemCount(0);
      } else {
        pager.setItemCount(iobjs.getSize());
        objList = iobjs.toList(pager);
      }
    } finally {
      if (iobjs != null) iobjs.clear();
    }

    // 2. to prepare the head titles
    if (objList != null && objList.size() > 0) {
      ListHelper lh = new ListHelper();
      lh.setSenery(getScenery());
      colInfos =
          lh.prepareColsInfo(
              thisform.getColunms(),
              getInclude(),
              getExclude(),
              getReplace(),
              thisform.getEntityMetadata().getName(),
              true);
      lh.clear();
    }

    // 3. to prepare the result in page
    String sTitle = getTitle();
    request.setAttribute("title", sTitle == null ? "ап╠М" : sTitle);
    request.setAttribute("headTable", getHeadTable());
    request.setAttribute("objs", objList);
    request.setAttribute("pager", pager);
    request.setAttribute("colInfos", colInfos);
    request.setAttribute("tailedButtons", getTailedButtons());
    request.setAttribute("metaDatas", thisform.getEntityMetadata().getProperties());
    request.setAttribute("submitee", getSubmitee());
    request.setAttribute("scenery", getScenery());
    request.setAttribute("needExport", new Boolean(isNeedExport()));
    request.setAttribute("needRowSelector", new Boolean(isNeedRowSelector()));
    if (isNeedSerial()) {
      request.setAttribute("needSerial", new Boolean(true));
    }
    return mapping.findForward("success");
  }
 private int getPublicationId(String _sISSN) throws PureException {
   IStatement query = null;
   IObjects result = null;
   try {
     IContentMgr mgr = ArkContentHelper.getContentMgrOf(Publication.class);
     final String strSQL = "SELECT * FROM {this} WHERE {this.publishCode}='" + _sISSN + '\'';
     query = mgr.createQuery(strSQL, 1);
     result = query.executeQuery();
     Publication publication = (Publication) result.next();
     if (publication != null) return publication.getId();
     return 0;
   } finally {
     DolphinHelper.clear(result, query);
   }
 }
 private static int getMaxSerialNo(String _sSQL) throws PureException {
   IStatement query = null;
   IObjects result = null;
   try {
     IProductMgr mgr = (IProductMgr) ArkContentHelper.getContentMgrOf(Product.class);
     query = mgr.createQuery(_sSQL, 0);
     result = query.executeQuery();
     Product product = (Product) result.next();
     if (product == null) {
       return 1;
     }
     return product.getIntProperty("_MAX", 0) + 1;
   } finally {
     DolphinHelper.clear(result, query);
   }
 }
  public void testQuery() throws PureException {
    InstituteService service = new InstituteService();
    String name = null;
    try {
      name = new String(("¾­¼Ã").getBytes("iso-8859-1"), "utf-8");
    } catch (Exception ex) {
      ex.printStackTrace(System.err);
    }

    System.out.println(name);
    IObjects institutes = service.queryByName("¾­¼Ã", "6", null);
    System.out.println("size: " + institutes.getSize());
    for (int i = 0; i < institutes.getSize(); i++) {
      System.out.println(((Institute) institutes.next()).getName());
    }
  }
 private static void update3index() throws PureException {
   IStatement query = null;
   IObjects result = null;
   try {
     int[] aValues = { //
       //            1964,//
       //                    1978, 1979,//
       //                    1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989,//
       1990,
       1991,
       1992,
       1993,
       1994,
       1995,
       1996,
       1997,
       1998,
       1999, //
       2000,
       2001,
       2002,
       2003,
       2004,
       2005,
       2006 //
     };
     IProductMgr mgr = (IProductMgr) ArkContentHelper.getContentMgrOf(Product.class);
     String strSQL =
         "SELECT {this.id},{this.serialNo} FROM {this} WHERE {this.productForm}=3 AND {this.indexIndexDate}=?";
     for (int j = 0; j < aValues.length; j++) {
       query = mgr.createQuery(strSQL, 0);
       query.setInt(0, aValues[j]);
       result = query.executeQuery();
       int i = 1;
       for (Iterator iter = result.iterator(); iter.hasNext(); i++) {
         Product product = (Product) iter.next();
         int nSerialNo = aValues[j] * 1000000 + 300000 + i;
         System.out.println(product.getId() + " : " + nSerialNo);
         product.setProperty("serialNo", nSerialNo);
         mgr.save(product);
       }
     }
   } finally {
     DolphinHelper.clear(result, query);
   }
 }
  public Object convert(
      DolphinObject _old,
      DolphinObject _new,
      String _sFromProperty,
      String _sToProperty,
      ISession _fromSession,
      ISession _toSession,
      EntityMetadata _metadata,
      String _sKey,
      String _sToTable)
      throws PureException {
    // TODO Auto-generated method stub
    int nImportType = Integer.parseInt(_sToProperty);

    // ¼ì²â
    if (Xls2srmForm.JUSTFORCHECK == nImportType) return null;

    String value = _old.getStrProperty(_sFromProperty);
    if (value != null && !"".equals(value.trim())) {
      IUserMgr mgr = (IUserMgr) ArkContentHelper.getContentMgrOf(SRMUser.class);
      SRMUser user = null;
      IObjects users = null;
      IStatement query = null;
      try {
        query =
            mgr.createQuery(
                "SELECT {this.trueName} FROM {this} WHERE {this.employeeSId}=? and {this.name}=? and {this.status}<>32",
                1);
        query.setString(0, value.trim());
        query.setString(1, value.trim());
        users = query.executeQuery(false);
        user = (SRMUser) users.next();
      } finally {
        DolphinHelper.clear(users, query);
      }

      if (user != null) {
        System.out.println("--------------------------------------------");
        System.out.println("TrueName:" + user.getTrueName());
        System.out.println("---------------------------------------------");
        return user.getTrueName();
      }
    }
    return "";
  }
 private int getAuthorId(String _sAuthorName) throws PureException {
   IStatement query = null;
   IObjects result = null;
   try {
     ISRMUserMgr userMgr = (ISRMUserMgr) ArkContentHelper.getContentMgrOf(SRMUser.class);
     // 1. formal table
     String strSQL = "SELECT * FROM {this} WHERE {this.trueName}=?";
     query = userMgr.createQuery(strSQL, 1);
     query.setString(0, _sAuthorName);
     result = query.executeQuery();
     SRMUser user = (SRMUser) result.next();
     if (user != null) return user.getId();
     // 2. temp table
     strSQL = "SELECT * FROM {this}0 WHERE {this.trueName}=?";
     query = userMgr.createQuery(strSQL, 1);
     query.setString(0, _sAuthorName);
     result = query.executeQuery();
     user = (SRMUser) result.next();
     if (user != null) return user.getId();
     return 0;
   } finally {
     DolphinHelper.clear(result, query);
   }
 }
  /**
   * @see com.pureinfo.importer.ref.IImportorRef#convert(com.pureinfo.dolphin.model.DolphinObject,
   *     com.pureinfo.dolphin.model.DolphinObject, java.lang.String, java.lang.String,
   *     com.pureinfo.dolphin.persister.ISession, com.pureinfo.dolphin.persister.ISession,
   *     com.pureinfo.dolphin.mapping.EntityMetadata, java.lang.String, java.lang.String)
   */
  public Object convert(
      DolphinObject _old,
      DolphinObject _new,
      String _sFromProperty,
      String _sToProperty,
      ISession _fromSession,
      ISession _toSession,
      EntityMetadata _metadata,
      String _sKey,
      String _sToTable)
      throws PureException {
    String sAdminName = _old.getStrProperty(_sFromProperty);
    if (sAdminName == null) return null;
    String sDeptCode = _old.getStrProperty("单位代码");
    _new.setProperty("firstAuthorName", sAdminName);

    IObjects users = null;
    IStatement query = null;
    SRMUser user = null;
    int nUserId = 0;
    try {
      ISRMUserMgr userMgr = (ISRMUserMgr) ArkContentHelper.getContentMgrOf(SRMUser.class);
      query =
          userMgr.createQuery(
              "SELECT * FROM {this} WHERE {this.trueName}=?", DolphinConstants.MAXSIZE_UNLIMITED);
      query.setString(0, sAdminName);
      users = query.executeQuery();
      SRMUser[] aUsers = (SRMUser[]) users.toList().toArray(new SRMUser[0]);
      if (aUsers.length == 0) {
        nUserId = 0;
      } else if (aUsers.length == 1) {
        user = aUsers[0];
        nUserId = user.getId();
      } else {
        if (sDeptCode == null) {
          sDeptCode = _old.getStrProperty("字段1");
        }
        String sCollege = sDeptCode.substring(0, 2);
        for (int i = 0; i < aUsers.length; i++) {
          Organization org = aUsers[i].getDepartment();
          String sCode = null;
          if (org != null) sCode = org.getCode();
          if (sCode != null && sCode.length() > 2) sCode = sCode.substring(0, 2);
          if (sCode != null && sCode.equals(sCollege)) {
            user = aUsers[i];
            nUserId = user.getId();
            break;
          }
        }
        if (user == null) {
          logger.error(_old.getStrProperty("成果名称") + "," + _old.getStrProperty("负责人"));
          user = aUsers[0];
          nUserId = user.getId();
        }
      }
      LocalContextHelper.currentSession().autoGenerateProperty(_new, "id");
      int nProductId = _new.getIntProperty("id", -1);
      ObjUserMapping author = new ObjUserMapping();

      author.setObjType(SRMTypes.PRODUCT);
      author.setUserType("1");
      author.setUserId(nUserId);
      author.setUserName(sAdminName);
      author.setOrderNo(1);
      author.setObjId(nProductId);
      author.setWeightYear(WeightConstants.WEIGHT_YEAR_DEFAULT_VALUE);

      IObjUserMappingMgr puMgr =
          (IObjUserMappingMgr) ArkContentHelper.getContentMgrOf(ObjUserMapping.class);
      puMgr.save(author);
    } finally {
      DolphinHelper.clear(users, query);
    }
    return "" + nUserId;
  }
  /** Exports object list. */
  protected ActionForward doExport() throws PureException {
    SearchForm thisform = (SearchForm) form;
    IObjects exObjs = null;
    try {
      // 1. to fetch the objects collection
      if (thisform.getExportMode() == SearchForm.EX_MODE_SELECTED
          && thisform.getExportIds() != null) {
        Class entityClass = thisform.getEntityMetadata().getEntityClass();
        IContentMgr mgr = ArkContentHelper.getContentMgrOf(entityClass);
        if (!isFromTemp()) {
          exObjs = mgr.lookupByIds(thisform.getExportIds());
        } else {
          String strSQL =
              "SELECT * FROM "
                  + thisform.getEntityMetadata().getTempTable()
                  + " WHERE {this.id} IN ("
                  + thisform.getExportIds()
                  + ")";
          ISession session = LocalContextHelper.currentSession();
          IStatement query = session.createQuery(strSQL, entityClass, 0);
          try {
            exObjs = query.executeQuery();
          } finally {
            query.clear();
          }
        }
      } else {
        exObjs = getIObjects();
      }

      // 2. to prepare the columns
      ListHelper lh = new ListHelper();
      lh.setSenery(getScenery());
      List baseCols = thisform.getColunms();
      String sClassName = exObjs.getElementClass().getName();
      if (baseCols == null || baseCols.size() < 1) {
        baseCols = lh.prepareBase(exObjs.getElementClass().getName());
      }

      lh.setSenery(getExportSenery());
      lh.setAct("content");

      List colInfos =
          lh.prepareColsInfo(baseCols, getInclude(), getExclude(), null, sClassName, false);
      String[] headers = new String[colInfos.size()];
      String[] properties = new String[colInfos.size()];
      SceneryContext sceneryContext = null;
      try {
        boolean bUsePropertyName = (thisform.getExportType() == ExportHelper.TYPE_XML);
        String sHeader;
        for (int i = 0; i < colInfos.size(); i++) {
          ColumnInfo colInfo = (ColumnInfo) colInfos.get(i);
          if (bUsePropertyName) {
            sHeader = colInfo.getOldName();
          } else {
            sHeader = colInfo.getTitle();
            if (sHeader.indexOf('$') >= 0) {
              if (sceneryContext == null) {
                IDVContextFactory factory =
                    (IDVContextFactory) PureFactory.getBean("IDVContextFactory");
                DolphinObject obj = (DolphinObject) exObjs.getElementClass().newInstance();
                sceneryContext =
                    factory.createSceneryContext(obj, getExportSenery(), "plain.default");
              }
              sHeader = Executer.execute(ScriptReader.readBlock(sHeader), sceneryContext);
            }
          }
          headers[i] = sHeader.replaceAll("[\\\\\\[\\]\\?/<>]+", "_");
          properties[i] = colInfo.getName();
        }
      } catch (Exception ex) {
        throw new PureException(ArkExceptionTypes.EXPORT_CONTENTS, "failed to get the headers", ex);
      } finally {
        if (sceneryContext != null) {
          sceneryContext.clear();
        }
        colInfos.clear();
      }

      // 3. to prepare the data
      IConvertor convertor = new ExportConvertor(getExportSenery(), "content");
      DolphinExportGoods goods = new DolphinExportGoods();
      goods.setType(thisform.getExportType());
      goods.setName(getTitle());
      goods.setHeaders(headers);
      goods.setData(exObjs, properties, convertor);

      // 4. to return
      request.setAttribute("export", goods);
      return mapping.findForward("guest-export");
    } finally {
      LocalContextHelper.closeSession();
    }
  }