--- android/TrainInfoService/src/dk/thoerup/traininfoservice/db/StationDAO.java 2011/06/10 08:25:43 1515 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/db/StationDAO.java 2012/02/24 14:26:53 1692 @@ -6,6 +6,8 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.Collections; +import java.util.Comparator; import java.util.logging.Logger; import dk.thoerup.android.traininfo.common.StationBean; @@ -145,11 +147,22 @@ return stations; } + private String removeSuffix(String str, String suffix) { + if (str.endsWith(suffix)) { + return str.substring(0, str.length() - suffix.length() ); + } else { + return str; + } + } + public StationBean getByName(String name) throws SQLException { + name = removeSuffix(name, " st."); + name = removeSuffix(name, " st"); + name = removeSuffix(name, " station"); + StationBean stations = getByNameNormal(name); if (stations.entries.size() == 0) { - name = name.replace(".", ""); //remove any .'s before fuzzy search stations = getByNameFuzzy(name); logger.info("getByName failover: " + name + "(" + (stations.entries.size() >0) + ")" ); @@ -246,13 +259,27 @@ } } + Comparator nameComparator = new Comparator() { + @Override + public int compare(StationEntry arg0, StationEntry arg1) { + return arg0.getName().compareTo( arg1.getName() ); + } + }; + //used to create full dump in order to populate Google Appengine DB - @Deprecated + //after 1.1.0 also used to populate client-side station list public StationBean dumpAll() throws SQLException { String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog,stationcode_metro,address,0.0,aliases " + - "FROM trainstations WHERE enabled = true ORDER BY id"; + "FROM trainstations WHERE enabled = true"; + + + StationBean stations = fetchStations(SQL, new NullSetter() ); + Collections.sort( stations.entries,nameComparator ); + return stations; + + /* Connection conn = null; Statement stmt = null; ResultSet res = null; @@ -278,6 +305,7 @@ stations.entries.add( entry ); } + Collections.sort( stations.entries,nameComparator ); return stations; @@ -288,7 +316,7 @@ stmt.close(); if (conn != null) conn.close(); - } + }*/ } @@ -316,6 +344,23 @@ return station; } + public boolean hasDisabledStation(final String name) throws SQLException { + String SQL = "Select count(*) as antal from trainstations where name = '" + name + "' and enabled=false " ; + + Connection conn = DBConnection.getConnection(); + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery( SQL ); + + rs.next(); + + int antal = rs.getInt(1); + + rs.close(); + stmt.close(); + conn.close(); + + return (antal > 0); + } @Deprecated