예제 #1
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  public DSResponse fetchCustSearchResult(DSRequest req) throws Exception {
    Map criteria = req.getCriteria();
    criteria.put("only_building_ids", 1);
    criteria.put("for_building", 1);
    Object uuid = criteria.get("uuid");
    Map<?, ?> result = DMIUtils.findRecordByCriteria("CustomerDS", null, criteria);
    Object building_ids = result.get("cusname");
    if (building_ids == null) {
      building_ids = ""; // return new DSResponse(new ArrayList<Map<String,
      // Object>>());
    }
    Object srid = criteria.get("srid");
    Connection connMaps = null;
    try {
      connMaps = DBConnection.getConnection("MAP");
      String feature_text =
          saveSearchResult(
              uuid.toString(), building_ids.toString(), new Integer(srid.toString()), connMaps);
      Map<String, Object> rs = new TreeMap<String, Object>();
      rs.put("feature_text", feature_text);
      ArrayList<Map<String, Object>> res = new ArrayList<Map<String, Object>>();
      res.add(rs);
      connMaps.commit();
      return new DSResponse(res);
    } catch (Exception e) {

      try {
        connMaps.rollback();
      } catch (Exception e2) {
        // TODO: handle exception
      }
      throw new Exception(e.toString());
    } finally {

      try {
        DBConnection.freeConnection(connMaps);
      } catch (Exception e2) {
        // TODO: handle exception
      }
    }
  }
예제 #2
0
  public Map<String, Object> update(Map<String, Object> map) throws Exception {

    Connection connMaps = null;
    Connection connBilling = null;
    PreparedStatement psUpdate = null;
    ResultSet rs = null;
    try {
      int building_id = new Integer(map.get("buid").toString());
      String feature_text = map.get("feature_text").toString();
      int srid = new Integer(map.get("srid").toString());
      int to_srid = new Integer(map.get("to_srid").toString());
      int regid = new Integer(map.get("regid").toString());
      int raiid = new Integer(map.get("raiid").toString());
      int map_object_type = new Integer(map.get("map_object_type").toString());
      String table_name = MapObjectTypes.getMapObjectTypeTblName(map_object_type);

      Map<String, Object> criteria = new TreeMap<String, Object>();
      criteria.putAll(map);
      criteria.put("to_srid", srid);
      criteria.put("from_srid", to_srid);
      criteria.put("buffer_size", 0.5);
      criteria.put("point", feature_text);

      List<Map<?, ?>> list =
          DMIUtils.findRecordsByCriteria("BuildingsDS", "getBufferedPoligon", criteria);
      if (list == null || list.size() == 0) throw new Exception("Cannot find subregion!!!");
      if (list.size() > 1) throw new Exception("This object intersects several subregion!!!");
      Map<?, ?> res = list.get(0);
      int p_regid = new Integer(res.get("regid").toString());
      int p_raiid = new Integer(res.get("raiid").toString());
      int p_corector_id = -1;
      try {
        p_corector_id = new Integer(map.get("corector_id").toString());
      } catch (Exception e) {
        // TODO: handle exception
      }

      if (p_regid != regid) throw new Exception("This object belongs to other region!!!");
      if (p_raiid != raiid) throw new Exception("This object belongs to other subregion!!!");

      connMaps = DBConnection.getConnection("MAP");
      connBilling = DBConnection.getConnection("Gass");
      // object_type character varying, object_id integer, p_regid
      // integer, p_raiid integer,srid integer, to_srid integer,
      // feature_text character varying
      psUpdate =
          connMaps.prepareStatement("select globals.saveMapObject(?, ?, ?, ?,?, ?, ?, ?) buid");
      int index = 1;
      psUpdate.setString(index++, table_name);
      psUpdate.setInt(index++, building_id);
      psUpdate.setInt(index++, regid);
      psUpdate.setInt(index++, raiid);
      psUpdate.setInt(index++, p_corector_id);
      psUpdate.setInt(index++, srid);
      psUpdate.setInt(index++, to_srid);
      psUpdate.setString(index++, feature_text);
      rs = psUpdate.executeQuery();
      rs.next();

      building_id = rs.getInt(1);
      map.put("buid", building_id);
      if (map_object_type == MapObjectTypes.MO_DISTRICT_METER_TYPE) {
        int cusid = new Integer(map.get("cusid").toString());
        saveDistrict_Meter_mapping(building_id, cusid, connBilling);
        saveDistrict_Meter_mapping(building_id, cusid, connMaps);
      }
      saveMapObject(connMaps, map_object_type, map);
      connMaps.commit();
      connBilling.commit();
      return map;

    } catch (Exception e) {
      e.printStackTrace();
      try {
        connMaps.rollback();
      } catch (Exception e2) {
        // TODO: handle exception
      }
      try {
        connBilling.rollback();
      } catch (Exception e2) {
        // TODO: handle exception
      }
      throw new Exception(e.toString());
    } finally {
      try {
        rs.close();
      } catch (Exception e2) {
        // TODO: handle exception
      }
      try {
        psUpdate.close();
      } catch (Exception e2) {
        // TODO: handle exception
      }
      try {
        DBConnection.freeConnection(connBilling);
      } catch (Exception e2) {
        // TODO: handle exception
      }
      try {
        DBConnection.freeConnection(connMaps);
      } catch (Exception e2) {
        // TODO: handle exception
      }
    }
  }