--- android/TrainInfoServiceGoogle/src/dk/thoerup/traininfoservice/StationDAO.java 2010/09/23 15:08:39 1115 +++ android/TrainInfoServiceGoogle/src/dk/thoerup/traininfoservice/StationDAO.java 2010/09/23 15:11:52 1116 @@ -34,6 +34,7 @@ Cache cache; + @SuppressWarnings("unchecked") public StationDAO() { Map props = new HashMap(); props.put(GCacheFactory.EXPIRATION_DELTA, TIMEOUT_SECONDS); @@ -62,48 +63,37 @@ /* damn that JDO sucks so we to the filtering in java-code */ public StationBean getByName(String searchname) { - PersistenceManager pm = null; - - try { - /*pm = PMF.get().getPersistenceManager(); - - - - Query q = pm.newQuery(JdoStationBean.class); - q.setOrdering("name"); - List beanList = (List) q.execute();*/ - List beanList = getAllStations(); - - - StationBean stationBean = new StationBean(); - - searchname = searchname.toLowerCase(); - for(JdoStationBean bean : beanList) { - if (bean.getName().toLowerCase().startsWith(searchname)) { - stationBean.entries.add( bean.toStationEntry() ); - } else { - for (String alias : bean.aliases ) { - if (alias.toLowerCase().startsWith(searchname)) { - stationBean.entries.add( bean.toStationEntry() ); - } + List beanList = getAllStations(); + + + StationBean stationBean = new StationBean(); + + searchname = searchname.toLowerCase(); + for(JdoStationBean bean : beanList) { + if (bean.getName().toLowerCase().startsWith(searchname)) { + stationBean.entries.add( bean.toStationEntry() ); + } else { + for (String alias : bean.aliases ) { + if (alias.toLowerCase().startsWith(searchname)) { + stationBean.entries.add( bean.toStationEntry() ); } } } - - Collections.sort(stationBean.entries, new Comparator() { - @Override - public int compare(StationEntry arg0, StationEntry arg1) { - return arg0.getName().compareTo( arg1.getName() ); - } - }); - - return stationBean; - } finally { - // pm.close(); } + + Collections.sort(stationBean.entries, new Comparator() { + @Override + public int compare(StationEntry arg0, StationEntry arg1) { + return arg0.getName().compareTo( arg1.getName() ); + } + }); + + return stationBean; + } + @SuppressWarnings("unchecked") public List getAllStations() { final String key = "allstations"; List result = (List) cache.get(key); @@ -112,8 +102,6 @@ logger.info("getAllStations Cache miss"); PersistenceManager pm = null; - final double LAT = 0.4; - final double LNG = 0.75; try { pm = PMF.get().getPersistenceManager(); @@ -177,13 +165,6 @@ public StationBean getByLocation(double latitude, double longitude) { - /* - List beanList = getByLocationList(latitude,longitude,true); - - if (beanList.size() < LOCATION_LIMIT ) { - logger.info("getByLocation failover: " +latitude + "," + longitude); - beanList = getByLocationList(latitude,longitude, false); - }*/ List beanList = getAllStations(); @@ -219,6 +200,7 @@ } + @SuppressWarnings("unchecked") public StationBean getByList(String list) { PersistenceManager pm = null; @@ -234,7 +216,6 @@ filter.append("id == ").append(part); } - //String filter = "id == 10 || id == 82"; //TODO: build filter pm = PMF.get().getPersistenceManager(); Query q = pm.newQuery(JdoStationBean.class); @@ -257,6 +238,7 @@ } + @SuppressWarnings("unchecked") public int getIdByName(String name) { List beanList = null;