Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 72.37 KB | None | 0 0
  1. package com.ogiqvo;
  2.  
  3. import com.ogiqvo.lib.Cube;
  4. import com.ogiqvo.lib.Tile;
  5. import com.ogiqvo.lib.bean.Agency;
  6. import com.ogiqvo.lib.bean.Calendar;
  7. import com.ogiqvo.lib.bean.Carmodel;
  8. import com.ogiqvo.lib.bean.Gradient;
  9. import com.ogiqvo.lib.bean.Lnglat;
  10. import com.ogiqvo.lib.loader.OgiqvoRDBHandler;
  11. import com.ogiqvo.lib.loader.stringref.StringRefBezier;
  12. import com.ogiqvo.lib.loader.stringref.StringRefCar;
  13. import com.ogiqvo.lib.loader.stringref.StringRefEdgeInEdgeSet;
  14. import com.ogiqvo.lib.loader.stringref.StringRefFormation;
  15. import com.ogiqvo.lib.loader.stringref.StringRefInstruction;
  16. import com.ogiqvo.lib.loader.stringref.StringRefPlatform;
  17. import com.ogiqvo.lib.loader.stringref.StringRefRoute;
  18. import com.ogiqvo.lib.loader.stringref.StringRefStation;
  19. import com.ogiqvo.lib.loader.stringref.StringRefTrip;
  20. import com.ogiqvo.lib.loader.stringref.StringRefWait;
  21. import com.ogiqvo.lib.pool.CommitCube;
  22. import com.ogiqvo.lib.pool.CommitTile;
  23.  
  24. import java.sql.Connection;
  25. import java.sql.DriverManager;
  26. import java.sql.PreparedStatement;
  27. import java.sql.ResultSet;
  28. import java.sql.SQLException;
  29. import java.util.ArrayList;
  30. import java.util.Collection;
  31. import java.util.HashMap;
  32. import java.util.HashSet;
  33. import java.util.List;
  34. import java.util.Map;
  35. import java.util.Set;
  36. import java.util.TimeZone;
  37.  
  38. public class OgiqvoH2Handler implements OgiqvoRDBHandler {
  39. String path;
  40. Connection connection;
  41. PreparedStatement addBezierCidsInTilePreparedStatement;
  42. PreparedStatement findMinTimechunkForTilePreparedStatement;
  43. PreparedStatement findMaxTimechunkForTilePreparedStatement;
  44. PreparedStatement addInstructionCidsInCubePreparedStatement;
  45. PreparedStatement addWaitCidsInCubePreparedStatement;
  46. PreparedStatement findAllBezierCidsPreparedStatement;
  47. PreparedStatement findAllRouteCidsPreparedStatement;
  48. PreparedStatement findAllTripCidsForRouteCidPreparedStatement;
  49. PreparedStatement findAllStationCidsPreparedStatement;
  50. PreparedStatement findAllPlatformCidsForStationCidPreparedStatement;
  51. PreparedStatement findObjectiveCidForPlatformCidPreparedStatement;
  52. PreparedStatement findAllInstructionCidsForObjectiveCidsAndTripCidPreparedStatement1;
  53. PreparedStatement findAllInstructionCidsForObjectiveCidsAndTripCidPreparedStatement2;
  54. PreparedStatement findAllWaitCidsForObjectiveCidsAndTripCidPreparedStatement;
  55. PreparedStatement findFormationCidAndDayUtcSecondsForWaitCidPreparedStatement;
  56. PreparedStatement findFormationCidForInstructionCidPreparedStatement;
  57. PreparedStatement findCarCidsForFormationCidPreparedStatement;
  58. PreparedStatement findEdgeCidForBezierCidPreparedStatement;
  59. PreparedStatement findAllBezierCidsForEdgeCidPreparedStatement;
  60. PreparedStatement findAllInstructionCidsForEdgeCidPreparedStatement;
  61. PreparedStatement findPlatformCidForObjectiveCidPreparedStatement;
  62. PreparedStatement findAllWaitCidsForEdgeCidPreparedStatement;
  63. PreparedStatement findAllInstructionCidsForTripCidPreparedStatement;
  64. PreparedStatement findAllWaitCidsForTripCidPreparedStatement;
  65. PreparedStatement findAllEdgeCidsForInstructionCidPreparedStatement;
  66. PreparedStatement findAllEdgeCidsForWaitCidPreparedStatement;
  67. PreparedStatement findTimechunk2tilesForInstructionCidPreparedStatement;
  68. PreparedStatement findTimechunk2tilesForWaitCidPreparedStatement;
  69. PreparedStatement findTilesForInstructionCidAndTimechunkPreparedStatement;
  70. PreparedStatement findTilesForWaitCidAndTimechunkPreparedStatement;
  71. PreparedStatement findDayUtcSecondsForInstructionCidAndObjectiveCidsPreparedStatement;
  72. PreparedStatement addAgenciesPreparedStatement;
  73. PreparedStatement addBeziersPreparedStatement;
  74. PreparedStatement addCalendarsPreparedStatement1;
  75. PreparedStatement addCalendarsPreparedStatement2;
  76. PreparedStatement addCarsPreparedStatement;
  77. PreparedStatement addCarmodelsPreparedStatement;
  78. PreparedStatement addFormations1PreparedStatement;
  79. PreparedStatement addFormations2PreparedStatement;
  80. PreparedStatement addGradientsPreparedStatement;
  81. PreparedStatement addInstructions1PreparedStatement;
  82. PreparedStatement addInstructions2PreparedStatement;
  83. PreparedStatement addPlatformsPreparedStatement;
  84. PreparedStatement addRoutesPreparedStatement;
  85. PreparedStatement addStationsPreparedStatement;
  86. PreparedStatement addTripsPreparedStatement;
  87. PreparedStatement addWaits1PreparedStatement;
  88. PreparedStatement addWaits2PreparedStatement;
  89.  
  90. public OgiqvoH2Handler(String path) {
  91. this.path = path;
  92. }
  93.  
  94. @Override
  95. public void load() {
  96. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  97. try {
  98. connection = DriverManager.getConnection("jdbc:h2:" + this.path+";USER=sa;PASSWORD=Passw0rd");
  99. addBezierCidsInTilePreparedStatement = connection.prepareStatement("SELECT bezier_id FROM beziers");
  100. findMinTimechunkForTilePreparedStatement = connection.prepareStatement("SELECT min_tc FROM cube_timechunk_ranges WHERE x=? AND y=?");
  101. findMaxTimechunkForTilePreparedStatement = connection.prepareStatement("SELECT max_tc FROM cube_timechunk_ranges WHERE x=? AND y=?");
  102. addInstructionCidsInCubePreparedStatement = connection.prepareStatement("SELECT instruction_id FROM cubes_instructions WHERE x=? AND y=? AND tc=?");
  103. addWaitCidsInCubePreparedStatement = connection.prepareStatement("SELECT wait_id FROM cubes_waits WHERE x=? AND y=? AND tc=?");
  104. findAllBezierCidsPreparedStatement = connection.prepareStatement("SELECT bezier_id FROM beziers");
  105. findAllRouteCidsPreparedStatement = connection.prepareStatement("SELECT route_id FROM routes");
  106. findAllTripCidsForRouteCidPreparedStatement = connection.prepareStatement("SELECT trip_id FROM trips WHERE route_id=?");
  107. findAllStationCidsPreparedStatement = connection.prepareStatement("SELECT station_id FROM stations");
  108. findAllPlatformCidsForStationCidPreparedStatement = connection.prepareStatement("SELECT platform_id FROM platforms WHERE station_id=?");
  109. findObjectiveCidForPlatformCidPreparedStatement = connection.prepareStatement("SELECT objective_id FROM objectives WHERE platform_id=?");
  110. findAllInstructionCidsForObjectiveCidsAndTripCidPreparedStatement1 = connection.prepareStatement("SELECT instruction_id FROM instructions WHERE trip_id=? AND first_objective_id=?");
  111. findAllInstructionCidsForObjectiveCidsAndTripCidPreparedStatement2 = connection.prepareStatement("SELECT instruction_id FROM instructions WHERE trip_id=? AND last_objective_id=?");
  112. findAllWaitCidsForObjectiveCidsAndTripCidPreparedStatement = connection.prepareStatement("SELECT wait_id FROM waits WHERE trip_id=? AND objective_id=?");
  113. findFormationCidAndDayUtcSecondsForWaitCidPreparedStatement = connection.prepareStatement("SELECT formation_id,to_utc_seconds,objective_id FROM waits WHERE wait_id=?");
  114. findFormationCidForInstructionCidPreparedStatement = connection.prepareStatement("SELECT formation_id FROM instructions WHERE instruction_id=?");
  115. findCarCidsForFormationCidPreparedStatement = connection.prepareStatement("SELECT car_id FROM formations_cars WHERE formation_id=?");
  116. findEdgeCidForBezierCidPreparedStatement = connection.prepareStatement("SELECT edge_id FROM beziers WHERE bezier_id=?");
  117. findAllBezierCidsForEdgeCidPreparedStatement = connection.prepareStatement("SELECT bezier_id FROM beziers WHERE edge_id=?");
  118. findAllInstructionCidsForEdgeCidPreparedStatement = connection.prepareStatement("SELECT instruction_id FROM instructions_edges WHERE edge_id=?");
  119. findPlatformCidForObjectiveCidPreparedStatement = connection.prepareStatement("SELECT platform_id FROM objectives WHERE objective_id=?");
  120. findAllWaitCidsForEdgeCidPreparedStatement = connection.prepareStatement("SELECT wait_id FROM waits_edges WHERE edge_id=?");
  121. findAllInstructionCidsForTripCidPreparedStatement = connection.prepareStatement("SELECT instruction_id FROM instructions WHERE trip_id=?");
  122. findAllWaitCidsForTripCidPreparedStatement = connection.prepareStatement("SELECT wait_id FROM waits WHERE trip_id=?");
  123. findAllEdgeCidsForInstructionCidPreparedStatement = connection.prepareStatement("SELECT edge_id FROM instructions_edges WHERE instruction_id=?");
  124. findAllEdgeCidsForWaitCidPreparedStatement = connection.prepareStatement("SELECT edge_id FROM waits_edges WHERE wait_id=?");
  125. findTimechunk2tilesForInstructionCidPreparedStatement = connection.prepareStatement("SELECT x,y,tc FROM cubes_instructions WHERE instruction_id=?");
  126. findTimechunk2tilesForWaitCidPreparedStatement = connection.prepareStatement("SELECT x,y,tc FROM cubes_waits WHERE wait_id=?");
  127. findTilesForInstructionCidAndTimechunkPreparedStatement = connection.prepareStatement("SELECT x,y FROM cubes_instructions WHERE instruction_id=? AND tc=?");
  128. findTilesForWaitCidAndTimechunkPreparedStatement = connection.prepareStatement("SELECT x,y FROM cubes_waits WHERE wait_id=? AND tc=?");
  129. findDayUtcSecondsForInstructionCidAndObjectiveCidsPreparedStatement = connection.prepareStatement("SELECT flat_coeffs,first_objective_id,last_objective_id FROM instructions WHERE instruction_id=?");
  130. addAgenciesPreparedStatement = connection.prepareStatement("SELECT agency_id,agency_name,agency_url,agency_timezone,agency_lang,agency_phone" +
  131. " FROM agency WHERE agency_id=?");
  132. addBeziersPreparedStatement = connection.prepareStatement("SELECT bezier_id,gradient0_id,distance0,gradient3_id,distance3,edge_id,from_distance,to_distance,sign" +
  133. " FROM beziers WHERE bezier_id=?");
  134. addCalendarsPreparedStatement1 = connection.prepareStatement("SELECT service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date,name" +
  135. " FROM calendar WHERE service_id=?");
  136. addCalendarsPreparedStatement2 = connection.prepareStatement("SELECT service_id,date,exception_type" +
  137. " FROM calendar_dates WHERE service_id=?");
  138. addCarsPreparedStatement = connection.prepareStatement("SELECT car_id,car_name,carmodel_id" +
  139. " FROM cars WHERE car_id=?");
  140. addCarmodelsPreparedStatement = connection.prepareStatement("SELECT carmodel_id,carmodel_name,carmodel_length,carmodel_width,carmodel_height,carmodel_wheelheight,carmodel_bogielengthdelta,carmodel_couplinglengthdelta,carmodel_3dmodel,carmodel_3dmodel_mime" +
  141. " FROM carmodels WHERE carmodel_id=?");
  142. addFormations1PreparedStatement = connection.prepareStatement("SELECT formation_id,explicit_name" +
  143. " FROM formations WHERE formation_id=?");
  144. addFormations2PreparedStatement = connection.prepareStatement("SELECT formation_id,sequence,car_id,direction,label" +
  145. " FROM formations_cars WHERE formation_id=? ORDER BY sequence");
  146. addGradientsPreparedStatement = connection.prepareStatement("SELECT gradient_id,gradient_lat,gradient_lon,gradient_altitude,gradient_bearing,gradient_slope,gradient_cant" +
  147. " FROM gradients WHERE gradient_id=?");
  148. addInstructions1PreparedStatement = connection.prepareStatement("SELECT instruction_id,trip_id,formation_id,first_car_distance,last_car_distance,flat_coeffs" +
  149. " FROM instructions WHERE instruction_id=?");
  150. addInstructions2PreparedStatement = connection.prepareStatement("SELECT edge_id,from_distance,to_distance,sign" +
  151. " FROM instructions_edges WHERE instruction_id=? ORDER BY seq");
  152. addPlatformsPreparedStatement = connection.prepareStatement("SELECT platform_id,platform_name,station_id" +
  153. " FROM platforms WHERE platform_id=?");
  154. addRoutesPreparedStatement = connection.prepareStatement("SELECT route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color,route_text_color" +
  155. " FROM routes WHERE route_id=?");
  156. addStationsPreparedStatement = connection.prepareStatement("SELECT station_id,station_code,station_name,station_desc,station_lat,station_lon,station_url,station_timezone" +
  157. " FROM stations WHERE station_id=?");
  158. addTripsPreparedStatement = connection.prepareStatement("SELECT trip_id,explicit_name,route_id,service_id,trip_headsign,trip_short_name,direction_id,rank_name,rank_color,rank_text_color" +
  159. " FROM trips WHERE trip_id=?");
  160. addWaits1PreparedStatement = connection.prepareStatement("SELECT w.wait_id,w.trip_id,w.formation_id,o.platform_id,w.first_bogie_distance,w.first_car_distance,w.last_car_distance,w.from_utc_seconds,w.to_utc_seconds,w.is_serving" +
  161. " FROM waits w LEFT OUTER JOIN objectives o ON w.objective_id=o.objective_id WHERE w.wait_id=?");
  162. addWaits2PreparedStatement = connection.prepareStatement("SELECT edge_id,from_distance,to_distance,sign" +
  163. " FROM waits_edges WHERE wait_id=? ORDER BY seq");
  164. } catch (SQLException e) {
  165. e.printStackTrace();
  166. }
  167. }
  168. }
  169.  
  170. @Override
  171. public void addBezierCidsInTile(CommitTile tileId, Set<String> cids) {
  172. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  173. ResultSet resultSet = null;
  174. try {
  175. resultSet = addBezierCidsInTilePreparedStatement.executeQuery();
  176. while (resultSet.next()) {
  177. String bezierCid = resultSet.getString(1);
  178. cids.add(bezierCid);
  179. }
  180. } catch (SQLException e) {
  181. e.printStackTrace();
  182. } finally {
  183. if (resultSet != null) {
  184. try {
  185. resultSet.close();
  186. } catch (SQLException e) {
  187. e.printStackTrace();
  188. }
  189. }
  190. }
  191. }
  192. }
  193.  
  194. @Override
  195. public int findMinTimechunkForTile(CommitTile tileId) {
  196. int x = tileId.getTile().x;
  197. int y = -tileId.getTile().y - 1;
  198. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  199. ResultSet resultSet = null;
  200. try {
  201. findMinTimechunkForTilePreparedStatement.setInt(1, x);
  202. findMinTimechunkForTilePreparedStatement.setInt(2, y);
  203. resultSet = findMinTimechunkForTilePreparedStatement.executeQuery();
  204. while (resultSet.next()) {
  205. return resultSet.getInt(1);
  206. }
  207. } catch (SQLException e) {
  208. e.printStackTrace();
  209. } finally {
  210. if (resultSet != null) {
  211. try {
  212. resultSet.close();
  213. } catch (SQLException e) {
  214. e.printStackTrace();
  215. }
  216. }
  217. }
  218. }
  219. return 0;
  220. }
  221.  
  222. @Override
  223. public int findMaxTimechunkForTile(CommitTile tileId) {
  224. int x = tileId.getTile().x;
  225. int y = -tileId.getTile().y - 1;
  226. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  227. ResultSet resultSet = null;
  228. try {
  229. findMaxTimechunkForTilePreparedStatement.setInt(1, x);
  230. findMaxTimechunkForTilePreparedStatement.setInt(2, y);
  231. resultSet = findMaxTimechunkForTilePreparedStatement.executeQuery();
  232. while (resultSet.next()) {
  233. return resultSet.getInt(1);
  234. }
  235. } catch (SQLException e) {
  236. e.printStackTrace();
  237. } finally {
  238. if (resultSet != null) {
  239. try {
  240. resultSet.close();
  241. } catch (SQLException e) {
  242. e.printStackTrace();
  243. }
  244. }
  245. }
  246. }
  247. return 0;
  248. }
  249.  
  250. @Override
  251. public void addInstructionCidsInCube(CommitCube cubeId, Set<String> cids) {
  252. Cube c = cubeId.getCube();
  253. Tile tile = cubeId.getCube().tile;
  254. int x = tile.x;
  255. int y = -tile.y - 1;
  256. int tc = cubeId.getCube().timechunk;
  257. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  258. ResultSet resultSet = null;
  259. try {
  260. addInstructionCidsInCubePreparedStatement.setInt(1, x);
  261. addInstructionCidsInCubePreparedStatement.setInt(2, y);
  262. addInstructionCidsInCubePreparedStatement.setInt(3, tc);
  263. resultSet = addInstructionCidsInCubePreparedStatement.executeQuery();
  264. while (resultSet.next()) {
  265. String instructionCid = resultSet.getString(1);
  266. cids.add(instructionCid);
  267. }
  268. } catch (SQLException e) {
  269. e.printStackTrace();
  270. } finally {
  271. if (resultSet != null) {
  272. try {
  273. resultSet.close();
  274. } catch (SQLException e) {
  275. e.printStackTrace();
  276. }
  277. }
  278. }
  279. }
  280. }
  281.  
  282. @Override
  283. public void addWaitCidsInCube(CommitCube cubeId, Set<String> cids) {
  284. Tile tile = cubeId.getCube().tile;
  285. int x = tile.x;
  286. int y = -tile.y - 1;
  287. int tc = cubeId.getCube().timechunk;
  288. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  289. ResultSet resultSet = null;
  290. try {
  291. addWaitCidsInCubePreparedStatement.setInt(1, x);
  292. addWaitCidsInCubePreparedStatement.setInt(2, y);
  293. addWaitCidsInCubePreparedStatement.setInt(3, tc);
  294. resultSet = addWaitCidsInCubePreparedStatement.executeQuery();
  295. while (resultSet.next()) {
  296. String instructionCid = resultSet.getString(1);
  297. cids.add(instructionCid);
  298. }
  299. } catch (SQLException e) {
  300. e.printStackTrace();
  301. } finally {
  302. if (resultSet != null) {
  303. try {
  304. resultSet.close();
  305. } catch (SQLException e) {
  306. e.printStackTrace();
  307. }
  308. }
  309. }
  310. }
  311. }
  312.  
  313. @Override
  314. public Collection<String> findAllBezierCids() {
  315. Collection<String> cids = new HashSet<>();
  316. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  317. ResultSet resultSet = null;
  318. try {
  319. resultSet = findAllBezierCidsPreparedStatement.executeQuery();
  320. while (resultSet.next()) {
  321. String bezierCid = resultSet.getString(1);
  322. cids.add(bezierCid);
  323. }
  324. } catch (SQLException e) {
  325. e.printStackTrace();
  326. } finally {
  327. if (resultSet != null) {
  328. try {
  329. resultSet.close();
  330. } catch (SQLException e) {
  331. e.printStackTrace();
  332. }
  333. }
  334. }
  335. }
  336. return cids;
  337. }
  338.  
  339. @Override
  340. public Collection<String> findAllRouteCids() {
  341. Collection<String> cids = new HashSet<>();
  342. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  343. ResultSet resultSet = null;
  344. try {
  345. resultSet = findAllRouteCidsPreparedStatement.executeQuery();
  346. while (resultSet.next()) {
  347. String routeCid = resultSet.getString(1);
  348. cids.add(routeCid);
  349. }
  350. } catch (SQLException e) {
  351. e.printStackTrace();
  352. } finally {
  353. if (resultSet != null) {
  354. try {
  355. resultSet.close();
  356. } catch (SQLException e) {
  357. e.printStackTrace();
  358. }
  359. }
  360. }
  361. }
  362. return cids;
  363. }
  364.  
  365. @Override
  366. public Collection<String> findAllTripCidsForRouteCid(String routeCid) {
  367. Collection<String> cids = new HashSet<>();
  368. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  369. ResultSet resultSet = null;
  370. try {
  371. findAllTripCidsForRouteCidPreparedStatement.setString(1, routeCid);
  372. resultSet = findAllTripCidsForRouteCidPreparedStatement.executeQuery();
  373. while (resultSet.next()) {
  374. String tripCid = resultSet.getString(1);
  375. cids.add(tripCid);
  376. }
  377. } catch (SQLException e) {
  378. e.printStackTrace();
  379. } finally {
  380. if (resultSet != null) {
  381. try {
  382. resultSet.close();
  383. } catch (SQLException e) {
  384. e.printStackTrace();
  385. }
  386. }
  387. }
  388. }
  389. return cids;
  390. }
  391.  
  392. @Override
  393. public Collection<String> findAllStationCids() {
  394. Collection<String> cids = new HashSet<>();
  395. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  396. ResultSet resultSet = null;
  397. try {
  398. resultSet = findAllStationCidsPreparedStatement.executeQuery();
  399. while (resultSet.next()) {
  400. String stationCid = resultSet.getString(1);
  401. cids.add(stationCid);
  402. }
  403. } catch (SQLException e) {
  404. e.printStackTrace();
  405. } finally {
  406. if (resultSet != null) {
  407. try {
  408. resultSet.close();
  409. } catch (SQLException e) {
  410. e.printStackTrace();
  411. }
  412. }
  413. }
  414. }
  415. return cids;
  416. }
  417.  
  418. @Override
  419. public Collection<String> findAllPlatformCidsForStationCid(String stationCid) {
  420. Collection<String> cids = new HashSet<>();
  421. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  422. ResultSet resultSet = null;
  423. try {
  424. findAllPlatformCidsForStationCidPreparedStatement.setString(1, stationCid);
  425. resultSet = findAllPlatformCidsForStationCidPreparedStatement.executeQuery();
  426. while (resultSet.next()) {
  427. String platformCid = resultSet.getString(1);
  428. cids.add(platformCid);
  429. }
  430. } catch (SQLException e) {
  431. e.printStackTrace();
  432. } finally {
  433. if (resultSet != null) {
  434. try {
  435. resultSet.close();
  436. } catch (SQLException e) {
  437. e.printStackTrace();
  438. }
  439. }
  440. }
  441. }
  442. return cids;
  443. }
  444.  
  445. @Override
  446. public String findObjectiveCidForPlatformCid(String platformCid) {
  447. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  448. ResultSet resultSet = null;
  449. try {
  450. findObjectiveCidForPlatformCidPreparedStatement.setString(1, platformCid);
  451. resultSet = findObjectiveCidForPlatformCidPreparedStatement.executeQuery();
  452. while (resultSet.next()) {
  453. return resultSet.getString(1);
  454. }
  455. } catch (SQLException e) {
  456. e.printStackTrace();
  457. } finally {
  458. if (resultSet != null) {
  459. try {
  460. resultSet.close();
  461. } catch (SQLException e) {
  462. e.printStackTrace();
  463. }
  464. }
  465. }
  466. }
  467. return null;
  468. }
  469.  
  470. @Override
  471. public Collection<String> findAllInstructionCidsForObjectiveCidsAndTripCid(String tripCid, Collection<String> objectiveCids) {
  472. Collection<String> cids = new HashSet<>();
  473. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  474. ResultSet resultSet = null;
  475. for (String objectiveCid : objectiveCids) {
  476. try {
  477. findAllInstructionCidsForObjectiveCidsAndTripCidPreparedStatement1.setString(1, tripCid);
  478. findAllInstructionCidsForObjectiveCidsAndTripCidPreparedStatement1.setString(2, objectiveCid);
  479. resultSet = findAllInstructionCidsForObjectiveCidsAndTripCidPreparedStatement1.executeQuery();
  480. while (resultSet.next()) {
  481. String waitCid = resultSet.getString(1);
  482. cids.add(waitCid);
  483. }
  484. } catch (SQLException e) {
  485. e.printStackTrace();
  486. } finally {
  487. if (resultSet != null) {
  488. try {
  489. resultSet.close();
  490. } catch (SQLException e) {
  491. e.printStackTrace();
  492. }
  493. }
  494. }
  495.  
  496. try {
  497. findAllInstructionCidsForObjectiveCidsAndTripCidPreparedStatement2.setString(1, tripCid);
  498. findAllInstructionCidsForObjectiveCidsAndTripCidPreparedStatement2.setString(2, objectiveCid);
  499. resultSet = findAllInstructionCidsForObjectiveCidsAndTripCidPreparedStatement2.executeQuery();
  500. while (resultSet.next()) {
  501. String waitCid = resultSet.getString(1);
  502. cids.add(waitCid);
  503. }
  504. } catch (SQLException e) {
  505. e.printStackTrace();
  506. } finally {
  507. if (resultSet != null) {
  508. try {
  509. resultSet.close();
  510. } catch (SQLException e) {
  511. e.printStackTrace();
  512. }
  513. }
  514. }
  515. }
  516. }
  517. return cids;
  518. }
  519.  
  520. @Override
  521. public Collection<String> findAllWaitCidsForObjectiveCidsAndTripCid(String tripCid, Collection<String> objectiveCids) {
  522. Collection<String> cids = new HashSet<>();
  523. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  524. ResultSet resultSet = null;
  525. for (String objectiveCid : objectiveCids) {
  526. try {
  527. findAllWaitCidsForObjectiveCidsAndTripCidPreparedStatement.setString(1, tripCid);
  528. findAllWaitCidsForObjectiveCidsAndTripCidPreparedStatement.setString(2, objectiveCid);
  529. resultSet = findAllWaitCidsForObjectiveCidsAndTripCidPreparedStatement.executeQuery();
  530. while (resultSet.next()) {
  531. String waitCid = resultSet.getString(1);
  532. cids.add(waitCid);
  533. }
  534. } catch (SQLException e) {
  535. e.printStackTrace();
  536. } finally {
  537. if (resultSet != null) {
  538. try {
  539. resultSet.close();
  540. } catch (SQLException e) {
  541. e.printStackTrace();
  542. }
  543. }
  544. }
  545. }
  546. }
  547. return cids;
  548. }
  549.  
  550. @Override
  551. public void findFormationCidAndDayUtcSecondsForWaitCid(String waitCid, FormationCidAndDayUtcSeconds result) {
  552. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  553. ResultSet resultSet = null;
  554. try {
  555. findFormationCidAndDayUtcSecondsForWaitCidPreparedStatement.setString(1, waitCid);
  556. resultSet = findFormationCidAndDayUtcSecondsForWaitCidPreparedStatement.executeQuery();
  557. while (resultSet.next()) {
  558. String formationCid = resultSet.getString(1);
  559. int toUtcSeconds = resultSet.getInt(2);
  560. result.formationCid = formationCid;
  561. result.dayUtcSeconds = toUtcSeconds;
  562. result.platformCid = this.findPlatformCidForObjectiveCid(resultSet.getString(3));
  563. }
  564. } catch (SQLException e) {
  565. e.printStackTrace();
  566. } finally {
  567. if (resultSet != null) {
  568. try {
  569. resultSet.close();
  570. } catch (SQLException e) {
  571. e.printStackTrace();
  572. }
  573. }
  574. }
  575. }
  576. }
  577.  
  578. @Override
  579. public String findFormationCidForInstructionCid(String instructionCid) {
  580. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  581. ResultSet resultSet = null;
  582. try {
  583. findFormationCidForInstructionCidPreparedStatement.setString(1, instructionCid);
  584. resultSet = findFormationCidForInstructionCidPreparedStatement.executeQuery();
  585. while (resultSet.next()) {
  586. return resultSet.getString(1);
  587. }
  588. } catch (SQLException e) {
  589. e.printStackTrace();
  590. } finally {
  591. if (resultSet != null) {
  592. try {
  593. resultSet.close();
  594. } catch (SQLException e) {
  595. e.printStackTrace();
  596. }
  597. }
  598. }
  599. }
  600. return null;
  601. }
  602.  
  603. @Override
  604. public List<String> findCarCidsForFormationCid(String formationCid) {
  605. List<String> carCids = new ArrayList<>();
  606. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  607. ResultSet resultSet = null;
  608. try {
  609. findCarCidsForFormationCidPreparedStatement.setString(1, formationCid);
  610. resultSet = findCarCidsForFormationCidPreparedStatement.executeQuery();
  611. while (resultSet.next()) {
  612. String carCid = resultSet.getString(1);
  613. carCids.add(carCid);
  614. }
  615. } catch (SQLException e) {
  616. e.printStackTrace();
  617. } finally {
  618. if (resultSet != null) {
  619. try {
  620. resultSet.close();
  621. } catch (SQLException e) {
  622. e.printStackTrace();
  623. }
  624. }
  625. }
  626. }
  627. return carCids;
  628. }
  629.  
  630. @Override
  631. public String findEdgeCidForBezierCid(String bezierCid) {
  632. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  633. ResultSet resultSet = null;
  634. try {
  635. findEdgeCidForBezierCidPreparedStatement.setString(1, bezierCid);
  636. resultSet = findEdgeCidForBezierCidPreparedStatement.executeQuery();
  637. while (resultSet.next()) {
  638. return resultSet.getString(1);
  639. }
  640. } catch (SQLException e) {
  641. e.printStackTrace();
  642. } finally {
  643. if (resultSet != null) {
  644. try {
  645. resultSet.close();
  646. } catch (SQLException e) {
  647. e.printStackTrace();
  648. }
  649. }
  650. }
  651. }
  652. return null;
  653. }
  654.  
  655. @Override
  656. public Collection<String> findAllBezierCidsForEdgeCid(String edgeCid) {
  657. Collection<String> bezierCids = new HashSet<>();
  658. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  659. ResultSet resultSet = null;
  660. try {
  661. findAllBezierCidsForEdgeCidPreparedStatement.setString(1, edgeCid);
  662. resultSet = findAllBezierCidsForEdgeCidPreparedStatement.executeQuery();
  663. while (resultSet.next()) {
  664. String bezierCid = resultSet.getString(1);
  665. bezierCids.add(bezierCid);
  666. }
  667. } catch (SQLException e) {
  668. e.printStackTrace();
  669. } finally {
  670. if (resultSet != null) {
  671. try {
  672. resultSet.close();
  673. } catch (SQLException e) {
  674. e.printStackTrace();
  675. }
  676. }
  677. }
  678. }
  679. return bezierCids;
  680. }
  681.  
  682. @Override
  683. public Collection<String> findAllInstructionCidsForEdgeCid(String edgeCid) {
  684. Collection<String> instructionCids = new HashSet<>();
  685. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  686. ResultSet resultSet = null;
  687. try {
  688. findAllInstructionCidsForEdgeCidPreparedStatement.setString(1, edgeCid);
  689. resultSet = findAllInstructionCidsForEdgeCidPreparedStatement.executeQuery();
  690. while (resultSet.next()) {
  691. String instructionCid = resultSet.getString(1);
  692. instructionCids.add(instructionCid);
  693. }
  694. } catch (SQLException e) {
  695. e.printStackTrace();
  696. } finally {
  697. if (resultSet != null) {
  698. try {
  699. resultSet.close();
  700. } catch (SQLException e) {
  701. e.printStackTrace();
  702. }
  703. }
  704. }
  705. }
  706. return instructionCids;
  707. }
  708.  
  709. private String findPlatformCidForObjectiveCid(String objectiveCid) {
  710. ResultSet resultSet = null;
  711. try {
  712. findPlatformCidForObjectiveCidPreparedStatement.setString(1, objectiveCid);
  713. resultSet = findPlatformCidForObjectiveCidPreparedStatement.executeQuery();
  714. while (resultSet.next()) {
  715. return resultSet.getString(1);
  716. }
  717. } catch (SQLException e) {
  718. e.printStackTrace();
  719. } finally {
  720. if (resultSet != null) {
  721. try {
  722. resultSet.close();
  723. } catch (SQLException e) {
  724. e.printStackTrace();
  725. }
  726. }
  727. }
  728. return null;
  729. }
  730.  
  731. @Override
  732. public Collection<String> findAllWaitCidsForEdgeCid(String edgeCid) {
  733. Collection<String> waitCids = new HashSet<>();
  734. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  735. ResultSet resultSet = null;
  736. try {
  737. findAllWaitCidsForEdgeCidPreparedStatement.setString(1, edgeCid);
  738. resultSet = findAllWaitCidsForEdgeCidPreparedStatement.executeQuery();
  739. while (resultSet.next()) {
  740. String waitCid = resultSet.getString(1);
  741. waitCids.add(waitCid);
  742. }
  743. } catch (SQLException e) {
  744. e.printStackTrace();
  745. } finally {
  746. if (resultSet != null) {
  747. try {
  748. resultSet.close();
  749. } catch (SQLException e) {
  750. e.printStackTrace();
  751. }
  752. }
  753. }
  754. }
  755. return waitCids;
  756. }
  757.  
  758. @Override
  759. public Collection<String> findAllInstructionCidsForTripCid(String tripCid) {
  760. Collection<String> instructionCids = new HashSet<>();
  761. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  762. ResultSet resultSet = null;
  763. try {
  764. findAllInstructionCidsForTripCidPreparedStatement.setString(1, tripCid);
  765. resultSet = findAllInstructionCidsForTripCidPreparedStatement.executeQuery();
  766. while (resultSet.next()) {
  767. String instructionCid = resultSet.getString(1);
  768. instructionCids.add(instructionCid);
  769. }
  770. } catch (SQLException e) {
  771. e.printStackTrace();
  772. } finally {
  773. if (resultSet != null) {
  774. try {
  775. resultSet.close();
  776. } catch (SQLException e) {
  777. e.printStackTrace();
  778. }
  779. }
  780. }
  781. }
  782. return instructionCids;
  783. }
  784.  
  785. @Override
  786. public Collection<String> findAllWaitCidsForTripCid(String tripCid) {
  787. Collection<String> waitCids = new HashSet<>();
  788. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  789. ResultSet resultSet = null;
  790. try {
  791. findAllWaitCidsForTripCidPreparedStatement.setString(1, tripCid);
  792. resultSet = findAllWaitCidsForTripCidPreparedStatement.executeQuery();
  793. while (resultSet.next()) {
  794. String waitCid = resultSet.getString(1);
  795. waitCids.add(waitCid);
  796. }
  797. } catch (SQLException e) {
  798. e.printStackTrace();
  799. } finally {
  800. if (resultSet != null) {
  801. try {
  802. resultSet.close();
  803. } catch (SQLException e) {
  804. e.printStackTrace();
  805. }
  806. }
  807. }
  808. }
  809. return waitCids;
  810. }
  811.  
  812. @Override
  813. public Collection<String> findAllEdgeCidsForInstructionCid(String instructionCid) {
  814. Collection<String> edgeCids = new HashSet<>();
  815. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  816. ResultSet resultSet = null;
  817. try {
  818. findAllEdgeCidsForInstructionCidPreparedStatement.setString(1, instructionCid);
  819. resultSet = findAllEdgeCidsForInstructionCidPreparedStatement.executeQuery();
  820. while (resultSet.next()) {
  821. String edgeCid = resultSet.getString(1);
  822. edgeCids.add(edgeCid);
  823. }
  824. } catch (SQLException e) {
  825. e.printStackTrace();
  826. } finally {
  827. if (resultSet != null) {
  828. try {
  829. resultSet.close();
  830. } catch (SQLException e) {
  831. e.printStackTrace();
  832. }
  833. }
  834. }
  835. }
  836. return edgeCids;
  837. }
  838.  
  839. @Override
  840. public Collection<String> findAllEdgeCidsForWaitCid(String waitCid) {
  841. Collection<String> edgeCids = new HashSet<>();
  842. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  843. ResultSet resultSet = null;
  844. try {
  845. findAllEdgeCidsForWaitCidPreparedStatement.setString(1, waitCid);
  846. resultSet = findAllEdgeCidsForWaitCidPreparedStatement.executeQuery();
  847. while (resultSet.next()) {
  848. String edgeCid = resultSet.getString(1);
  849. edgeCids.add(edgeCid);
  850. }
  851. } catch (SQLException e) {
  852. e.printStackTrace();
  853. } finally {
  854. if (resultSet != null) {
  855. try {
  856. resultSet.close();
  857. } catch (SQLException e) {
  858. e.printStackTrace();
  859. }
  860. }
  861. }
  862. }
  863. return edgeCids;
  864. }
  865.  
  866. @Override
  867. public Map<Integer, Collection<Tile>> findTimechunk2tilesForInstructionCid(String instructionCid) {
  868. Map<Integer, Collection<Tile>> result = new HashMap<>();
  869. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  870. ResultSet resultSet = null;
  871. try {
  872. findTimechunk2tilesForInstructionCidPreparedStatement.setString(1, instructionCid);
  873. resultSet = findTimechunk2tilesForInstructionCidPreparedStatement.executeQuery();
  874. while (resultSet.next()) {
  875. int x = resultSet.getInt(1);
  876. int y = resultSet.getInt(2);
  877. int tc = resultSet.getInt(3);
  878. if (!result.containsKey(tc)) {
  879. Collection<Tile> tiles = new HashSet<>();
  880. result.put(tc, tiles);
  881. }
  882. Tile tile = new Tile(x, y, 16);
  883. result.get(tc).add(tile);
  884. }
  885. } catch (SQLException e) {
  886. e.printStackTrace();
  887. } finally {
  888. if (resultSet != null) {
  889. try {
  890. resultSet.close();
  891. } catch (SQLException e) {
  892. e.printStackTrace();
  893. }
  894. }
  895. }
  896. }
  897. return result;
  898. }
  899.  
  900. @Override
  901. public Map<Integer, Collection<Tile>> findTimechunk2tilesForWaitCid(String waitCid) {
  902. Map<Integer, Collection<Tile>> result = new HashMap<>();
  903. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  904. ResultSet resultSet = null;
  905. try {
  906. findTimechunk2tilesForWaitCidPreparedStatement.setString(1, waitCid);
  907. resultSet = findTimechunk2tilesForWaitCidPreparedStatement.executeQuery();
  908. while (resultSet.next()) {
  909. int x = resultSet.getInt(1);
  910. int y = resultSet.getInt(2);
  911. int tc = resultSet.getInt(3);
  912. if (!result.containsKey(tc)) {
  913. Collection<Tile> tiles = new HashSet<>();
  914. result.put(tc, tiles);
  915. }
  916. Tile tile = new Tile(x, y, 16);
  917. result.get(tc).add(tile);
  918. }
  919. } catch (SQLException e) {
  920. e.printStackTrace();
  921. } finally {
  922. if (resultSet != null) {
  923. try {
  924. resultSet.close();
  925. } catch (SQLException e) {
  926. e.printStackTrace();
  927. }
  928. }
  929. }
  930. }
  931. return result;
  932. }
  933.  
  934. @Override
  935. public Collection<Tile> findTilesForInstructionCidAndTimechunk(String instructionCid, int timechunk) {
  936. Collection<Tile> result = new HashSet<>();
  937. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  938. ResultSet resultSet = null;
  939. try {
  940. findTilesForInstructionCidAndTimechunkPreparedStatement.setString(1, instructionCid);
  941. findTilesForInstructionCidAndTimechunkPreparedStatement.setInt(2, timechunk);
  942. resultSet = findTilesForInstructionCidAndTimechunkPreparedStatement.executeQuery();
  943. while (resultSet.next()) {
  944. int x = resultSet.getInt(1);
  945. int y = resultSet.getInt(2);
  946. Tile tile = new Tile(x, y, 16);
  947. result.add(tile);
  948. }
  949. } catch (SQLException e) {
  950. e.printStackTrace();
  951. } finally {
  952. if (resultSet != null) {
  953. try {
  954. resultSet.close();
  955. } catch (SQLException e) {
  956. e.printStackTrace();
  957. }
  958. }
  959. }
  960. }
  961. return result;
  962. }
  963.  
  964. @Override
  965. public Collection<Tile> findTilesForWaitCidAndTimechunk(String waitCid, int timechunk) {
  966. Collection<Tile> result = new HashSet<>();
  967. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  968. ResultSet resultSet = null;
  969. try {
  970. findTilesForWaitCidAndTimechunkPreparedStatement.setString(1, waitCid);
  971. findTilesForWaitCidAndTimechunkPreparedStatement.setInt(2, timechunk);
  972. resultSet = findTilesForWaitCidAndTimechunkPreparedStatement.executeQuery();
  973. while (resultSet.next()) {
  974. int x = resultSet.getInt(1);
  975. int y = resultSet.getInt(2);
  976. Tile tile = new Tile(x, y, 16);
  977. result.add(tile);
  978. }
  979. } catch (SQLException e) {
  980. e.printStackTrace();
  981. } finally {
  982. if (resultSet != null) {
  983. try {
  984. resultSet.close();
  985. } catch (SQLException e) {
  986. e.printStackTrace();
  987. }
  988. }
  989. }
  990. }
  991. return result;
  992. }
  993.  
  994. @Override
  995. public void findDayUtcSecondsForInstructionCidAndObjectiveCids(String instructionCid, Set<String> objectiveCids, FormationCidAndDayUtcSeconds result) {
  996. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  997. ResultSet resultSet = null;
  998. try {
  999. findDayUtcSecondsForInstructionCidAndObjectiveCidsPreparedStatement.setString(1, instructionCid);
  1000. resultSet = findTilesForWaitCidAndTimechunkPreparedStatement.executeQuery();
  1001. while (resultSet.next()) {
  1002. String flatCoeffsStr = resultSet.getString(1);
  1003. String firstObjectiveCid = resultSet.getString(2);
  1004. String lastObjectiveCid = resultSet.getString(3);
  1005. if (!objectiveCids.contains(firstObjectiveCid) && !objectiveCids.contains(lastObjectiveCid)) {
  1006. continue;
  1007. }
  1008. String[] flatCoeffs = flatCoeffsStr.split(",");
  1009. if (objectiveCids.contains(firstObjectiveCid)) {
  1010. result.dayUtcSeconds = Double.parseDouble(flatCoeffs[0]);
  1011. result.platformCid = this.findPlatformCidForObjectiveCid(firstObjectiveCid);
  1012. } else {
  1013. result.dayUtcSeconds = Double.parseDouble(flatCoeffs[flatCoeffs.length - 2]);
  1014. result.platformCid = this.findPlatformCidForObjectiveCid(lastObjectiveCid);
  1015. }
  1016. }
  1017. } catch (SQLException e) {
  1018. e.printStackTrace();
  1019. } finally {
  1020. if (resultSet != null) {
  1021. try {
  1022. resultSet.close();
  1023. } catch (SQLException e) {
  1024. e.printStackTrace();
  1025. }
  1026. }
  1027. }
  1028. }
  1029. }
  1030.  
  1031. @Override
  1032. public void addAgencies(Collection<String> cids, Map<String, Agency> results) {
  1033. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  1034. ResultSet resultSet = null;
  1035. try {
  1036. for (String cid : cids) {
  1037. if (results.containsKey(cid)) {
  1038. continue;
  1039. }
  1040. addAgenciesPreparedStatement.setString(1, cid);
  1041. resultSet = addAgenciesPreparedStatement.executeQuery();
  1042. while (resultSet.next()) {
  1043. String agencyCid = resultSet.getString(1);
  1044. String agencyName = resultSet.getString(2);
  1045. String agencyUrl = resultSet.getString(3);
  1046. String agencyTimezone = resultSet.getString(4);
  1047. String agencyLang = resultSet.getString(5);
  1048. String agencyPhone = resultSet.getString(6);
  1049. TimeZone tz = TimeZone.getTimeZone(agencyTimezone);
  1050. Agency a = new Agency(agencyCid, agencyName, agencyUrl, tz, agencyLang, agencyPhone);
  1051. results.put(cid, a);
  1052. }
  1053. }
  1054. } catch (SQLException e) {
  1055. e.printStackTrace();
  1056. } finally {
  1057. if (resultSet != null) {
  1058. try {
  1059. resultSet.close();
  1060. } catch (SQLException e) {
  1061. e.printStackTrace();
  1062. }
  1063. }
  1064. }
  1065. }
  1066. }
  1067.  
  1068. @Override
  1069. public void addBeziers(Collection<String> cids, Map<String, StringRefBezier> results) {
  1070. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  1071. ResultSet resultSet = null;
  1072. try {
  1073. for (String cid : cids) {
  1074. if (results.containsKey(cid)) {
  1075. continue;
  1076. }
  1077. addBeziersPreparedStatement.setString(1, cid);
  1078. resultSet = addBeziersPreparedStatement.executeQuery();
  1079. while (resultSet.next()) {
  1080. String bezierCid = resultSet.getString(1);
  1081. String gradient0id = resultSet.getString(2);
  1082. double distance0 = resultSet.getDouble(3);
  1083. String gradient3id = resultSet.getString(4);
  1084. double distance3 = resultSet.getDouble(5);
  1085. String edgeId = resultSet.getString(6);
  1086. double fromDistance = resultSet.getDouble(7);
  1087. double toDistance = resultSet.getDouble(8);
  1088. int sgn = resultSet.getInt(9);
  1089. StringRefBezier br = new StringRefBezier(bezierCid, gradient0id, distance0, gradient3id, distance3, edgeId, fromDistance, toDistance, sgn > 0);
  1090. results.put(cid, br);
  1091. }
  1092. }
  1093. } catch (SQLException e) {
  1094. e.printStackTrace();
  1095. } finally {
  1096. if (resultSet != null) {
  1097. try {
  1098. resultSet.close();
  1099. } catch (SQLException e) {
  1100. e.printStackTrace();
  1101. }
  1102. }
  1103. }
  1104. }
  1105. }
  1106.  
  1107. @Override
  1108. public void addCalendars(Collection<String> cids, Map<String, Calendar> results) {
  1109. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  1110. ResultSet resultSet = null;
  1111. try {
  1112. for (String cid : cids) {
  1113. if (results.containsKey(cid)) {
  1114. continue;
  1115. }
  1116. addCalendarsPreparedStatement1.setString(1, cid);
  1117. resultSet = addCalendarsPreparedStatement1.executeQuery();
  1118. while (resultSet.next()) {
  1119. String serviceCid = resultSet.getString(1);
  1120. boolean monday = resultSet.getInt(2) == 1;
  1121. boolean tuesday = resultSet.getInt(3) == 1;
  1122. boolean wednesday = resultSet.getInt(4) == 1;
  1123. boolean thursday = resultSet.getInt(5) == 1;
  1124. boolean friday = resultSet.getInt(6) == 1;
  1125. boolean saturday = resultSet.getInt(7) == 1;
  1126. boolean sunday = resultSet.getInt(8) == 1;
  1127. int startDate = resultSet.getInt(9);
  1128. int endDate = resultSet.getInt(10);
  1129. String name = resultSet.getString(11);
  1130.  
  1131. boolean[] weeklyCalendarRules = new boolean[]{sunday, monday, tuesday, wednesday, thursday, friday, saturday};
  1132. Map<Integer, Boolean> ex = new HashMap<>();
  1133.  
  1134. ResultSet resultSet2 = null;
  1135. addCalendarsPreparedStatement2.setString(1, cid);
  1136. resultSet2 = addCalendarsPreparedStatement2.executeQuery();
  1137. while (resultSet2.next()) {
  1138. int day1970 = resultSet2.getInt(2);
  1139. int etype = resultSet2.getInt(3);
  1140. ex.put(day1970, etype == 1);
  1141. }
  1142. resultSet2.close();
  1143.  
  1144. Calendar cr = new Calendar(serviceCid, weeklyCalendarRules, ex, startDate, endDate);
  1145. results.put(cid, cr);
  1146. }
  1147. }
  1148. } catch (SQLException e) {
  1149. e.printStackTrace();
  1150. } finally {
  1151. if (resultSet != null) {
  1152. try {
  1153. resultSet.close();
  1154. } catch (SQLException e) {
  1155. e.printStackTrace();
  1156. }
  1157. }
  1158. }
  1159. }
  1160. }
  1161.  
  1162. @Override
  1163. public void addCars(Collection<String> cids, Map<String, StringRefCar> results) {
  1164. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  1165. ResultSet resultSet = null;
  1166. try {
  1167. for (String cid : cids) {
  1168. if (results.containsKey(cid)) {
  1169. continue;
  1170. }
  1171. addCarsPreparedStatement.setString(1, cid);
  1172. resultSet = addCarsPreparedStatement.executeQuery();
  1173. while (resultSet.next()) {
  1174. String carCid = resultSet.getString(1);
  1175. String carName = resultSet.getString(2);
  1176. String carmodelId = resultSet.getString(3);
  1177. StringRefCar cr = new StringRefCar(carCid, carmodelId, carName);
  1178. results.put(cid, cr);
  1179. }
  1180. }
  1181. } catch (SQLException e) {
  1182. e.printStackTrace();
  1183. } finally {
  1184. if (resultSet != null) {
  1185. try {
  1186. resultSet.close();
  1187. } catch (SQLException e) {
  1188. e.printStackTrace();
  1189. }
  1190. }
  1191. }
  1192. }
  1193. }
  1194.  
  1195. @Override
  1196. public void addCarmodels(Collection<String> cids, Map<String, Carmodel> results) {
  1197. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  1198. ResultSet resultSet = null;
  1199. try {
  1200. for (String cid : cids) {
  1201. if (results.containsKey(cid)) {
  1202. continue;
  1203. }
  1204. addCarmodelsPreparedStatement.setString(1, cid);
  1205. resultSet = addCarmodelsPreparedStatement.executeQuery();
  1206. while (resultSet.next()) {
  1207. String carmodelCid = resultSet.getString(1);
  1208. String carmodelName = resultSet.getString(2);
  1209. double carmodelLength = resultSet.getDouble(3);
  1210. double carmodelWidth = resultSet.getDouble(4);
  1211. double carmodelHeight = resultSet.getDouble(5);
  1212. double carmodelWheelHeight = resultSet.getDouble(6);
  1213. double carmodelBogieLengthDelta = resultSet.getDouble(7);
  1214. double carmodelCouplingLengthDelta = resultSet.getDouble(8);
  1215. byte[] carmodel3dModel = resultSet.getBytes(9);
  1216. String carmodel3dModelMime = resultSet.getString(10);
  1217. Carmodel cm = new Carmodel(carmodelCid, carmodelName, carmodelLength, carmodelWidth, carmodelHeight, carmodelWheelHeight, carmodelBogieLengthDelta, carmodelCouplingLengthDelta, carmodel3dModel, carmodel3dModelMime);
  1218. results.put(cid, cm);
  1219. }
  1220. }
  1221. } catch (SQLException e) {
  1222. e.printStackTrace();
  1223. } finally {
  1224. if (resultSet != null) {
  1225. try {
  1226. resultSet.close();
  1227. } catch (SQLException e) {
  1228. e.printStackTrace();
  1229. }
  1230. }
  1231. }
  1232. }
  1233. }
  1234.  
  1235. @Override
  1236. public void addFormations(Collection<String> cids, Map<String, StringRefFormation> results) {
  1237. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  1238. ResultSet resultSet = null;
  1239. try {
  1240. for (String cid : cids) {
  1241. if (results.containsKey(cid)) {
  1242. continue;
  1243. }
  1244. String formationCid = null;
  1245. String explicitName = null;
  1246.  
  1247. addFormations1PreparedStatement.setString(1, cid);
  1248. resultSet = addFormations1PreparedStatement.executeQuery();
  1249. while (resultSet.next()) {
  1250. formationCid = resultSet.getString(1);
  1251. explicitName = resultSet.getString(2);
  1252. break;
  1253. }
  1254.  
  1255. List<String> carIds = new ArrayList<>();
  1256. List<Boolean> direction1s = new ArrayList<>();
  1257. List<String> labels = new ArrayList<>();
  1258.  
  1259. addFormations2PreparedStatement.setString(1, cid);
  1260. resultSet = addFormations2PreparedStatement.executeQuery();
  1261. while (resultSet.next()) {
  1262. String carId = resultSet.getString(3);
  1263. boolean directionIs1 = resultSet.getInt(4) == 1;
  1264. String label = resultSet.getString(5);
  1265.  
  1266. carIds.add(carId);
  1267. direction1s.add(directionIs1);
  1268. labels.add(label);
  1269. }
  1270.  
  1271. StringRefFormation fr = new StringRefFormation(formationCid, carIds, direction1s, labels, explicitName);
  1272. results.put(cid, fr);
  1273. }
  1274. } catch (SQLException e) {
  1275. e.printStackTrace();
  1276. } finally {
  1277. if (resultSet != null) {
  1278. try {
  1279. resultSet.close();
  1280. } catch (SQLException e) {
  1281. e.printStackTrace();
  1282. }
  1283. }
  1284. }
  1285. }
  1286. }
  1287.  
  1288. @Override
  1289. public void addGradients(Collection<String> cids, Map<String, Gradient> results) {
  1290. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  1291. ResultSet resultSet = null;
  1292. try {
  1293. for (String cid : cids) {
  1294. if (results.containsKey(cid)) {
  1295. continue;
  1296. }
  1297. addGradientsPreparedStatement.setString(1, cid);
  1298. resultSet = addGradientsPreparedStatement.executeQuery();
  1299. while (resultSet.next()) {
  1300. String gradientCid = resultSet.getString(1);
  1301. double gradientLat = resultSet.getDouble(2);
  1302. double gradientLon = resultSet.getDouble(3);
  1303. double gradientAlt = resultSet.getDouble(4);
  1304. double gradientBearing = resultSet.getDouble(5);
  1305. double gradientSlope = resultSet.getDouble(6);
  1306. double gradientCant = resultSet.getDouble(7);
  1307. Lnglat ll = new Lnglat(gradientLon, gradientLat);
  1308. Gradient g = new Gradient(gradientCid, ll, gradientBearing, gradientAlt, gradientSlope, gradientCant);
  1309. results.put(cid, g);
  1310. }
  1311. }
  1312. } catch (SQLException e) {
  1313. e.printStackTrace();
  1314. } finally {
  1315. if (resultSet != null) {
  1316. try {
  1317. resultSet.close();
  1318. } catch (SQLException e) {
  1319. e.printStackTrace();
  1320. }
  1321. }
  1322. }
  1323. }
  1324. }
  1325.  
  1326. @Override
  1327. public void addInstructions(Collection<String> cids, Map<String, StringRefInstruction> results) {
  1328. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  1329. ResultSet resultSet = null;
  1330. try {
  1331. for (String cid : cids) {
  1332. if (results.containsKey(cid)) {
  1333. continue;
  1334. }
  1335. String instructionCid = null;
  1336. String tripCid = null;
  1337. String formationCid = null;
  1338. double firstCarDistance = 0;
  1339. double lastCarDistance = 0;
  1340. String flatCoeffs = null;
  1341. List<Double> flatCoeffsBoxed = null;
  1342.  
  1343. addInstructions1PreparedStatement.setString(1, cid);
  1344. resultSet = addInstructions1PreparedStatement.executeQuery();
  1345. while (resultSet.next()) {
  1346. instructionCid = resultSet.getString(1);
  1347. tripCid = resultSet.getString(2);
  1348. formationCid = resultSet.getString(3);
  1349. firstCarDistance = resultSet.getDouble(4);
  1350. lastCarDistance = resultSet.getDouble(5);
  1351. flatCoeffs = resultSet.getString(6);
  1352. String[] flatCoeffsSplitted = flatCoeffs.split(",");
  1353. flatCoeffsBoxed = new ArrayList<>(flatCoeffsSplitted.length);
  1354. for (int i = 0; i < flatCoeffsSplitted.length; i++) {
  1355. flatCoeffsBoxed.add(Double.parseDouble(flatCoeffsSplitted[i]));
  1356. }
  1357. break;
  1358. }
  1359.  
  1360. List<StringRefEdgeInEdgeSet> eies = new ArrayList<>();
  1361. addInstructions2PreparedStatement.setString(1, cid);
  1362. resultSet = addInstructions2PreparedStatement.executeQuery();
  1363. while (resultSet.next()) {
  1364. String edgeCid = resultSet.getString(1);
  1365. double fromDistance = resultSet.getDouble(2);
  1366. double toDistance = resultSet.getDouble(3);
  1367. int sgn = resultSet.getInt(4);
  1368. StringRefEdgeInEdgeSet eie = new StringRefEdgeInEdgeSet();
  1369. eie.edgeCid = edgeCid;
  1370. eie.fromDistance = fromDistance;
  1371. eie.toDistance = toDistance;
  1372. eie.sgn = sgn;
  1373. eies.add(eie);
  1374. }
  1375.  
  1376. StringRefInstruction ir = new StringRefInstruction(instructionCid, formationCid, tripCid, firstCarDistance, lastCarDistance, eies, flatCoeffsBoxed,null,null);
  1377. results.put(cid, ir);
  1378. }
  1379. } catch (SQLException e) {
  1380. e.printStackTrace();
  1381. } finally {
  1382. if (resultSet != null) {
  1383. try {
  1384. resultSet.close();
  1385. } catch (SQLException e) {
  1386. e.printStackTrace();
  1387. }
  1388. }
  1389. }
  1390. }
  1391. }
  1392.  
  1393. @Override
  1394. public void addPlatforms(Collection<String> cids, Map<String, StringRefPlatform> results) {
  1395. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  1396. ResultSet resultSet = null;
  1397. try {
  1398. for (String cid : cids) {
  1399. if (results.containsKey(cid)) {
  1400. continue;
  1401. }
  1402. addPlatformsPreparedStatement.setString(1, cid);
  1403. resultSet = addPlatformsPreparedStatement.executeQuery();
  1404. while (resultSet.next()) {
  1405. String platformCid = resultSet.getString(1);
  1406. String platformName = resultSet.getString(2);
  1407. String stationCid = resultSet.getString(3);
  1408.  
  1409. StringRefPlatform pr = new StringRefPlatform(platformCid, stationCid, platformName, null);
  1410. results.put(cid, pr);
  1411. }
  1412. }
  1413. } catch (SQLException e) {
  1414. e.printStackTrace();
  1415. } finally {
  1416. if (resultSet != null) {
  1417. try {
  1418. resultSet.close();
  1419. } catch (SQLException e) {
  1420. e.printStackTrace();
  1421. }
  1422. }
  1423. }
  1424. }
  1425. }
  1426.  
  1427. @Override
  1428. public void addRoutes(Collection<String> cids, Map<String, StringRefRoute> results) {
  1429. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  1430. ResultSet resultSet = null;
  1431. try {
  1432. for (String cid : cids) {
  1433. if (results.containsKey(cid)) {
  1434. continue;
  1435. }
  1436. addRoutesPreparedStatement.setString(1, cid);
  1437. resultSet = addRoutesPreparedStatement.executeQuery();
  1438. while (resultSet.next()) {
  1439. String routeCid = resultSet.getString(1);
  1440. String agencyCid = resultSet.getString(2);
  1441. String routeShortName = resultSet.getString(3);
  1442. String routeLongName = resultSet.getString(4);
  1443. String routeDesc = resultSet.getString(5);
  1444. int routeType = resultSet.getInt(6);
  1445. String routeUrl = resultSet.getString(7);
  1446. String routeColor = resultSet.getString(8);
  1447. String routeTextColor = resultSet.getString(9);
  1448. if (routeColor != null && routeColor.equals("")) {
  1449. routeColor = null;
  1450. }
  1451. if (routeTextColor != null && routeTextColor.equals("")) {
  1452. routeTextColor = null;
  1453. }
  1454.  
  1455. StringRefRoute rr = new StringRefRoute(routeCid, agencyCid, routeShortName, routeLongName, routeDesc, routeUrl, routeColor, routeTextColor);
  1456. results.put(cid, rr);
  1457. }
  1458. }
  1459. } catch (SQLException e) {
  1460. e.printStackTrace();
  1461. } finally {
  1462. if (resultSet != null) {
  1463. try {
  1464. resultSet.close();
  1465. } catch (SQLException e) {
  1466. e.printStackTrace();
  1467. }
  1468. }
  1469. }
  1470. }
  1471. }
  1472.  
  1473. @Override
  1474. public void addStations(Collection<String> cids, Map<String, StringRefStation> results) {
  1475. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  1476. ResultSet resultSet = null;
  1477. try {
  1478. for (String cid : cids) {
  1479. if (results.containsKey(cid)) {
  1480. continue;
  1481. }
  1482. addStationsPreparedStatement.setString(1, cid);
  1483. resultSet = addStationsPreparedStatement.executeQuery();
  1484. while (resultSet.next()) {
  1485. String stationCid = resultSet.getString(1);
  1486. String stationCode = resultSet.getString(2);
  1487. String stationName = resultSet.getString(3);
  1488. String stationDesc = resultSet.getString(4);
  1489. double stationLat = resultSet.getDouble(5);
  1490. double stationLon = resultSet.getDouble(6);
  1491. String stationUrl = resultSet.getString(7);
  1492. String stationTimezone = resultSet.getString(8);
  1493. TimeZone tz = TimeZone.getTimeZone(stationTimezone);
  1494.  
  1495. StringRefStation sr = new StringRefStation(stationCid, stationCode, stationName, stationDesc, stationLat, stationLon, tz, stationUrl);
  1496. results.put(cid, sr);
  1497. }
  1498. }
  1499. } catch (SQLException e) {
  1500. e.printStackTrace();
  1501. } finally {
  1502. if (resultSet != null) {
  1503. try {
  1504. resultSet.close();
  1505. } catch (SQLException e) {
  1506. e.printStackTrace();
  1507. }
  1508. }
  1509. }
  1510. }
  1511. }
  1512.  
  1513. @Override
  1514. public void addTrips(Collection<String> cids, Map<String, StringRefTrip> results) {
  1515. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  1516. ResultSet resultSet = null;
  1517. try {
  1518. for (String cid : cids) {
  1519. if (results.containsKey(cid)) {
  1520. continue;
  1521. }
  1522. addTripsPreparedStatement.setString(1, cid);
  1523. resultSet = addTripsPreparedStatement.executeQuery();
  1524. while (resultSet.next()) {
  1525. String tripCid = resultSet.getString(1);
  1526. String explicitName = resultSet.getString(2);
  1527. String routeCid = resultSet.getString(3);
  1528. String serviceCid = resultSet.getString(4);
  1529. String tripHeadsign = resultSet.getString(5);
  1530. String tripShortName = resultSet.getString(6);
  1531. boolean directionIs1 = resultSet.getInt(7) == 1;
  1532. String rankName = resultSet.getString(8);
  1533. String rankColor = resultSet.getString(9);
  1534. String rankTextColor = resultSet.getString(10);
  1535. if (rankColor != null && rankColor.equals("")) {
  1536. rankColor = null;
  1537. }
  1538. if (rankTextColor != null && rankTextColor.equals("")) {
  1539. rankTextColor = null;
  1540. }
  1541.  
  1542. StringRefTrip tr = new StringRefTrip(tripCid, explicitName, routeCid, serviceCid, tripHeadsign, tripShortName, directionIs1, rankName, rankColor, rankTextColor);
  1543. results.put(cid, tr);
  1544. }
  1545. }
  1546. } catch (SQLException e) {
  1547. e.printStackTrace();
  1548. } finally {
  1549. if (resultSet != null) {
  1550. try {
  1551. resultSet.close();
  1552. } catch (SQLException e) {
  1553. e.printStackTrace();
  1554. }
  1555. }
  1556. }
  1557. }
  1558. }
  1559.  
  1560. @Override
  1561. public void addWaits(Collection<String> cids, Map<String, StringRefWait> results) {
  1562. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  1563. ResultSet resultSet = null;
  1564. try {
  1565. for (String cid : cids) {
  1566. if (results.containsKey(cid)) {
  1567. continue;
  1568. }
  1569. String waitCid = null;
  1570. String tripCid = null;
  1571. String formationCid = null;
  1572. String platformCid = null;
  1573. double firstBogieDistance = 0;
  1574. double firstCarDistance = 0;
  1575. double lastCarDistance = 0;
  1576. double fromUtcSeconds = 0;
  1577. double toUtcSeconds = 0;
  1578. boolean isServing = false;
  1579.  
  1580. addWaits1PreparedStatement.setString(1, cid);
  1581. resultSet = addWaits1PreparedStatement.executeQuery();
  1582. while (resultSet.next()) {
  1583. waitCid = resultSet.getString(1);
  1584. tripCid = resultSet.getString(2);
  1585. formationCid = resultSet.getString(3);
  1586. platformCid = resultSet.getString(4);
  1587. firstBogieDistance = resultSet.getDouble(5);
  1588. firstCarDistance = resultSet.getDouble(6);
  1589. lastCarDistance = resultSet.getDouble(7);
  1590. fromUtcSeconds = resultSet.getDouble(8);
  1591. toUtcSeconds = resultSet.getDouble(9);
  1592. isServing = resultSet.getInt(10) == 1;
  1593. break;
  1594. }
  1595.  
  1596. List<StringRefEdgeInEdgeSet> eies = new ArrayList<>();
  1597. addWaits2PreparedStatement.setString(1, cid);
  1598. resultSet = addWaits2PreparedStatement.executeQuery();
  1599. while (resultSet.next()) {
  1600. String edgeCid = resultSet.getString(1);
  1601. double fromDistance = resultSet.getDouble(2);
  1602. double toDistance = resultSet.getDouble(3);
  1603. int sgn = resultSet.getInt(4);
  1604. StringRefEdgeInEdgeSet eie = new StringRefEdgeInEdgeSet();
  1605. eie.edgeCid = edgeCid;
  1606. eie.fromDistance = fromDistance;
  1607. eie.toDistance = toDistance;
  1608. eie.sgn = sgn;
  1609. eies.add(eie);
  1610. }
  1611.  
  1612. StringRefWait ir = new StringRefWait(waitCid, formationCid, tripCid, platformCid, fromUtcSeconds, toUtcSeconds, firstCarDistance, lastCarDistance, firstBogieDistance, isServing, eies);
  1613. results.put(cid, ir);
  1614. }
  1615. } catch (SQLException e) {
  1616. e.printStackTrace();
  1617. } finally {
  1618. if (resultSet != null) {
  1619. try {
  1620. resultSet.close();
  1621. } catch (SQLException e) {
  1622. e.printStackTrace();
  1623. }
  1624. }
  1625. }
  1626. }
  1627. }
  1628. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement