/[projects]/android/TrainInfoService/src/dk/thoerup/traininfoservice/db/StationDAO.java
ViewVC logotype

Diff of /android/TrainInfoService/src/dk/thoerup/traininfoservice/db/StationDAO.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1513 by torben, Thu Jun 9 10:02:31 2011 UTC revision 1692 by torben, Fri Feb 24 14:26:53 2012 UTC
# Line 6  import java.sql.PreparedStatement; Line 6  import java.sql.PreparedStatement;
6  import java.sql.ResultSet;  import java.sql.ResultSet;
7  import java.sql.SQLException;  import java.sql.SQLException;
8  import java.sql.Statement;  import java.sql.Statement;
9    import java.util.Collections;
10    import java.util.Comparator;
11  import java.util.logging.Logger;  import java.util.logging.Logger;
12    
13  import dk.thoerup.android.traininfo.common.StationBean;  import dk.thoerup.android.traininfo.common.StationBean;
# Line 145  public class StationDAO { Line 147  public class StationDAO {
147                  return stations;                  return stations;
148          }          }
149                    
150            private String removeSuffix(String str, String suffix) {
151                    if (str.endsWith(suffix)) {
152                            return str.substring(0, str.length() - suffix.length() );
153                    } else {
154                            return str;
155                    }
156            }
157            
158          public StationBean getByName(String name) throws SQLException {          public StationBean getByName(String name) throws SQLException {
159                    name = removeSuffix(name, " st.");
160                    name = removeSuffix(name, " st");
161                    name = removeSuffix(name, " station");
162                    
163                  StationBean stations = getByNameNormal(name);                  StationBean stations = getByNameNormal(name);
164                                    
165                  if (stations.entries.size() == 0) {                  if (stations.entries.size() == 0) {
                         logger.info("getByName failover: " + name);  
                         name = name.replace(".", ""); //remove any .'s before fuzzy search  
166                          stations = getByNameFuzzy(name);                          stations = getByNameFuzzy(name);
167    
168                            logger.info("getByName failover: " + name + "(" + (stations.entries.size() >0) + ")" );
169                  }                  }
170                  return stations;                  return stations;
171          }          }
# Line 245  public class StationDAO { Line 259  public class StationDAO {
259                  }                  }
260          }          }
261                    
262            Comparator<StationEntry> nameComparator = new Comparator<StationEntry>() {
263                    @Override
264                    public int compare(StationEntry arg0, StationEntry arg1) {
265                            return arg0.getName().compareTo( arg1.getName() );
266                    }              
267            };
268            
269          //used to create full dump in order to populate Google Appengine DB          //used to create full dump in order to populate Google Appengine DB
270          @Deprecated          //after 1.1.0 also used to populate client-side station list
271          public StationBean dumpAll() throws SQLException {          public StationBean dumpAll() throws SQLException {
272                                    
273                  String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog,stationcode_metro,address,0.0,aliases " +                  String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog,stationcode_metro,address,0.0,aliases " +
274                                  "FROM trainstations WHERE enabled = true ORDER BY id";                                  "FROM trainstations WHERE enabled = true";
275                    
276                                    
277                    StationBean stations = fetchStations(SQL, new NullSetter() );
278                    Collections.sort( stations.entries,nameComparator );
279                    
280                    return stations;
281                    
282                    /*
283                  Connection conn = null;                  Connection conn = null;
284                  Statement stmt = null;                  Statement stmt = null;
285                  ResultSet res = null;                            ResultSet res = null;          
# Line 277  public class StationDAO { Line 305  public class StationDAO {
305                                  stations.entries.add( entry );                                  stations.entries.add( entry );
306                                                                    
307                          }                          }
308                            Collections.sort( stations.entries,nameComparator );
309                          return stations;                          return stations;
310                                                    
311    
# Line 287  public class StationDAO { Line 316  public class StationDAO {
316                                  stmt.close();                                  stmt.close();
317                          if (conn != null)                          if (conn != null)
318                                  conn.close();                                  conn.close();
319                  }                  }*/
320                                    
321          }          }
322    
# Line 315  public class StationDAO { Line 344  public class StationDAO {
344                  return station;                  return station;
345          }          }
346                    
347            public boolean hasDisabledStation(final String name) throws SQLException {
348                    String SQL = "Select count(*) as antal from trainstations where name = '" + name + "'  and enabled=false " ;
349    
350                    Connection conn = DBConnection.getConnection();
351                    Statement stmt = conn.createStatement();
352                    ResultSet rs = stmt.executeQuery( SQL );
353                    
354                    rs.next();
355    
356                    int antal = rs.getInt(1);
357                    
358                    rs.close();
359                    stmt.close();
360                    conn.close();
361                    
362                    return (antal > 0);
363            }
364                    
365                    
366          @Deprecated          @Deprecated

Legend:
Removed from v.1513  
changed lines
  Added in v.1692

  ViewVC Help
Powered by ViewVC 1.1.20