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

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

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

revision 650 by torben, Mon Apr 19 19:04:34 2010 UTC revision 734 by torben, Tue May 18 20:39:22 2010 UTC
# Line 63  public class StationDAO { Line 63  public class StationDAO {
63                  return result;                  return result;
64          }          }
65                    
66                    /*
67             * this code requires theses statements are run on database in order to do ILIKE searches against aliases (which is defines as array of varchar(64) )
68             *     create function rlike(text,text) returns bool as
69             *     'select $2 ilike $1' language sql strict immutable;
70         *     create operator ~~~ (procedure = rlike, leftarg = text, rightarg = text, commutator = ~~);
71             */
72          public List<StationBean> getByName(String name) throws SQLException {          public List<StationBean> getByName(String name) throws SQLException {
73                  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 " +
74                  "FROM trainstations " +                  "FROM trainstations " +
75                  "WHERE name ILIKE ? AND enabled = true " +                  "WHERE (name ILIKE ? OR ? ~~~ ANY(aliases)) AND enabled = true " +
76                  "ORDER BY name ";                  "ORDER BY name ";
77    
78                                    
# Line 80  public class StationDAO { Line 85  public class StationDAO {
85                          stmt = conn.prepareStatement(SQL);                          stmt = conn.prepareStatement(SQL);
86                                                    
87                          stmt.setString(1, name + "%");                          stmt.setString(1, name + "%");
88                            stmt.setString(2, name + "%");
89                                                    
90                          res = stmt.executeQuery();                          res = stmt.executeQuery();
91                          result = convertResultset(res);                          result = convertResultset(res);
# Line 96  public class StationDAO { Line 102  public class StationDAO {
102          }          }
103                    
104          public List<StationBean> getByLocation(double latitude, double longitude) throws SQLException {          public List<StationBean> getByLocation(double latitude, double longitude) throws SQLException {
105                  String SQL = "SELECT * FROM ( "+                  String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, stationcode_metro, address," +
106                  "               SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, stationcode_metro, address," +                                           "       earth_distance( earth_coord, ll_to_earth(?,?))::int AS calcdist " +
107                  "                     earth_distance( ll_to_earth(latitude,longitude), ll_to_earth(?,?))::int AS calcdist " +                                           "FROM trainstations " +
108                  "               FROM trainstations " +                                           "WHERE enabled = true " +
109                  "               WHERE enabled = true " +                                           "ORDER BY calcdist ASC " +
110                  "       ) AS trainstations2 " +                                           "LIMIT 4 ";
                 "ORDER BY calcdist ASC " +  
                 "LIMIT 4 ";  
111                  List<StationBean> result;                  List<StationBean> result;
112                  Connection conn = null;                  Connection conn = null;
113                  PreparedStatement stmt = null;                  PreparedStatement stmt = null;

Legend:
Removed from v.650  
changed lines
  Added in v.734

  ViewVC Help
Powered by ViewVC 1.1.20