diff --git a/src/osm/jp/coverage/busstop/Busstop.java b/src/osm/jp/coverage/busstop/Busstop.java index 067390c..02efe48 100644 --- a/src/osm/jp/coverage/busstop/Busstop.java +++ b/src/osm/jp/coverage/busstop/Busstop.java @@ -134,10 +134,6 @@ Connection conPost = null; File outFile = new File(gmldir, "update.sql"); - if (outFile.isFile()) { - outFile.delete(); - outFile = new File(gmldir, "update.sql"); - } ow = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8")); if (Busstop.update) { @@ -470,11 +466,6 @@ count = stmt.executeUpdate("delete from existing_data"); System.out.println("'Database.existing_data'から "+ count +" 件のデータを削除しました。"); - count = stmt.executeUpdate("delete from bus_course"); - System.out.println("'Database.bus_course'から "+ count +" 件のデータを削除しました。"); - - count = stmt.executeUpdate("delete from bus_ref"); - System.out.println("'Database.bus_ref'から "+ count +" 件のデータを削除しました。"); stmt.close(); } @@ -544,94 +535,55 @@ String nameStr = ""; PreparedStatement ps1 = con.prepareStatement("SELECT idref FROM bus_stop WHERE idref=?"); PreparedStatement ps2 = con.prepareStatement("INSERT INTO bus_stop (idref,name,ifile) VALUES (?,?,?)"); - PreparedStatement ps3 = con.prepareStatement("SELECT code FROM bus_course WHERE course=? AND corp=? AND ifile=?"); - PreparedStatement ps4 = con.prepareStatement("INSERT INTO bus_course (code,type,corp,course,ifile) VALUES (?,?,?,?,?)"); - PreparedStatement ps5 = con.prepareStatement("INSERT INTO bus_ref (idref,code) VALUES (?,?)"); - PreparedStatement ps6 = con.prepareStatement("SELECT max(code) FROM bus_course WHERE ifile=?"); - - ArrayList bris = new ArrayList(); - NodeList nodes = node.getChildNodes(); - for (int i=0; i < nodes.getLength(); i++) { - Node node2 = nodes.item(i); - if (node2.getNodeName().equals("ksj:POS")) { - NamedNodeMap nodeMap = node2.getAttributes(); - if (null != nodeMap) { - for ( int j=0; j < nodeMap.getLength(); j++ ) { - if (nodeMap.item(j).getNodeName().equals("idref")) { - idrefStr = nodeMap.item(j).getNodeValue(); - System.out.println("found idref='"+ idrefStr +"'"); - break; + try { + ArrayList bris = new ArrayList(); + NodeList nodes = node.getChildNodes(); + for (int i=0; i < nodes.getLength(); i++) { + Node node2 = nodes.item(i); + if (node2.getNodeName().equals("ksj:POS")) { + NamedNodeMap nodeMap = node2.getAttributes(); + if (null != nodeMap) { + for ( int j=0; j < nodeMap.getLength(); j++ ) { + if (nodeMap.item(j).getNodeName().equals("idref")) { + idrefStr = nodeMap.item(j).getNodeValue(); + System.out.println("found idref='"+ idrefStr +"'"); + break; + } } } } - } - else if (node2.getNodeName().equals("ksj:BSN")) { - nameStr = node2.getTextContent(); - } - else if (node2.getNodeName().equals("ksj:BRI")) { - String[] rtn = anaComm(node2); - if (rtn != null) { - bris.add(rtn); + else if (node2.getNodeName().equals("ksj:BSN")) { + nameStr = node2.getTextContent(); + } + else if (node2.getNodeName().equals("ksj:BRI")) { + String[] rtn = anaComm(node2); + if (rtn != null) { + bris.add(rtn); + } } } - } - // idref と nameStr をデータベースに格納する - boolean insert = true; - ps1.setString(1, idrefStr); - ResultSet rset = ps1.executeQuery(); - if (rset.next()) { - insert = false; - } - rset.close(); - - if (insert) { - ps2.setString(1, idrefStr); - ps2.setString(2, nameStr); - ps2.setString(3, iFileName); - System.out.println("INSERT INTO bus_stop (idref,name,ifile) VALUES ('"+ idrefStr +"','"+ nameStr +"','"+ iFileName +"')"); - ps2.executeUpdate(); - } - - for (String[] rtn : bris) { - int code = 0; - ps3.setString(1, rtn[1]); - ps3.setString(2, rtn[2]); - ps3.setString(3, iFileName); - rset = ps3.executeQuery(); + // idref と nameStr をデータベースに格納する + boolean insert = true; + ps1.setString(1, idrefStr); + ResultSet rset = ps1.executeQuery(); if (rset.next()) { - code = rset.getInt(1); + insert = false; } rset.close(); - if (code == 0) { - ps6.setString(1, iFileName); - ResultSet rset6 = ps6.executeQuery(); - if (rset6.next()) { - code = rset6.getInt(1); - } - rset6.close(); - code++; - - System.out.println("code="+code); - ps4.setInt(1, code); - ps4.setInt(2, Integer.parseInt(rtn[0])); - ps4.setString(3, rtn[2]); - ps4.setString(4, rtn[1]); - ps4.setString(5, iFileName); - ps4.executeUpdate(); + if (insert) { + ps2.setString(1, idrefStr); + ps2.setString(2, nameStr); + ps2.setString(3, iFileName); + System.out.println("INSERT INTO bus_stop (idref,name,ifile) VALUES ('"+ idrefStr +"','"+ nameStr +"','"+ iFileName +"')"); + ps2.executeUpdate(); } - - ps5.setString(1, idrefStr); - ps5.setInt(2, code); - ps5.executeUpdate(); } - - ps1.close(); - ps2.close(); - ps3.close(); - ps4.close(); - ps5.close(); + finally { + ps1.close(); + ps2.close(); + } } /** @@ -671,10 +623,6 @@ String idrefStr = ""; String nameStr = ""; PreparedStatement ps2 = con.prepareStatement("UPDATE bus_stop SET name=?,ifile=? WHERE idref=?"); - PreparedStatement ps3 = con.prepareStatement("SELECT code FROM bus_course WHERE course=? AND corp=? AND ifile=?"); - PreparedStatement ps4 = con.prepareStatement("INSERT INTO bus_course (code,type,corp,course,ifile) VALUES (?,?,?,?,?)"); - PreparedStatement ps5 = con.prepareStatement("INSERT INTO bus_ref (idref,code) VALUES (?,?)"); - PreparedStatement ps6 = con.prepareStatement("SELECT max(code) FROM bus_course WHERE ifile=?"); ArrayList bris = new ArrayList(); NodeList nodes = node.getChildNodes(); @@ -709,46 +657,7 @@ ps2.setString(2, iFileName); ps2.setString(3, idrefStr); ps2.executeUpdate(); - - for (String[] rtn : bris) { - int code = 0; - ps3.setString(1, rtn[1]); - ps3.setString(2, rtn[2]); - ps3.setString(3, iFileName); - ResultSet rset = ps3.executeQuery(); - if (rset.next()) { - code = rset.getInt(1); - } - rset.close(); - - if (code == 0) { - ps6.setString(1, iFileName); - ResultSet rset6 = ps6.executeQuery(); - if (rset6.next()) { - code = rset6.getInt(1); - } - rset6.close(); - code++; - - System.out.println("bus_course="+ code +" : "+ rtn[0] +" : "+ rtn[1] +" : "+ rtn[2] ); - ps4.setInt(1, code); - ps4.setInt(2, Integer.parseInt(rtn[0])); - ps4.setString(3, rtn[2]); - ps4.setString(4, rtn[1]); - ps4.setString(5, iFileName); - ps4.executeUpdate(); - } - - System.out.println("bus_ref=("+ idrefStr +", "+ code +")"); - ps5.setString(1, idrefStr); - ps5.setInt(2, code); - ps5.executeUpdate(); - } - ps2.close(); - ps3.close(); - ps4.close(); - ps5.close(); } public static String[] anaComm(Node briNode) { diff --git a/src/update.sh b/src/update.sh index 2db7016..534611c 100755 --- a/src/update.sh +++ b/src/update.sh @@ -1,3 +1,4 @@ +rm */update.sql java -cp .:osmCoverage.jar:hayashi_0225.jar:postgresql-9.4.1212.jar:hsqldb_2.2.9.jar osm.jp.coverage.busstop.Busstop -update java -cp .:osmCoverage.jar:hayashi_0225.jar:postgresql-9.4.1212.jar osm.jp.postgis.Do_sqlfiles -update java -cp .:osmCoverage.jar:hayashi_0225.jar:postgresql-9.4.1212.jar:hsqldb_2.2.9.jar osm.jp.coverage.busstop.Coverage coverage.csv