src/main/java/com/conveyal/gtfs/loader/JdbcTableWriter.java
private int updateStopTimesForPatternStops(List<PatternStop> patternStops) throws SQLException {
        PatternStop firstPatternStop = patternStops.iterator().next();
        int firstStopSequence = firstPatternStop.stop_sequence;
        // Prepare SQL query to determine the time that should form the basis for adding the travel time values.
        int previousStopSequence = firstStopSequence > 0 ? firstStopSequence - 1 : 0;
        String timeField = firstStopSequence > 0 ? "departure_time" : "arrival_time";
        String getFirstTravelTimeSql = String.format(
            "select t.trip_id, %s from %s.stop_times st, %s.trips t where stop_sequence = ? " +
                "and t.pattern_id = ? " +
                "and t.trip_id = st.trip_id",
            timeField,
            tablePrefix,
            tablePrefix
        );
        PreparedStatement statement = connection.prepareStatement(getFirstTravelTimeSql);
        statement.setInt(1, previousStopSequence);
        statement.setString(2, firstPatternStop.pattern_id);
        LOG.info(statement.toString());
        ResultSet resultSet = statement.executeQuery();
        Map<String, Integer> timesForTripIds = new HashMap<>();
        while (resultSet.next()) {
            timesForTripIds.put(resultSet.getString(1), resultSet.getInt(2));
        }
        // Update stop times for individual trips with normalized travel times.
        String updateTravelTimeSql = String.format(
            "update %s.stop_times set arrival_time = ?, departure_time = ? where trip_id = ? and stop_sequence = ?",
            tablePrefix
        );
        PreparedStatement updateStopTimeStatement = connection.prepareStatement(updateTravelTimeSql);
        LOG.info(updateStopTimeStatement.toString());
        final BatchTracker stopTimesTracker = new BatchTracker("stop_times", updateStopTimeStatement);
        for (String tripId : timesForTripIds.keySet()) {
            // Initialize travel time with previous stop time value.
            int cumulativeTravelTime = timesForTripIds.get(tripId);
            for (PatternStop patternStop : patternStops) {
                // Gather travel/dwell time for pattern stop (being sure to check for missing values).
                int travelTime = patternStop.default_travel_time == Entity.INT_MISSING ? 0 : patternStop.default_travel_time;
                int dwellTime = patternStop.default_dwell_time == Entity.INT_MISSING ? 0 : patternStop.default_dwell_time;
                int oneBasedIndex = 1;
                // Increase travel time by current pattern stop's travel and dwell times (and set values for update).
                cumulativeTravelTime += travelTime;
                updateStopTimeStatement.setInt(oneBasedIndex++, cumulativeTravelTime);
                cumulativeTravelTime += dwellTime;
                updateStopTimeStatement.setInt(oneBasedIndex++, cumulativeTravelTime);
                updateStopTimeStatement.setString(oneBasedIndex++, tripId);
                updateStopTimeStatement.setInt(oneBasedIndex++, patternStop.stop_sequence);
                stopTimesTracker.addBatch();
            }
        }
        return stopTimesTracker.executeRemaining();
    }
private int updateStopTimesForPatternStops(List<PatternStop> patternStops) throws SQLException {
        PatternStop firstPatternStop = patternStops.iterator().next();
        int firstStopSequence = firstPatternStop.stop_sequence;
        // Prepare SQL query to determine the time that should form the basis for adding the travel time values.
        int previousStopSequence = firstStopSequence > 0 ? firstStopSequence - 1 : 0;
        String timeField = firstStopSequence > 0 ? "departure_time" : "arrival_time";
        String getFirstTravelTimeSql = String.format(
            "select t.trip_id, %s from %s.stop_times st, %s.trips t where stop_sequence = ? " +
                "and t.pattern_id = ? " +
                "and t.trip_id = st.trip_id",
            timeField,
            tablePrefix,
            tablePrefix
        );
        PreparedStatement statement = connection.prepareStatement(getFirstTravelTimeSql);
        statement.setInt(1, previousStopSequence);
        statement.setString(2, firstPatternStop.pattern_id);
        LOG.info(statement.toString());
        ResultSet resultSet = statement.executeQuery();
        Map<String, Integer> timesForTripIds = new HashMap<>();
        while (resultSet.next()) {
            timesForTripIds.put(resultSet.getString(1), resultSet.getInt(2));
        }
        // Update stop times for individual trips with normalized travel times.
        String updateTravelTimeSql = String.format(
            "update %s.stop_times set arrival_time = ?, departure_time = ? where trip_id = ? and stop_sequence = ?",
            tablePrefix
        );
        PreparedStatement updateStopTimeStatement = connection.prepareStatement(updateTravelTimeSql);
        LOG.info(updateStopTimeStatement.toString());
        final BatchTracker stopTimesTracker = new BatchTracker("stop_times", updateStopTimeStatement);
        for (String tripId : timesForTripIds.keySet()) {
            // Initialize travel time with previous stop time value.
            int cumulativeTravelTime = timesForTripIds.get(tripId);
            for (PatternStop patternStop : patternStops) {
                // Gather travel/dwell time for pattern stop (being sure to check for missing values).
                int travelTime = patternStop.default_travel_time == Entity.INT_MISSING ? 0 : patternStop.default_travel_time;
                int dwellTime = patternStop.default_dwell_time == Entity.INT_MISSING ? 0 : patternStop.default_dwell_time;
                int oneBasedIndex = 1;
                // Increase travel time by current pattern stop's travel and dwell times (and set values for update).
                cumulativeTravelTime += travelTime;
                updateStopTimeStatement.setInt(oneBasedIndex++, cumulativeTravelTime);
                cumulativeTravelTime += dwellTime;
                updateStopTimeStatement.setInt(oneBasedIndex++, cumulativeTravelTime);
                updateStopTimeStatement.setString(oneBasedIndex++, tripId);
                updateStopTimeStatement.setInt(oneBasedIndex++, patternStop.stop_sequence);
                stopTimesTracker.addBatch();
            }
        }
        return stopTimesTracker.executeRemaining();
    }
Normalizes all stop times' arrivals and departures for an ordered set of pattern stops. This set can be the full
set of stops for a pattern or just a subset. Typical usage for this method would be to overwrite the arrival and
departure times for existing trips after a pattern stop has been added or inserted into a pattern or if a
pattern stop's default travel or dwell time were updated and the stop times need to reflect this update.
@param patternStops list of pattern stops for which to update stop times (ordered by increasing stop_sequence)
@throws SQLException

TODO? add param Set<String> serviceIdFilters service_id values to filter trips on