/**
  * In case value is null or an empty string the defValue is returned
  *
  * @param value
  * @param defValue
  * @param errorMsgOnParseFailure
  * @return the converted int.
  * @throws SearchException if value can't be parsed.
  */
 public static final int parseInt(String value, int defValue, String errorMsgOnParseFailure) {
   if (StringHelper.isEmpty(value)) {
     return defValue;
   } else {
     return parseInt(value, errorMsgOnParseFailure);
   }
 }
 /**
  * Build a directory name out of a root and relative path, guessing the significant part and
  * checking for the file availability
  *
  * @param directoryProviderName
  * @param properties the configuration properties
  * @param needWritePermissions when true the directory will be tested for read-write permissions.
  * @return The file representing the source directory
  */
 public static File getSourceDirectory(
     String directoryProviderName, Properties properties, boolean needWritePermissions) {
   String root = properties.getProperty(ROOT_INDEX_PROP_NAME);
   String relative = properties.getProperty(RELATIVE_INDEX_PROP_NAME);
   File sourceDirectory;
   if (log.isTraceEnabled()) {
     log.trace(
         "Guess source directory from {} {} and {} {}",
         new Object[] {
           ROOT_INDEX_PROP_NAME,
           (root != null ? root : "<null>"),
           RELATIVE_INDEX_PROP_NAME,
           (relative != null ? relative : "<null>")
         });
   }
   if (relative == null) {
     relative = directoryProviderName;
   }
   if (StringHelper.isEmpty(root)) {
     log.debug("No root directory, go with relative " + relative);
     sourceDirectory = new File(relative);
     if (!sourceDirectory.isDirectory()) { // this also tests for existence
       throw new SearchException("Unable to read source directory: " + relative);
     }
     // else keep source as it
   } else {
     File rootDir = new File(root);
     makeSanityCheckedDirectory(rootDir, directoryProviderName, needWritePermissions);
     sourceDirectory = new File(root, relative);
     makeSanityCheckedDirectory(sourceDirectory, directoryProviderName, needWritePermissions);
     log.debug("Got directory from root + relative");
   }
   return sourceDirectory;
 }
  @Override
  public String getQueryHintString(String sql, List<String> hints) {
    final String hint = StringHelper.join(", ", hints.iterator());

    if (StringHelper.isEmpty(hint)) {
      return sql;
    }

    final int pos = sql.indexOf("select");
    if (pos > -1) {
      final StringBuilder buffer = new StringBuilder(sql.length() + hint.length() + 8);
      if (pos > 0) {
        buffer.append(sql.substring(0, pos));
      }
      buffer
          .append("select /*+ ")
          .append(hint)
          .append(" */")
          .append(sql.substring(pos + "select".length()));
      sql = buffer.toString();
    }

    return sql;
  }
 public static FSDirectoryType getType(Properties properties) {
   FSDirectoryType fsDirectoryType;
   String fsDirectoryTypeValue = properties.getProperty(FS_DIRECTORY_TYPE_PROP_NAME);
   if (StringHelper.isNotEmpty(fsDirectoryTypeValue)) {
     try {
       fsDirectoryType = Enum.valueOf(FSDirectoryType.class, fsDirectoryTypeValue.toUpperCase());
     } catch (IllegalArgumentException e) {
       throw new SearchException(
           "Invalid option value for "
               + FS_DIRECTORY_TYPE_PROP_NAME
               + ": "
               + fsDirectoryTypeValue);
     }
   } else {
     fsDirectoryType = AUTO;
   }
   return fsDirectoryType;
 }
示例#5
0
  public void save(List<TYearThOpusEntity> opusList, String sessionId)
      throws SwordBaseCheckedException {
    IPersistenceService dao = SwordPersistenceUtils.getPersistenceService();
    // 查询已存在作品信息
    String yearThOpusIds = "";
    String sql = "select * from t_year_th_opus t where t.year_th_id=? and t.invalid='N'";
    List<String> param = new ArrayList<String>();
    param.add(sessionId);
    List<TYearThOpusEntity> opusOldList = dao.findAllBySql(TYearThOpusEntity.class, sql, param);

    // 保存作品信息
    for (TYearThOpusEntity opus : opusList) {
      opus.setYearThId(sessionId);
      if (StringHelper.isEmpty(opus.getYearThOpusId())) {
        opus.setYearThOpusId(UUIDUtil.generateUUID());
      } else {
        yearThOpusIds += (opus.getYearThOpusId() + " ");
      }
      dao.saveOrUpdate(opus);

      // 查询已存在的作品分类
      String yearThOpusId = opus.getYearThOpusId();
      String groupIds = "";
      String sql1 = "select * from t_year_th_opus_grouping t where t.year_th_opus_id=?";
      List<String> param1 = new ArrayList<String>();
      param1.add(yearThOpusId);
      List<TYearThOpusGroupingEntity> groupList =
          dao.findAllBySql(TYearThOpusGroupingEntity.class, sql1, param1);

      // 保存分类
      List<TYearThOpusGroupingEntity> groups = opus.getOpusTypes();
      for (TYearThOpusGroupingEntity group : groups) {
        group.setYearThOpusId(yearThOpusId);
        if (StringHelper.isEmpty(group.getGroupingId())) {
          group.setGroupingId(UUIDUtil.generateUUID());
        } else {
          groupIds += (group.getGroupingId() + " ");
        }
        dao.saveOrUpdate(group);
      }
      // 删除分类
      for (TYearThOpusGroupingEntity entity : groupList) {
        if (groupIds.indexOf(entity.getGroupingId()) < 0) {
          dao.delete(entity);
        }
      }
    }

    // 删除作品信息
    for (TYearThOpusEntity opusEntity : opusOldList) {
      if (yearThOpusIds.indexOf(opusEntity.getYearThOpusId()) < 0) {
        String sql2 = "select * from t_year_th_opus_grouping t where t.year_th_opus_id=?";
        List<String> param2 = new ArrayList<String>();
        param2.add(opusEntity.getYearThOpusId());
        List<TYearThOpusGroupingEntity> delGroups =
            dao.findAllBySql(TYearThOpusGroupingEntity.class, sql2, param2);
        dao.delete(opusEntity);
        dao.deleteBatch(delGroups);
      }
    }
  }