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); |
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); |
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(); |
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 |
|
|
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 |
|
|
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); |
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; |