public List<KpiSyncMapping> query(String sql) throws Exception {
   List<KpiSyncMapping> ret = new ArrayList<KpiSyncMapping>();
   try {
     Connection conn = MongoConnect.getConnection();
     Statement stmt = conn.createStatement();
     ResultSet rs = stmt.executeQuery(sql);
     while (rs.next()) {
       String id = rs.getString("_id");
       String name = rs.getString("name");
       String cateId = rs.getString("cateId");
       String dataSourceId = rs.getString("dataSourceId");
       JSONObject fieldMap = null;
       try {
         fieldMap = JSONObject.fromObject(rs.getString("fieldMap"));
       } catch (Exception e) {
         fieldMap = new JSONObject();
       }
       KpiCategory cate = kCateStorage.getById(cateId);
       DataSourcePool dataSource = dsStorage.getById(dataSourceId);
       @SuppressWarnings("unchecked")
       KpiSyncMapping ksm = new KpiSyncMapping(name, cate, dataSource, dataSourceId, fieldMap);
       ksm.setId(id);
       ksm.setOwner(rs.getString("owner"));
       ret.add(ksm);
     }
   } catch (Exception e) {
     throw e;
   }
   return ret;
 }
 public KpiSyncMapping save(KpiSyncMapping kpiMapping) throws Exception {
   try {
     Connection conn = MongoConnect.getConnection();
     PreparedStatement pstmt =
         conn.prepareStatement(
             "insert into KpiSyncMapping(name,cateId,dataSourceId,fieldMap,owner) values(?,?,?,?,?)");
     pstmt.setString(1, kpiMapping.getName() == null ? "" : kpiMapping.getName());
     pstmt.setString(2, kpiMapping.getCateId() == null ? "" : kpiMapping.getCateId());
     pstmt.setString(3, kpiMapping.getDataSourceId() == null ? "" : kpiMapping.getDataSourceId());
     pstmt.setString(
         4,
         kpiMapping.getFieldMap() == null
             ? "{}"
             : JSONObject.fromObject(kpiMapping.getFieldMap()).toString());
     pstmt.setString(5, kpiMapping.getOwner());
     pstmt.executeUpdate();
   } catch (Exception e) {
     throw e;
   }
   return getByName(kpiMapping.getName());
 }
 public KpiSyncMapping update(KpiSyncMapping kpiMapping) throws Exception {
   try {
     Connection conn = MongoConnect.getConnection();
     PreparedStatement pstmt =
         conn.prepareStatement(
             "update KpiSyncMapping set name=?,cateId=?,dataSourceId=?,fieldMap=? where _id=?");
     pstmt.setString(1, kpiMapping.getName() == null ? "" : kpiMapping.getName());
     pstmt.setString(2, kpiMapping.getCateId() == null ? "" : kpiMapping.getCateId());
     pstmt.setString(3, kpiMapping.getDataSourceId() == null ? "" : kpiMapping.getDataSourceId());
     pstmt.setString(
         4,
         kpiMapping.getFieldMap() == null
             ? "{}"
             : JSONObject.fromObject(kpiMapping.getFieldMap()).toString());
     pstmt.setString(5, kpiMapping.getId());
     pstmt.executeUpdate();
   } catch (Exception e) {
     throw e;
   }
   return kpiMapping;
 }