Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ogiqvo;
- import com.ogiqvo.lib.Cube;
- import com.ogiqvo.lib.Tile;
- import com.ogiqvo.lib.bean.Agency;
- import com.ogiqvo.lib.bean.Calendar;
- import com.ogiqvo.lib.bean.Carmodel;
- import com.ogiqvo.lib.bean.Gradient;
- import com.ogiqvo.lib.bean.Lnglat;
- import com.ogiqvo.lib.loader.OgiqvoRDBHandler;
- import com.ogiqvo.lib.loader.stringref.StringRefBezier;
- import com.ogiqvo.lib.loader.stringref.StringRefCar;
- import com.ogiqvo.lib.loader.stringref.StringRefEdgeInEdgeSet;
- import com.ogiqvo.lib.loader.stringref.StringRefFormation;
- import com.ogiqvo.lib.loader.stringref.StringRefInstruction;
- import com.ogiqvo.lib.loader.stringref.StringRefPlatform;
- import com.ogiqvo.lib.loader.stringref.StringRefRoute;
- import com.ogiqvo.lib.loader.stringref.StringRefStation;
- import com.ogiqvo.lib.loader.stringref.StringRefTrip;
- import com.ogiqvo.lib.loader.stringref.StringRefWait;
- import com.ogiqvo.lib.pool.CommitCube;
- import com.ogiqvo.lib.pool.CommitTile;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import java.util.TimeZone;
- public class OgiqvoH2Handler implements OgiqvoRDBHandler {
- String path;
- Connection connection;
- PreparedStatement addBezierCidsInTilePreparedStatement;
- PreparedStatement findMinTimechunkForTilePreparedStatement;
- PreparedStatement findMaxTimechunkForTilePreparedStatement;
- PreparedStatement addInstructionCidsInCubePreparedStatement;
- PreparedStatement addWaitCidsInCubePreparedStatement;
- PreparedStatement findAllBezierCidsPreparedStatement;
- PreparedStatement findAllRouteCidsPreparedStatement;
- PreparedStatement findAllTripCidsForRouteCidPreparedStatement;
- PreparedStatement findAllStationCidsPreparedStatement;
- PreparedStatement findAllPlatformCidsForStationCidPreparedStatement;
- PreparedStatement findObjectiveCidForPlatformCidPreparedStatement;
- PreparedStatement findAllInstructionCidsForObjectiveCidsAndTripCidPreparedStatement1;
- PreparedStatement findAllInstructionCidsForObjectiveCidsAndTripCidPreparedStatement2;
- PreparedStatement findAllWaitCidsForObjectiveCidsAndTripCidPreparedStatement;
- PreparedStatement findFormationCidAndDayUtcSecondsForWaitCidPreparedStatement;
- PreparedStatement findFormationCidForInstructionCidPreparedStatement;
- PreparedStatement findCarCidsForFormationCidPreparedStatement;
- PreparedStatement findEdgeCidForBezierCidPreparedStatement;
- PreparedStatement findAllBezierCidsForEdgeCidPreparedStatement;
- PreparedStatement findAllInstructionCidsForEdgeCidPreparedStatement;
- PreparedStatement findPlatformCidForObjectiveCidPreparedStatement;
- PreparedStatement findAllWaitCidsForEdgeCidPreparedStatement;
- PreparedStatement findAllInstructionCidsForTripCidPreparedStatement;
- PreparedStatement findAllWaitCidsForTripCidPreparedStatement;
- PreparedStatement findAllEdgeCidsForInstructionCidPreparedStatement;
- PreparedStatement findAllEdgeCidsForWaitCidPreparedStatement;
- PreparedStatement findTimechunk2tilesForInstructionCidPreparedStatement;
- PreparedStatement findTimechunk2tilesForWaitCidPreparedStatement;
- PreparedStatement findTilesForInstructionCidAndTimechunkPreparedStatement;
- PreparedStatement findTilesForWaitCidAndTimechunkPreparedStatement;
- PreparedStatement findDayUtcSecondsForInstructionCidAndObjectiveCidsPreparedStatement;
- PreparedStatement addAgenciesPreparedStatement;
- PreparedStatement addBeziersPreparedStatement;
- PreparedStatement addCalendarsPreparedStatement1;
- PreparedStatement addCalendarsPreparedStatement2;
- PreparedStatement addCarsPreparedStatement;
- PreparedStatement addCarmodelsPreparedStatement;
- PreparedStatement addFormations1PreparedStatement;
- PreparedStatement addFormations2PreparedStatement;
- PreparedStatement addGradientsPreparedStatement;
- PreparedStatement addInstructions1PreparedStatement;
- PreparedStatement addInstructions2PreparedStatement;
- PreparedStatement addPlatformsPreparedStatement;
- PreparedStatement addRoutesPreparedStatement;
- PreparedStatement addStationsPreparedStatement;
- PreparedStatement addTripsPreparedStatement;
- PreparedStatement addWaits1PreparedStatement;
- PreparedStatement addWaits2PreparedStatement;
- public OgiqvoH2Handler(String path) {
- this.path = path;
- }
- @Override
- public void load() {
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- try {
- connection = DriverManager.getConnection("jdbc:h2:" + this.path+";USER=sa;PASSWORD=Passw0rd");
- addBezierCidsInTilePreparedStatement = connection.prepareStatement("SELECT bezier_id FROM beziers");
- findMinTimechunkForTilePreparedStatement = connection.prepareStatement("SELECT min_tc FROM cube_timechunk_ranges WHERE x=? AND y=?");
- findMaxTimechunkForTilePreparedStatement = connection.prepareStatement("SELECT max_tc FROM cube_timechunk_ranges WHERE x=? AND y=?");
- addInstructionCidsInCubePreparedStatement = connection.prepareStatement("SELECT instruction_id FROM cubes_instructions WHERE x=? AND y=? AND tc=?");
- addWaitCidsInCubePreparedStatement = connection.prepareStatement("SELECT wait_id FROM cubes_waits WHERE x=? AND y=? AND tc=?");
- findAllBezierCidsPreparedStatement = connection.prepareStatement("SELECT bezier_id FROM beziers");
- findAllRouteCidsPreparedStatement = connection.prepareStatement("SELECT route_id FROM routes");
- findAllTripCidsForRouteCidPreparedStatement = connection.prepareStatement("SELECT trip_id FROM trips WHERE route_id=?");
- findAllStationCidsPreparedStatement = connection.prepareStatement("SELECT station_id FROM stations");
- findAllPlatformCidsForStationCidPreparedStatement = connection.prepareStatement("SELECT platform_id FROM platforms WHERE station_id=?");
- findObjectiveCidForPlatformCidPreparedStatement = connection.prepareStatement("SELECT objective_id FROM objectives WHERE platform_id=?");
- findAllInstructionCidsForObjectiveCidsAndTripCidPreparedStatement1 = connection.prepareStatement("SELECT instruction_id FROM instructions WHERE trip_id=? AND first_objective_id=?");
- findAllInstructionCidsForObjectiveCidsAndTripCidPreparedStatement2 = connection.prepareStatement("SELECT instruction_id FROM instructions WHERE trip_id=? AND last_objective_id=?");
- findAllWaitCidsForObjectiveCidsAndTripCidPreparedStatement = connection.prepareStatement("SELECT wait_id FROM waits WHERE trip_id=? AND objective_id=?");
- findFormationCidAndDayUtcSecondsForWaitCidPreparedStatement = connection.prepareStatement("SELECT formation_id,to_utc_seconds,objective_id FROM waits WHERE wait_id=?");
- findFormationCidForInstructionCidPreparedStatement = connection.prepareStatement("SELECT formation_id FROM instructions WHERE instruction_id=?");
- findCarCidsForFormationCidPreparedStatement = connection.prepareStatement("SELECT car_id FROM formations_cars WHERE formation_id=?");
- findEdgeCidForBezierCidPreparedStatement = connection.prepareStatement("SELECT edge_id FROM beziers WHERE bezier_id=?");
- findAllBezierCidsForEdgeCidPreparedStatement = connection.prepareStatement("SELECT bezier_id FROM beziers WHERE edge_id=?");
- findAllInstructionCidsForEdgeCidPreparedStatement = connection.prepareStatement("SELECT instruction_id FROM instructions_edges WHERE edge_id=?");
- findPlatformCidForObjectiveCidPreparedStatement = connection.prepareStatement("SELECT platform_id FROM objectives WHERE objective_id=?");
- findAllWaitCidsForEdgeCidPreparedStatement = connection.prepareStatement("SELECT wait_id FROM waits_edges WHERE edge_id=?");
- findAllInstructionCidsForTripCidPreparedStatement = connection.prepareStatement("SELECT instruction_id FROM instructions WHERE trip_id=?");
- findAllWaitCidsForTripCidPreparedStatement = connection.prepareStatement("SELECT wait_id FROM waits WHERE trip_id=?");
- findAllEdgeCidsForInstructionCidPreparedStatement = connection.prepareStatement("SELECT edge_id FROM instructions_edges WHERE instruction_id=?");
- findAllEdgeCidsForWaitCidPreparedStatement = connection.prepareStatement("SELECT edge_id FROM waits_edges WHERE wait_id=?");
- findTimechunk2tilesForInstructionCidPreparedStatement = connection.prepareStatement("SELECT x,y,tc FROM cubes_instructions WHERE instruction_id=?");
- findTimechunk2tilesForWaitCidPreparedStatement = connection.prepareStatement("SELECT x,y,tc FROM cubes_waits WHERE wait_id=?");
- findTilesForInstructionCidAndTimechunkPreparedStatement = connection.prepareStatement("SELECT x,y FROM cubes_instructions WHERE instruction_id=? AND tc=?");
- findTilesForWaitCidAndTimechunkPreparedStatement = connection.prepareStatement("SELECT x,y FROM cubes_waits WHERE wait_id=? AND tc=?");
- findDayUtcSecondsForInstructionCidAndObjectiveCidsPreparedStatement = connection.prepareStatement("SELECT flat_coeffs,first_objective_id,last_objective_id FROM instructions WHERE instruction_id=?");
- addAgenciesPreparedStatement = connection.prepareStatement("SELECT agency_id,agency_name,agency_url,agency_timezone,agency_lang,agency_phone" +
- " FROM agency WHERE agency_id=?");
- addBeziersPreparedStatement = connection.prepareStatement("SELECT bezier_id,gradient0_id,distance0,gradient3_id,distance3,edge_id,from_distance,to_distance,sign" +
- " FROM beziers WHERE bezier_id=?");
- addCalendarsPreparedStatement1 = connection.prepareStatement("SELECT service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date,name" +
- " FROM calendar WHERE service_id=?");
- addCalendarsPreparedStatement2 = connection.prepareStatement("SELECT service_id,date,exception_type" +
- " FROM calendar_dates WHERE service_id=?");
- addCarsPreparedStatement = connection.prepareStatement("SELECT car_id,car_name,carmodel_id" +
- " FROM cars WHERE car_id=?");
- 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" +
- " FROM carmodels WHERE carmodel_id=?");
- addFormations1PreparedStatement = connection.prepareStatement("SELECT formation_id,explicit_name" +
- " FROM formations WHERE formation_id=?");
- addFormations2PreparedStatement = connection.prepareStatement("SELECT formation_id,sequence,car_id,direction,label" +
- " FROM formations_cars WHERE formation_id=? ORDER BY sequence");
- addGradientsPreparedStatement = connection.prepareStatement("SELECT gradient_id,gradient_lat,gradient_lon,gradient_altitude,gradient_bearing,gradient_slope,gradient_cant" +
- " FROM gradients WHERE gradient_id=?");
- addInstructions1PreparedStatement = connection.prepareStatement("SELECT instruction_id,trip_id,formation_id,first_car_distance,last_car_distance,flat_coeffs" +
- " FROM instructions WHERE instruction_id=?");
- addInstructions2PreparedStatement = connection.prepareStatement("SELECT edge_id,from_distance,to_distance,sign" +
- " FROM instructions_edges WHERE instruction_id=? ORDER BY seq");
- addPlatformsPreparedStatement = connection.prepareStatement("SELECT platform_id,platform_name,station_id" +
- " FROM platforms WHERE platform_id=?");
- 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" +
- " FROM routes WHERE route_id=?");
- addStationsPreparedStatement = connection.prepareStatement("SELECT station_id,station_code,station_name,station_desc,station_lat,station_lon,station_url,station_timezone" +
- " FROM stations WHERE station_id=?");
- 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" +
- " FROM trips WHERE trip_id=?");
- 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" +
- " FROM waits w LEFT OUTER JOIN objectives o ON w.objective_id=o.objective_id WHERE w.wait_id=?");
- addWaits2PreparedStatement = connection.prepareStatement("SELECT edge_id,from_distance,to_distance,sign" +
- " FROM waits_edges WHERE wait_id=? ORDER BY seq");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- @Override
- public void addBezierCidsInTile(CommitTile tileId, Set<String> cids) {
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- resultSet = addBezierCidsInTilePreparedStatement.executeQuery();
- while (resultSet.next()) {
- String bezierCid = resultSet.getString(1);
- cids.add(bezierCid);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- @Override
- public int findMinTimechunkForTile(CommitTile tileId) {
- int x = tileId.getTile().x;
- int y = -tileId.getTile().y - 1;
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- findMinTimechunkForTilePreparedStatement.setInt(1, x);
- findMinTimechunkForTilePreparedStatement.setInt(2, y);
- resultSet = findMinTimechunkForTilePreparedStatement.executeQuery();
- while (resultSet.next()) {
- return resultSet.getInt(1);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return 0;
- }
- @Override
- public int findMaxTimechunkForTile(CommitTile tileId) {
- int x = tileId.getTile().x;
- int y = -tileId.getTile().y - 1;
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- findMaxTimechunkForTilePreparedStatement.setInt(1, x);
- findMaxTimechunkForTilePreparedStatement.setInt(2, y);
- resultSet = findMaxTimechunkForTilePreparedStatement.executeQuery();
- while (resultSet.next()) {
- return resultSet.getInt(1);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return 0;
- }
- @Override
- public void addInstructionCidsInCube(CommitCube cubeId, Set<String> cids) {
- Cube c = cubeId.getCube();
- Tile tile = cubeId.getCube().tile;
- int x = tile.x;
- int y = -tile.y - 1;
- int tc = cubeId.getCube().timechunk;
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- addInstructionCidsInCubePreparedStatement.setInt(1, x);
- addInstructionCidsInCubePreparedStatement.setInt(2, y);
- addInstructionCidsInCubePreparedStatement.setInt(3, tc);
- resultSet = addInstructionCidsInCubePreparedStatement.executeQuery();
- while (resultSet.next()) {
- String instructionCid = resultSet.getString(1);
- cids.add(instructionCid);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- @Override
- public void addWaitCidsInCube(CommitCube cubeId, Set<String> cids) {
- Tile tile = cubeId.getCube().tile;
- int x = tile.x;
- int y = -tile.y - 1;
- int tc = cubeId.getCube().timechunk;
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- addWaitCidsInCubePreparedStatement.setInt(1, x);
- addWaitCidsInCubePreparedStatement.setInt(2, y);
- addWaitCidsInCubePreparedStatement.setInt(3, tc);
- resultSet = addWaitCidsInCubePreparedStatement.executeQuery();
- while (resultSet.next()) {
- String instructionCid = resultSet.getString(1);
- cids.add(instructionCid);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- @Override
- public Collection<String> findAllBezierCids() {
- Collection<String> cids = new HashSet<>();
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- resultSet = findAllBezierCidsPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String bezierCid = resultSet.getString(1);
- cids.add(bezierCid);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return cids;
- }
- @Override
- public Collection<String> findAllRouteCids() {
- Collection<String> cids = new HashSet<>();
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- resultSet = findAllRouteCidsPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String routeCid = resultSet.getString(1);
- cids.add(routeCid);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return cids;
- }
- @Override
- public Collection<String> findAllTripCidsForRouteCid(String routeCid) {
- Collection<String> cids = new HashSet<>();
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- findAllTripCidsForRouteCidPreparedStatement.setString(1, routeCid);
- resultSet = findAllTripCidsForRouteCidPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String tripCid = resultSet.getString(1);
- cids.add(tripCid);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return cids;
- }
- @Override
- public Collection<String> findAllStationCids() {
- Collection<String> cids = new HashSet<>();
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- resultSet = findAllStationCidsPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String stationCid = resultSet.getString(1);
- cids.add(stationCid);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return cids;
- }
- @Override
- public Collection<String> findAllPlatformCidsForStationCid(String stationCid) {
- Collection<String> cids = new HashSet<>();
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- findAllPlatformCidsForStationCidPreparedStatement.setString(1, stationCid);
- resultSet = findAllPlatformCidsForStationCidPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String platformCid = resultSet.getString(1);
- cids.add(platformCid);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return cids;
- }
- @Override
- public String findObjectiveCidForPlatformCid(String platformCid) {
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- findObjectiveCidForPlatformCidPreparedStatement.setString(1, platformCid);
- resultSet = findObjectiveCidForPlatformCidPreparedStatement.executeQuery();
- while (resultSet.next()) {
- return resultSet.getString(1);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return null;
- }
- @Override
- public Collection<String> findAllInstructionCidsForObjectiveCidsAndTripCid(String tripCid, Collection<String> objectiveCids) {
- Collection<String> cids = new HashSet<>();
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- for (String objectiveCid : objectiveCids) {
- try {
- findAllInstructionCidsForObjectiveCidsAndTripCidPreparedStatement1.setString(1, tripCid);
- findAllInstructionCidsForObjectiveCidsAndTripCidPreparedStatement1.setString(2, objectiveCid);
- resultSet = findAllInstructionCidsForObjectiveCidsAndTripCidPreparedStatement1.executeQuery();
- while (resultSet.next()) {
- String waitCid = resultSet.getString(1);
- cids.add(waitCid);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- try {
- findAllInstructionCidsForObjectiveCidsAndTripCidPreparedStatement2.setString(1, tripCid);
- findAllInstructionCidsForObjectiveCidsAndTripCidPreparedStatement2.setString(2, objectiveCid);
- resultSet = findAllInstructionCidsForObjectiveCidsAndTripCidPreparedStatement2.executeQuery();
- while (resultSet.next()) {
- String waitCid = resultSet.getString(1);
- cids.add(waitCid);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- return cids;
- }
- @Override
- public Collection<String> findAllWaitCidsForObjectiveCidsAndTripCid(String tripCid, Collection<String> objectiveCids) {
- Collection<String> cids = new HashSet<>();
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- for (String objectiveCid : objectiveCids) {
- try {
- findAllWaitCidsForObjectiveCidsAndTripCidPreparedStatement.setString(1, tripCid);
- findAllWaitCidsForObjectiveCidsAndTripCidPreparedStatement.setString(2, objectiveCid);
- resultSet = findAllWaitCidsForObjectiveCidsAndTripCidPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String waitCid = resultSet.getString(1);
- cids.add(waitCid);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- return cids;
- }
- @Override
- public void findFormationCidAndDayUtcSecondsForWaitCid(String waitCid, FormationCidAndDayUtcSeconds result) {
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- findFormationCidAndDayUtcSecondsForWaitCidPreparedStatement.setString(1, waitCid);
- resultSet = findFormationCidAndDayUtcSecondsForWaitCidPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String formationCid = resultSet.getString(1);
- int toUtcSeconds = resultSet.getInt(2);
- result.formationCid = formationCid;
- result.dayUtcSeconds = toUtcSeconds;
- result.platformCid = this.findPlatformCidForObjectiveCid(resultSet.getString(3));
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- @Override
- public String findFormationCidForInstructionCid(String instructionCid) {
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- findFormationCidForInstructionCidPreparedStatement.setString(1, instructionCid);
- resultSet = findFormationCidForInstructionCidPreparedStatement.executeQuery();
- while (resultSet.next()) {
- return resultSet.getString(1);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return null;
- }
- @Override
- public List<String> findCarCidsForFormationCid(String formationCid) {
- List<String> carCids = new ArrayList<>();
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- findCarCidsForFormationCidPreparedStatement.setString(1, formationCid);
- resultSet = findCarCidsForFormationCidPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String carCid = resultSet.getString(1);
- carCids.add(carCid);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return carCids;
- }
- @Override
- public String findEdgeCidForBezierCid(String bezierCid) {
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- findEdgeCidForBezierCidPreparedStatement.setString(1, bezierCid);
- resultSet = findEdgeCidForBezierCidPreparedStatement.executeQuery();
- while (resultSet.next()) {
- return resultSet.getString(1);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return null;
- }
- @Override
- public Collection<String> findAllBezierCidsForEdgeCid(String edgeCid) {
- Collection<String> bezierCids = new HashSet<>();
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- findAllBezierCidsForEdgeCidPreparedStatement.setString(1, edgeCid);
- resultSet = findAllBezierCidsForEdgeCidPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String bezierCid = resultSet.getString(1);
- bezierCids.add(bezierCid);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return bezierCids;
- }
- @Override
- public Collection<String> findAllInstructionCidsForEdgeCid(String edgeCid) {
- Collection<String> instructionCids = new HashSet<>();
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- findAllInstructionCidsForEdgeCidPreparedStatement.setString(1, edgeCid);
- resultSet = findAllInstructionCidsForEdgeCidPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String instructionCid = resultSet.getString(1);
- instructionCids.add(instructionCid);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return instructionCids;
- }
- private String findPlatformCidForObjectiveCid(String objectiveCid) {
- ResultSet resultSet = null;
- try {
- findPlatformCidForObjectiveCidPreparedStatement.setString(1, objectiveCid);
- resultSet = findPlatformCidForObjectiveCidPreparedStatement.executeQuery();
- while (resultSet.next()) {
- return resultSet.getString(1);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- return null;
- }
- @Override
- public Collection<String> findAllWaitCidsForEdgeCid(String edgeCid) {
- Collection<String> waitCids = new HashSet<>();
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- findAllWaitCidsForEdgeCidPreparedStatement.setString(1, edgeCid);
- resultSet = findAllWaitCidsForEdgeCidPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String waitCid = resultSet.getString(1);
- waitCids.add(waitCid);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return waitCids;
- }
- @Override
- public Collection<String> findAllInstructionCidsForTripCid(String tripCid) {
- Collection<String> instructionCids = new HashSet<>();
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- findAllInstructionCidsForTripCidPreparedStatement.setString(1, tripCid);
- resultSet = findAllInstructionCidsForTripCidPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String instructionCid = resultSet.getString(1);
- instructionCids.add(instructionCid);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return instructionCids;
- }
- @Override
- public Collection<String> findAllWaitCidsForTripCid(String tripCid) {
- Collection<String> waitCids = new HashSet<>();
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- findAllWaitCidsForTripCidPreparedStatement.setString(1, tripCid);
- resultSet = findAllWaitCidsForTripCidPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String waitCid = resultSet.getString(1);
- waitCids.add(waitCid);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return waitCids;
- }
- @Override
- public Collection<String> findAllEdgeCidsForInstructionCid(String instructionCid) {
- Collection<String> edgeCids = new HashSet<>();
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- findAllEdgeCidsForInstructionCidPreparedStatement.setString(1, instructionCid);
- resultSet = findAllEdgeCidsForInstructionCidPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String edgeCid = resultSet.getString(1);
- edgeCids.add(edgeCid);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return edgeCids;
- }
- @Override
- public Collection<String> findAllEdgeCidsForWaitCid(String waitCid) {
- Collection<String> edgeCids = new HashSet<>();
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- findAllEdgeCidsForWaitCidPreparedStatement.setString(1, waitCid);
- resultSet = findAllEdgeCidsForWaitCidPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String edgeCid = resultSet.getString(1);
- edgeCids.add(edgeCid);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return edgeCids;
- }
- @Override
- public Map<Integer, Collection<Tile>> findTimechunk2tilesForInstructionCid(String instructionCid) {
- Map<Integer, Collection<Tile>> result = new HashMap<>();
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- findTimechunk2tilesForInstructionCidPreparedStatement.setString(1, instructionCid);
- resultSet = findTimechunk2tilesForInstructionCidPreparedStatement.executeQuery();
- while (resultSet.next()) {
- int x = resultSet.getInt(1);
- int y = resultSet.getInt(2);
- int tc = resultSet.getInt(3);
- if (!result.containsKey(tc)) {
- Collection<Tile> tiles = new HashSet<>();
- result.put(tc, tiles);
- }
- Tile tile = new Tile(x, y, 16);
- result.get(tc).add(tile);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return result;
- }
- @Override
- public Map<Integer, Collection<Tile>> findTimechunk2tilesForWaitCid(String waitCid) {
- Map<Integer, Collection<Tile>> result = new HashMap<>();
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- findTimechunk2tilesForWaitCidPreparedStatement.setString(1, waitCid);
- resultSet = findTimechunk2tilesForWaitCidPreparedStatement.executeQuery();
- while (resultSet.next()) {
- int x = resultSet.getInt(1);
- int y = resultSet.getInt(2);
- int tc = resultSet.getInt(3);
- if (!result.containsKey(tc)) {
- Collection<Tile> tiles = new HashSet<>();
- result.put(tc, tiles);
- }
- Tile tile = new Tile(x, y, 16);
- result.get(tc).add(tile);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return result;
- }
- @Override
- public Collection<Tile> findTilesForInstructionCidAndTimechunk(String instructionCid, int timechunk) {
- Collection<Tile> result = new HashSet<>();
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- findTilesForInstructionCidAndTimechunkPreparedStatement.setString(1, instructionCid);
- findTilesForInstructionCidAndTimechunkPreparedStatement.setInt(2, timechunk);
- resultSet = findTilesForInstructionCidAndTimechunkPreparedStatement.executeQuery();
- while (resultSet.next()) {
- int x = resultSet.getInt(1);
- int y = resultSet.getInt(2);
- Tile tile = new Tile(x, y, 16);
- result.add(tile);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return result;
- }
- @Override
- public Collection<Tile> findTilesForWaitCidAndTimechunk(String waitCid, int timechunk) {
- Collection<Tile> result = new HashSet<>();
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- findTilesForWaitCidAndTimechunkPreparedStatement.setString(1, waitCid);
- findTilesForWaitCidAndTimechunkPreparedStatement.setInt(2, timechunk);
- resultSet = findTilesForWaitCidAndTimechunkPreparedStatement.executeQuery();
- while (resultSet.next()) {
- int x = resultSet.getInt(1);
- int y = resultSet.getInt(2);
- Tile tile = new Tile(x, y, 16);
- result.add(tile);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- return result;
- }
- @Override
- public void findDayUtcSecondsForInstructionCidAndObjectiveCids(String instructionCid, Set<String> objectiveCids, FormationCidAndDayUtcSeconds result) {
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- findDayUtcSecondsForInstructionCidAndObjectiveCidsPreparedStatement.setString(1, instructionCid);
- resultSet = findTilesForWaitCidAndTimechunkPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String flatCoeffsStr = resultSet.getString(1);
- String firstObjectiveCid = resultSet.getString(2);
- String lastObjectiveCid = resultSet.getString(3);
- if (!objectiveCids.contains(firstObjectiveCid) && !objectiveCids.contains(lastObjectiveCid)) {
- continue;
- }
- String[] flatCoeffs = flatCoeffsStr.split(",");
- if (objectiveCids.contains(firstObjectiveCid)) {
- result.dayUtcSeconds = Double.parseDouble(flatCoeffs[0]);
- result.platformCid = this.findPlatformCidForObjectiveCid(firstObjectiveCid);
- } else {
- result.dayUtcSeconds = Double.parseDouble(flatCoeffs[flatCoeffs.length - 2]);
- result.platformCid = this.findPlatformCidForObjectiveCid(lastObjectiveCid);
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- @Override
- public void addAgencies(Collection<String> cids, Map<String, Agency> results) {
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- for (String cid : cids) {
- if (results.containsKey(cid)) {
- continue;
- }
- addAgenciesPreparedStatement.setString(1, cid);
- resultSet = addAgenciesPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String agencyCid = resultSet.getString(1);
- String agencyName = resultSet.getString(2);
- String agencyUrl = resultSet.getString(3);
- String agencyTimezone = resultSet.getString(4);
- String agencyLang = resultSet.getString(5);
- String agencyPhone = resultSet.getString(6);
- TimeZone tz = TimeZone.getTimeZone(agencyTimezone);
- Agency a = new Agency(agencyCid, agencyName, agencyUrl, tz, agencyLang, agencyPhone);
- results.put(cid, a);
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- @Override
- public void addBeziers(Collection<String> cids, Map<String, StringRefBezier> results) {
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- for (String cid : cids) {
- if (results.containsKey(cid)) {
- continue;
- }
- addBeziersPreparedStatement.setString(1, cid);
- resultSet = addBeziersPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String bezierCid = resultSet.getString(1);
- String gradient0id = resultSet.getString(2);
- double distance0 = resultSet.getDouble(3);
- String gradient3id = resultSet.getString(4);
- double distance3 = resultSet.getDouble(5);
- String edgeId = resultSet.getString(6);
- double fromDistance = resultSet.getDouble(7);
- double toDistance = resultSet.getDouble(8);
- int sgn = resultSet.getInt(9);
- StringRefBezier br = new StringRefBezier(bezierCid, gradient0id, distance0, gradient3id, distance3, edgeId, fromDistance, toDistance, sgn > 0);
- results.put(cid, br);
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- @Override
- public void addCalendars(Collection<String> cids, Map<String, Calendar> results) {
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- for (String cid : cids) {
- if (results.containsKey(cid)) {
- continue;
- }
- addCalendarsPreparedStatement1.setString(1, cid);
- resultSet = addCalendarsPreparedStatement1.executeQuery();
- while (resultSet.next()) {
- String serviceCid = resultSet.getString(1);
- boolean monday = resultSet.getInt(2) == 1;
- boolean tuesday = resultSet.getInt(3) == 1;
- boolean wednesday = resultSet.getInt(4) == 1;
- boolean thursday = resultSet.getInt(5) == 1;
- boolean friday = resultSet.getInt(6) == 1;
- boolean saturday = resultSet.getInt(7) == 1;
- boolean sunday = resultSet.getInt(8) == 1;
- int startDate = resultSet.getInt(9);
- int endDate = resultSet.getInt(10);
- String name = resultSet.getString(11);
- boolean[] weeklyCalendarRules = new boolean[]{sunday, monday, tuesday, wednesday, thursday, friday, saturday};
- Map<Integer, Boolean> ex = new HashMap<>();
- ResultSet resultSet2 = null;
- addCalendarsPreparedStatement2.setString(1, cid);
- resultSet2 = addCalendarsPreparedStatement2.executeQuery();
- while (resultSet2.next()) {
- int day1970 = resultSet2.getInt(2);
- int etype = resultSet2.getInt(3);
- ex.put(day1970, etype == 1);
- }
- resultSet2.close();
- Calendar cr = new Calendar(serviceCid, weeklyCalendarRules, ex, startDate, endDate);
- results.put(cid, cr);
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- @Override
- public void addCars(Collection<String> cids, Map<String, StringRefCar> results) {
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- for (String cid : cids) {
- if (results.containsKey(cid)) {
- continue;
- }
- addCarsPreparedStatement.setString(1, cid);
- resultSet = addCarsPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String carCid = resultSet.getString(1);
- String carName = resultSet.getString(2);
- String carmodelId = resultSet.getString(3);
- StringRefCar cr = new StringRefCar(carCid, carmodelId, carName);
- results.put(cid, cr);
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- @Override
- public void addCarmodels(Collection<String> cids, Map<String, Carmodel> results) {
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- for (String cid : cids) {
- if (results.containsKey(cid)) {
- continue;
- }
- addCarmodelsPreparedStatement.setString(1, cid);
- resultSet = addCarmodelsPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String carmodelCid = resultSet.getString(1);
- String carmodelName = resultSet.getString(2);
- double carmodelLength = resultSet.getDouble(3);
- double carmodelWidth = resultSet.getDouble(4);
- double carmodelHeight = resultSet.getDouble(5);
- double carmodelWheelHeight = resultSet.getDouble(6);
- double carmodelBogieLengthDelta = resultSet.getDouble(7);
- double carmodelCouplingLengthDelta = resultSet.getDouble(8);
- byte[] carmodel3dModel = resultSet.getBytes(9);
- String carmodel3dModelMime = resultSet.getString(10);
- Carmodel cm = new Carmodel(carmodelCid, carmodelName, carmodelLength, carmodelWidth, carmodelHeight, carmodelWheelHeight, carmodelBogieLengthDelta, carmodelCouplingLengthDelta, carmodel3dModel, carmodel3dModelMime);
- results.put(cid, cm);
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- @Override
- public void addFormations(Collection<String> cids, Map<String, StringRefFormation> results) {
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- for (String cid : cids) {
- if (results.containsKey(cid)) {
- continue;
- }
- String formationCid = null;
- String explicitName = null;
- addFormations1PreparedStatement.setString(1, cid);
- resultSet = addFormations1PreparedStatement.executeQuery();
- while (resultSet.next()) {
- formationCid = resultSet.getString(1);
- explicitName = resultSet.getString(2);
- break;
- }
- List<String> carIds = new ArrayList<>();
- List<Boolean> direction1s = new ArrayList<>();
- List<String> labels = new ArrayList<>();
- addFormations2PreparedStatement.setString(1, cid);
- resultSet = addFormations2PreparedStatement.executeQuery();
- while (resultSet.next()) {
- String carId = resultSet.getString(3);
- boolean directionIs1 = resultSet.getInt(4) == 1;
- String label = resultSet.getString(5);
- carIds.add(carId);
- direction1s.add(directionIs1);
- labels.add(label);
- }
- StringRefFormation fr = new StringRefFormation(formationCid, carIds, direction1s, labels, explicitName);
- results.put(cid, fr);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- @Override
- public void addGradients(Collection<String> cids, Map<String, Gradient> results) {
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- for (String cid : cids) {
- if (results.containsKey(cid)) {
- continue;
- }
- addGradientsPreparedStatement.setString(1, cid);
- resultSet = addGradientsPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String gradientCid = resultSet.getString(1);
- double gradientLat = resultSet.getDouble(2);
- double gradientLon = resultSet.getDouble(3);
- double gradientAlt = resultSet.getDouble(4);
- double gradientBearing = resultSet.getDouble(5);
- double gradientSlope = resultSet.getDouble(6);
- double gradientCant = resultSet.getDouble(7);
- Lnglat ll = new Lnglat(gradientLon, gradientLat);
- Gradient g = new Gradient(gradientCid, ll, gradientBearing, gradientAlt, gradientSlope, gradientCant);
- results.put(cid, g);
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- @Override
- public void addInstructions(Collection<String> cids, Map<String, StringRefInstruction> results) {
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- for (String cid : cids) {
- if (results.containsKey(cid)) {
- continue;
- }
- String instructionCid = null;
- String tripCid = null;
- String formationCid = null;
- double firstCarDistance = 0;
- double lastCarDistance = 0;
- String flatCoeffs = null;
- List<Double> flatCoeffsBoxed = null;
- addInstructions1PreparedStatement.setString(1, cid);
- resultSet = addInstructions1PreparedStatement.executeQuery();
- while (resultSet.next()) {
- instructionCid = resultSet.getString(1);
- tripCid = resultSet.getString(2);
- formationCid = resultSet.getString(3);
- firstCarDistance = resultSet.getDouble(4);
- lastCarDistance = resultSet.getDouble(5);
- flatCoeffs = resultSet.getString(6);
- String[] flatCoeffsSplitted = flatCoeffs.split(",");
- flatCoeffsBoxed = new ArrayList<>(flatCoeffsSplitted.length);
- for (int i = 0; i < flatCoeffsSplitted.length; i++) {
- flatCoeffsBoxed.add(Double.parseDouble(flatCoeffsSplitted[i]));
- }
- break;
- }
- List<StringRefEdgeInEdgeSet> eies = new ArrayList<>();
- addInstructions2PreparedStatement.setString(1, cid);
- resultSet = addInstructions2PreparedStatement.executeQuery();
- while (resultSet.next()) {
- String edgeCid = resultSet.getString(1);
- double fromDistance = resultSet.getDouble(2);
- double toDistance = resultSet.getDouble(3);
- int sgn = resultSet.getInt(4);
- StringRefEdgeInEdgeSet eie = new StringRefEdgeInEdgeSet();
- eie.edgeCid = edgeCid;
- eie.fromDistance = fromDistance;
- eie.toDistance = toDistance;
- eie.sgn = sgn;
- eies.add(eie);
- }
- StringRefInstruction ir = new StringRefInstruction(instructionCid, formationCid, tripCid, firstCarDistance, lastCarDistance, eies, flatCoeffsBoxed,null,null);
- results.put(cid, ir);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- @Override
- public void addPlatforms(Collection<String> cids, Map<String, StringRefPlatform> results) {
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- for (String cid : cids) {
- if (results.containsKey(cid)) {
- continue;
- }
- addPlatformsPreparedStatement.setString(1, cid);
- resultSet = addPlatformsPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String platformCid = resultSet.getString(1);
- String platformName = resultSet.getString(2);
- String stationCid = resultSet.getString(3);
- StringRefPlatform pr = new StringRefPlatform(platformCid, stationCid, platformName, null);
- results.put(cid, pr);
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- @Override
- public void addRoutes(Collection<String> cids, Map<String, StringRefRoute> results) {
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- for (String cid : cids) {
- if (results.containsKey(cid)) {
- continue;
- }
- addRoutesPreparedStatement.setString(1, cid);
- resultSet = addRoutesPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String routeCid = resultSet.getString(1);
- String agencyCid = resultSet.getString(2);
- String routeShortName = resultSet.getString(3);
- String routeLongName = resultSet.getString(4);
- String routeDesc = resultSet.getString(5);
- int routeType = resultSet.getInt(6);
- String routeUrl = resultSet.getString(7);
- String routeColor = resultSet.getString(8);
- String routeTextColor = resultSet.getString(9);
- if (routeColor != null && routeColor.equals("")) {
- routeColor = null;
- }
- if (routeTextColor != null && routeTextColor.equals("")) {
- routeTextColor = null;
- }
- StringRefRoute rr = new StringRefRoute(routeCid, agencyCid, routeShortName, routeLongName, routeDesc, routeUrl, routeColor, routeTextColor);
- results.put(cid, rr);
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- @Override
- public void addStations(Collection<String> cids, Map<String, StringRefStation> results) {
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- for (String cid : cids) {
- if (results.containsKey(cid)) {
- continue;
- }
- addStationsPreparedStatement.setString(1, cid);
- resultSet = addStationsPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String stationCid = resultSet.getString(1);
- String stationCode = resultSet.getString(2);
- String stationName = resultSet.getString(3);
- String stationDesc = resultSet.getString(4);
- double stationLat = resultSet.getDouble(5);
- double stationLon = resultSet.getDouble(6);
- String stationUrl = resultSet.getString(7);
- String stationTimezone = resultSet.getString(8);
- TimeZone tz = TimeZone.getTimeZone(stationTimezone);
- StringRefStation sr = new StringRefStation(stationCid, stationCode, stationName, stationDesc, stationLat, stationLon, tz, stationUrl);
- results.put(cid, sr);
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- @Override
- public void addTrips(Collection<String> cids, Map<String, StringRefTrip> results) {
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- for (String cid : cids) {
- if (results.containsKey(cid)) {
- continue;
- }
- addTripsPreparedStatement.setString(1, cid);
- resultSet = addTripsPreparedStatement.executeQuery();
- while (resultSet.next()) {
- String tripCid = resultSet.getString(1);
- String explicitName = resultSet.getString(2);
- String routeCid = resultSet.getString(3);
- String serviceCid = resultSet.getString(4);
- String tripHeadsign = resultSet.getString(5);
- String tripShortName = resultSet.getString(6);
- boolean directionIs1 = resultSet.getInt(7) == 1;
- String rankName = resultSet.getString(8);
- String rankColor = resultSet.getString(9);
- String rankTextColor = resultSet.getString(10);
- if (rankColor != null && rankColor.equals("")) {
- rankColor = null;
- }
- if (rankTextColor != null && rankTextColor.equals("")) {
- rankTextColor = null;
- }
- StringRefTrip tr = new StringRefTrip(tripCid, explicitName, routeCid, serviceCid, tripHeadsign, tripShortName, directionIs1, rankName, rankColor, rankTextColor);
- results.put(cid, tr);
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- @Override
- public void addWaits(Collection<String> cids, Map<String, StringRefWait> results) {
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- ResultSet resultSet = null;
- try {
- for (String cid : cids) {
- if (results.containsKey(cid)) {
- continue;
- }
- String waitCid = null;
- String tripCid = null;
- String formationCid = null;
- String platformCid = null;
- double firstBogieDistance = 0;
- double firstCarDistance = 0;
- double lastCarDistance = 0;
- double fromUtcSeconds = 0;
- double toUtcSeconds = 0;
- boolean isServing = false;
- addWaits1PreparedStatement.setString(1, cid);
- resultSet = addWaits1PreparedStatement.executeQuery();
- while (resultSet.next()) {
- waitCid = resultSet.getString(1);
- tripCid = resultSet.getString(2);
- formationCid = resultSet.getString(3);
- platformCid = resultSet.getString(4);
- firstBogieDistance = resultSet.getDouble(5);
- firstCarDistance = resultSet.getDouble(6);
- lastCarDistance = resultSet.getDouble(7);
- fromUtcSeconds = resultSet.getDouble(8);
- toUtcSeconds = resultSet.getDouble(9);
- isServing = resultSet.getInt(10) == 1;
- break;
- }
- List<StringRefEdgeInEdgeSet> eies = new ArrayList<>();
- addWaits2PreparedStatement.setString(1, cid);
- resultSet = addWaits2PreparedStatement.executeQuery();
- while (resultSet.next()) {
- String edgeCid = resultSet.getString(1);
- double fromDistance = resultSet.getDouble(2);
- double toDistance = resultSet.getDouble(3);
- int sgn = resultSet.getInt(4);
- StringRefEdgeInEdgeSet eie = new StringRefEdgeInEdgeSet();
- eie.edgeCid = edgeCid;
- eie.fromDistance = fromDistance;
- eie.toDistance = toDistance;
- eie.sgn = sgn;
- eies.add(eie);
- }
- StringRefWait ir = new StringRefWait(waitCid, formationCid, tripCid, platformCid, fromUtcSeconds, toUtcSeconds, firstCarDistance, lastCarDistance, firstBogieDistance, isServing, eies);
- results.put(cid, ir);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement