/[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

android/TrainInfoService/src/dk/thoerup/traininfoservice/StationDAO.java revision 1082 by torben, Tue Sep 21 05:55:31 2010 UTC android/TrainInfoService/src/dk/thoerup/traininfoservice/db/StationDAO.java revision 1409 by torben, Mon May 2 11:59:40 2011 UTC
# Line 1  Line 1 
1  package dk.thoerup.traininfoservice;  package dk.thoerup.traininfoservice.db;
2    
3  import java.sql.Array;  import java.sql.Array;
4  import java.sql.Connection;  import java.sql.Connection;
# Line 9  import java.sql.Statement; Line 9  import java.sql.Statement;
9  import java.util.logging.Logger;  import java.util.logging.Logger;
10    
11  import dk.thoerup.android.traininfo.common.StationBean;  import dk.thoerup.android.traininfo.common.StationBean;
12  import dk.thoerup.android.traininfo.common.StationBean.StationEntry;  import dk.thoerup.android.traininfo.common.StationEntry;
13    
14  public class StationDAO {  public class StationDAO {
15            
16            public static class NostationException extends Exception {
17                    private static final long serialVersionUID = 1L;
18            }
19            
20          final static int LOCATION_LIMIT = 8;          final static int LOCATION_LIMIT = 8;
21          static final Logger logger = Logger.getLogger(StationDAO.class.getName());          static final Logger logger = Logger.getLogger(StationDAO.class.getName());
22                    
# Line 46  public class StationDAO { Line 51  public class StationDAO {
51          }          }
52    
53    
54          public StationEntry getById(int id) throws SQLException {          public StationEntry getById(int id) throws SQLException,NostationException {
55                  String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog,stationcode_metro,address,0.0 " +                  String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog,stationcode_metro,address,0.0 " +
56                  "FROM trainstations WHERE id=" + id + " AND enabled=true";                  "FROM trainstations WHERE id=" + id + " AND enabled=true";
57    
# Line 59  public class StationDAO { Line 64  public class StationDAO {
64                          conn = DBConnection.getConnection();                          conn = DBConnection.getConnection();
65    
66                          stmt = conn.createStatement();                          stmt = conn.createStatement();
67                          res = stmt.executeQuery(SQL);                                    res = stmt.executeQuery(SQL);
68                          res.next();                          
69                          result = convertSingleRow(res);                          if (res.next()) {
70                                    result = convertSingleRow(res);
71                            } else {
72                                    throw new NostationException();
73                            }
74                  } finally {                  } finally {
75                          if (res != null)                          if (res != null)
76                                  res.close();                                  res.close();
# Line 156  public class StationDAO { Line 165  public class StationDAO {
165                  return result;                  return result;
166          }          }
167    
168          //the "hack" with max 0.4 degrees latitude and 0.75 degrees longitude is only valid since we only service danish trains,          //Latitude (horizonal), longitude(vertical) so
169            // 1 degree latitude is ~ 111320 meters, since the distance between the horizonal lines is always the same
170            // 1 degree longitude is ~111320 meters at equator but gets shorter as we get closer to the poles.
171            // the "hack" with max 0.4 degrees latitude and 0.75 degrees longitude is only valid since we only service danish trains,
172          // in denmark 0.4dg latitude ~ 44km, 0.75dg longitude ~ 47km          // in denmark 0.4dg latitude ~ 44km, 0.75dg longitude ~ 47km
173    
174          // the ultra fast method  (and only slightly inaccurate as long as we only cover a limited geographically area)          // the ultra fast method  (and only slightly inaccurate as long as we only cover a limited geographically area)

Legend:
Removed from v.1082  
changed lines
  Added in v.1409

  ViewVC Help
Powered by ViewVC 1.1.20