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

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

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

revision 1115 by torben, Thu Sep 23 15:08:39 2010 UTC revision 1116 by torben, Thu Sep 23 15:11:52 2010 UTC
# Line 34  public class StationDAO { Line 34  public class StationDAO {
34                    
35          Cache cache;          Cache cache;
36                    
37            @SuppressWarnings("unchecked")
38          public StationDAO() {          public StationDAO() {
39          Map props = new HashMap();          Map props = new HashMap();
40          props.put(GCacheFactory.EXPIRATION_DELTA, TIMEOUT_SECONDS);                  props.put(GCacheFactory.EXPIRATION_DELTA, TIMEOUT_SECONDS);        
# Line 62  public class StationDAO { Line 63  public class StationDAO {
63    
64          /* damn that JDO sucks so we to the filtering in java-code */          /* damn that JDO sucks so we to the filtering in java-code */
65          public StationBean getByName(String searchname) {          public StationBean getByName(String searchname) {
                 PersistenceManager pm = null;  
                   
                 try {  
                         /*pm = PMF.get().getPersistenceManager();  
                           
                           
                           
                         Query q = pm.newQuery(JdoStationBean.class);  
                         q.setOrdering("name");                    
                         List<JdoStationBean> beanList = (List<JdoStationBean>) q.execute();*/  
66                                                    
67                          List<JdoStationBean> beanList = getAllStations();                  List<JdoStationBean> beanList = getAllStations();
68                            
69                            
70                          StationBean stationBean = new StationBean();                  StationBean stationBean = new StationBean();
71                            
72                          searchname = searchname.toLowerCase();                  searchname = searchname.toLowerCase();
73                          for(JdoStationBean bean : beanList) {                  for(JdoStationBean bean : beanList) {
74                                  if (bean.getName().toLowerCase().startsWith(searchname)) {                          if (bean.getName().toLowerCase().startsWith(searchname)) {
75                                          stationBean.entries.add( bean.toStationEntry() );                                  stationBean.entries.add( bean.toStationEntry() );
76                                  } else {                          } else {
77                                          for (String alias : bean.aliases ) {                                  for (String alias : bean.aliases ) {
78                                                  if (alias.toLowerCase().startsWith(searchname)) {                                          if (alias.toLowerCase().startsWith(searchname)) {
79                                                          stationBean.entries.add( bean.toStationEntry() );                                                  stationBean.entries.add( bean.toStationEntry() );
                                                 }  
80                                          }                                          }
81                                  }                                  }
82                          }                          }
                           
                         Collections.sort(stationBean.entries, new Comparator<StationEntry>() {  
                                 @Override  
                                 public int compare(StationEntry arg0, StationEntry arg1) {  
                                         return arg0.getName().compareTo( arg1.getName() );  
                                 }                                
                         });  
   
                         return stationBean;                      
                 } finally {  
                 //      pm.close();  
83                  }                  }
84    
85                    Collections.sort(stationBean.entries, new Comparator<StationEntry>() {
86                            @Override
87                            public int compare(StationEntry arg0, StationEntry arg1) {
88                                    return arg0.getName().compareTo( arg1.getName() );
89                            }                              
90                    });
91    
92                    return stationBean;                    
93    
94          }          }
95                    
96            @SuppressWarnings("unchecked")
97          public List<JdoStationBean> getAllStations() {          public List<JdoStationBean> getAllStations() {
98                  final String key = "allstations";                  final String key = "allstations";
99                  List<JdoStationBean> result = (List<JdoStationBean>) cache.get(key);                  List<JdoStationBean> result = (List<JdoStationBean>) cache.get(key);
# Line 112  public class StationDAO { Line 102  public class StationDAO {
102                          logger.info("getAllStations Cache miss");                          logger.info("getAllStations Cache miss");
103                                                    
104                          PersistenceManager pm = null;                          PersistenceManager pm = null;
                         final double LAT = 0.4;  
                         final double LNG = 0.75;  
105                                                    
106                          try {                          try {
107                                  pm = PMF.get().getPersistenceManager();                                  pm = PMF.get().getPersistenceManager();
# Line 177  public class StationDAO { Line 165  public class StationDAO {
165    
166    
167          public StationBean getByLocation(double latitude, double longitude)  {          public StationBean getByLocation(double latitude, double longitude)  {
                 /*  
                 List<JdoStationBean> beanList = getByLocationList(latitude,longitude,true);  
                   
                 if (beanList.size() < LOCATION_LIMIT ) {  
                         logger.info("getByLocation failover: " +latitude + "," + longitude);  
                         beanList = getByLocationList(latitude,longitude, false);  
                 }*/  
168                                    
169                  List<JdoStationBean> beanList = getAllStations();                  List<JdoStationBean> beanList = getAllStations();
170    
# Line 219  public class StationDAO { Line 200  public class StationDAO {
200          }          }
201                    
202    
203            @SuppressWarnings("unchecked")
204          public StationBean getByList(String list)  {          public StationBean getByList(String list)  {
205                  PersistenceManager pm = null;                  PersistenceManager pm = null;
206                                    
# Line 234  public class StationDAO { Line 216  public class StationDAO {
216                                  filter.append("id == ").append(part);                                  filter.append("id == ").append(part);
217                          }                                                }                      
218                                                    
                         //String filter = "id == 10 || id == 82"; //TODO: build filter  
219                                                    
220                          pm = PMF.get().getPersistenceManager();                          pm = PMF.get().getPersistenceManager();
221                          Query q = pm.newQuery(JdoStationBean.class);                          Query q = pm.newQuery(JdoStationBean.class);
# Line 257  public class StationDAO { Line 238  public class StationDAO {
238          }          }
239    
240    
241            @SuppressWarnings("unchecked")
242          public int getIdByName(String name)  {          public int getIdByName(String name)  {
243                                    
244                  List<JdoStationBean> beanList = null;                  List<JdoStationBean> beanList = null;

Legend:
Removed from v.1115  
changed lines
  Added in v.1116

  ViewVC Help
Powered by ViewVC 1.1.20