1 |
package dk.thoerup.traininfoservice.banedk; |
package dk.thoerup.traininfoservice.banedk; |
2 |
|
|
|
import java.sql.Connection; |
|
|
import java.sql.ResultSet; |
|
|
import java.sql.Statement; |
|
3 |
import java.util.ArrayList; |
import java.util.ArrayList; |
4 |
import java.util.Collections; |
import java.util.Collections; |
5 |
import java.util.List; |
import java.util.List; |
13 |
|
|
14 |
import dk.thoerup.circuitbreaker.CircuitBreaker; |
import dk.thoerup.circuitbreaker.CircuitBreaker; |
15 |
import dk.thoerup.circuitbreaker.CircuitBreakerManager; |
import dk.thoerup.circuitbreaker.CircuitBreakerManager; |
16 |
import dk.thoerup.traininfoservice.DBConnection; |
import dk.thoerup.traininfoservice.StationBean; |
17 |
|
import dk.thoerup.traininfoservice.StationDAO; |
18 |
|
|
19 |
public class DepartureFetcher { |
public class DepartureFetcher { |
20 |
|
|
22 |
|
|
23 |
Map<Integer, List<DepartureBean>> cache; |
Map<Integer, List<DepartureBean>> cache; |
24 |
|
|
25 |
|
StationDAO stationDao = new StationDAO(); |
26 |
|
|
27 |
private boolean useTempSite; |
private boolean useTempSite; |
28 |
|
|
29 |
public DepartureFetcher(boolean tempSite, int cacheTimeout) { |
public DepartureFetcher(boolean tempSite, int cacheTimeout) { |
51 |
public List<DepartureBean> lookupDepartures(int stationID) throws Exception { |
public List<DepartureBean> lookupDepartures(int stationID) throws Exception { |
52 |
List<DepartureBean> departureList = new ArrayList<DepartureBean>(); |
List<DepartureBean> departureList = new ArrayList<DepartureBean>(); |
53 |
|
|
54 |
Connection conn = null; |
StationBean station = stationDao.getById(stationID); |
55 |
try |
|
56 |
{ |
if (station.getRegional() != null) { |
57 |
conn = DBConnection.getConnection(); |
List<DepartureBean> list = lookupDepartures(station.getRegional(), "FJRN"); |
58 |
|
departureList.addAll(list); |
|
String SQL = "SELECT stationcode_fjrn, stationcode_stog FROM trainstations WHERE id=" + stationID; |
|
|
Statement stmt = conn.createStatement(); |
|
|
ResultSet rs = stmt.executeQuery(SQL); |
|
|
|
|
|
if (rs.next()) { |
|
|
String code = rs.getString( 1 ); |
|
|
if (! rs.wasNull() ) { |
|
|
List<DepartureBean> list = lookupDepartures(code, "FJRN"); |
|
|
departureList.addAll(list); |
|
|
} |
|
|
|
|
|
code = rs.getString(2); |
|
|
if (! rs.wasNull() ) { |
|
|
List<DepartureBean> list = lookupDepartures(code, "S2"); |
|
|
departureList.addAll(list); |
|
|
} |
|
|
Collections.sort( departureList ); |
|
|
|
|
|
} |
|
|
|
|
|
} finally { |
|
|
if (conn != null && !conn.isClosed() ) { |
|
|
conn.close(); |
|
|
} |
|
59 |
} |
} |
60 |
|
|
61 |
|
if (station.getStrain() != null) { |
62 |
|
List<DepartureBean> list = lookupDepartures(station.getStrain(), "S2"); |
63 |
|
departureList.addAll(list); |
64 |
|
} |
65 |
|
|
66 |
|
Collections.sort( departureList ); |
67 |
|
|
68 |
|
|
69 |
return departureList; |
return departureList; |
70 |
} |
} |
71 |
|
|