Example #1
0
 private String getTransFieldName(TSysCodeTable codeDic, Connection conn) {
   Locale locale = Locale.getDefault();
   String language = locale.getLanguage();
   String country = locale.getCountry();
   String transFieldPrefix = codeDic.getTransField();
   String transField = transFieldPrefix + "_" + language + "_" + country;
   String tableName = codeDic.getTableName();
   RdbConnection rdbConn = new RdbConnection(codeDic.getDataSrc().getId(), conn);
   MdRdbColumn column = MdRdbTool.getColumn(rdbConn, tableName, transField);
   if (column == null) {
     transField = transFieldPrefix;
   }
   return transField;
 }
Example #2
0
 private List<CodeRecord> searchCodes(String codeTableId, TSysCodeTable codeDic) {
   List<CodeRecord> codes = new ArrayList<CodeRecord>();
   Connection conn = null;
   TSysDataSrc dataSrc = codeDic.getDataSrc();
   String sqlPattern = "SELECT * FROM {0} WHERE {1} ORDER BY {2} ASC";
   String codeFieldName = codeDic.getCodeField();
   String parentCodeField = codeDic.getParentField();
   String orderByField =
       StringTool.isBlank(codeDic.getOrderField()) ? codeFieldName : codeDic.getOrderField();
   String codeCategory = null;
   String groupingCommentField = codeDic.getGroupingCommentField();
   String where = "1=1";
   String activeField = codeDic.getActiveField();
   if (StringTool.isNotBlank(activeField)) {
     where += " AND " + activeField + " = '1'";
   }
   String deletedField = codeDic.getDeletedField();
   if (StringTool.isNotBlank(deletedField)) {
     where += " AND " + deletedField + " = '0'";
   }
   if (codeDic.getId().equals(codeTableId) == false) {
     String groupingField = codeDic.getGroupingField();
     where += " AND " + groupingField + " = '" + codeTableId + "'";
   } else {
     codeCategory = codeDic.getTableComment();
   }
   String sql = MessageFormat.format(sqlPattern, codeDic.getTableName(), where, orderByField);
   PreparedStatement statement = null;
   try {
     conn = JdbcTool.getConnection(dataSrc);
     statement = conn.prepareStatement(sql);
     String transFieldName = getTransFieldName(codeDic, conn);
     ResultSet rs = statement.executeQuery();
     while (rs.next()) {
       String code = rs.getString(codeFieldName);
       String trans = rs.getString(transFieldName);
       String parentCode =
           StringTool.isBlank(parentCodeField) ? null : rs.getString(parentCodeField);
       if (codeCategory == null && StringTool.isNotBlank(groupingCommentField)) {
         codeCategory = rs.getString(groupingCommentField);
       }
       String order = rs.getString(orderByField);
       CodeRecord codeRecord = new CodeRecord(code, trans, parentCode, order, codeCategory);
       codes.add(codeRecord);
     }
     if (codes.isEmpty() == false || codeDic.getId().equals(codeTableId)) {
       logger.info("加载代码表#{0}数据共{1}条。", codeTableId, codes.size());
     }
   } catch (SQLException e) {
     logger.error(e, "代码表#{0}数据加载失败!", codeTableId);
   } finally {
     if (statement != null) {
       try {
         statement.close();
       } catch (SQLException ex) {
         logger.error(ex.getMessage(), ex);
       }
     }
     JdbcTool.closeConnection(conn);
   }
   return codes;
 }