// 参数为车站ID // 所有相关的记录都将删除. ?????????????? public boolean deleteStationInfo(String stationName) { SQLRequestMessage msg = new SQLRequestMessage(); msg.setCommandMode(Constants.MODE_CS_SYN_CLIENT); // 从列车区段表District中获取车站ID等于stationID的所有区段的ID List<String> districtIDList = new ArrayList<String>(); msg.setCommandType(Constants.TYPE_CLIENT_SQLQUERY); msg.setDataBean("District"); String sqlStr = "select * from District where District_startstationname='" + stationName + "' or District_endstationname='" + stationName + "'"; msg.setSql(sqlStr); String paprams = "null"; msg.setParams(paprams); String listString = synClientSupport.sqlMessageSend(msg); if (listString == null) { // 此情况不会出现 districtIDList = null; } else { List<District> list = JsonUtil.getList4Json(listString, District.class); if (list.size() <= 0) districtIDList = null; else { for (int i = 0; i < list.size(); i++) { District data = (District) list.get(i); districtIDList.add(data.getDistrict_name()); } } } // 从列车表Train中获取车站ID等于stationID的所有车次的ID List<String> trainIDList = new ArrayList<String>(); msg.setDataBean("Train"); sqlStr = "select * from Train where Train_startstationname='" + stationName + "' or Train_endstationname='" + stationName + "'"; msg.setSql(sqlStr); paprams = "null"; msg.setParams(paprams); listString = synClientSupport.sqlMessageSend(msg); if (listString == null) { // 此情况不会出现 trainIDList = null; } else { List<Train> list = JsonUtil.getList4Json(listString, Train.class); if (list.size() <= 0) trainIDList = null; else { for (int i = 0; i < list.size(); i++) { Train data = (Train) list.get(i); trainIDList.add(data.getTrain_name()); } } } // 批量删除 // 涉及到的表:Station, District Train StationDistrictRelation TrainDistrictRelation int districtNumber = 0; int trainNumber = 0; if (districtIDList != null) districtNumber = districtIDList.size(); if (trainIDList != null) trainNumber = trainIDList.size(); String[] sqlArray = new String[5 + districtNumber * 2 + trainNumber]; int index = 0; sqlArray[index++] = "delete from Station where Station_name='" + stationName + "'"; // number 1 sqlArray[index++] = "delete from StationDistrictRelation where Station_name='" + stationName + "'"; // number 1 sqlArray[index++] = "delete from Plan where Station_name='" + stationName + "' or Prestation_name='" + stationName + "'"; // number 1 if (districtIDList != null) { sqlArray[index++] = "delete from District where District_startstationname='" + stationName + "' or District_endstationname='" + stationName + "'"; // number 1 for (int i = 0; i < districtNumber; i++) { // number districtNumber*2 sqlArray[index++] = "delete from StationDistrictRelation where District_name='" + districtIDList.get(i) + "'"; sqlArray[index++] = "delete from TrainDistrictRelation where District_name='" + districtIDList.get(i) + "'"; } } if (trainIDList != null) { sqlArray[index++] = "delete from Train where Train_startstationname='" + stationName + "' or Train_endstationname='" + stationName + "'"; // number 1 for (int i = 0; i < trainNumber; i++) { // number trainNumber sqlArray[index++] = "delete from TrainDistrictRelation where Train_name='" + trainIDList.get(i) + "'"; } } msg.setCommandType(Constants.TYPE_CLIENT_SQLBATCHDELETE); sqlStr = JsonUtil.array2json(sqlArray); msg.setSql(sqlStr); paprams = "null"; msg.setParams(paprams); listString = synClientSupport.sqlMessageSend(msg); // 同步通信 if (listString == null) { return false; } else { return true; } }
static int loadDist(int whseKount, int distWhseKount) { int k = 0; int t = 0; try { now = new java.util.Date(); if (outputFiles == true) { out = new PrintWriter(new FileOutputStream(fileLocation + "district.csv")); System.out.println("\nWriting District file to: " + fileLocation + "district.csv"); } District district = new District(); t = (whseKount * distWhseKount); System.out.println("\nStart District Data for " + t + " Dists @ " + now + " ..."); for (int w = 1; w <= whseKount; w++) { for (int d = 1; d <= distWhseKount; d++) { district.d_id = d; district.d_w_id = w; district.d_ytd = 30000; // random within [0.0000 .. 0.2000] district.d_tax = (float) ((jTPCCUtil.randomNumber(0, 2000, gen)) / 10000.0); district.d_next_o_id = 3001; district.d_name = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(6, 10, gen)); district.d_street_1 = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(10, 20, gen)); district.d_street_2 = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(10, 20, gen)); district.d_city = jTPCCUtil.randomStr(jTPCCUtil.randomNumber(10, 20, gen)); district.d_state = jTPCCUtil.randomStr(3).toUpperCase(); district.d_zip = "123456789"; k++; if (outputFiles == false) { distPrepStmt.setLong(1, district.d_id); distPrepStmt.setLong(2, district.d_w_id); distPrepStmt.setDouble(3, district.d_ytd); distPrepStmt.setDouble(4, district.d_tax); distPrepStmt.setLong(5, district.d_next_o_id); distPrepStmt.setString(6, district.d_name); distPrepStmt.setString(7, district.d_street_1); distPrepStmt.setString(8, district.d_street_2); distPrepStmt.setString(9, district.d_city); distPrepStmt.setString(10, district.d_state); distPrepStmt.setString(11, district.d_zip); distPrepStmt.executeUpdate(); } else { String str = ""; str = str + district.d_id + ","; str = str + district.d_w_id + ","; str = str + district.d_ytd + ","; str = str + district.d_tax + ","; str = str + district.d_next_o_id + ","; str = str + district.d_name + ","; str = str + district.d_street_1 + ","; str = str + district.d_street_2 + ","; str = str + district.d_city + ","; str = str + district.d_state + ","; str = str + district.d_zip; out.println(str); } } // end for [d] } // end for [w] long tmpTime = new java.util.Date().getTime(); String etStr = " Elasped Time(ms): " + ((tmpTime - lastTimeMS) / 1000.000) + " "; System.out.println(etStr.substring(0, 30) + " Writing record " + k + " of " + t); lastTimeMS = tmpTime; transCommit(); now = new java.util.Date(); System.out.println("End District Load @ " + now); } catch (SQLException se) { System.out.println(se.getMessage()); transRollback(); } catch (Exception e) { e.printStackTrace(); transRollback(); } return (k); } // end loadDist()