Search in sources :

Example 16 with GtfsMutableRelationalDao

use of org.onebusaway.gtfs.services.GtfsMutableRelationalDao in project OpenTripPlanner by opentripplanner.

the class GtfsModule method buildGraph.

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
    // we're about to add another agency to the graph, so clear the cached timezone
    // in case it should change
    // OTP doesn't currently support multiple time zones in a single graph;
    // at least this way we catch the error and log it instead of silently ignoring
    // because the time zone from the first agency is cached
    graph.clearTimeZone();
    MultiCalendarServiceImpl service = new MultiCalendarServiceImpl();
    GtfsStopContext stopContext = new GtfsStopContext();
    try {
        for (GtfsBundle gtfsBundle : gtfsBundles) {
            // apply global defaults to individual GTFSBundles (if globals have been set)
            if (cacheDirectory != null && gtfsBundle.cacheDirectory == null)
                gtfsBundle.cacheDirectory = cacheDirectory;
            if (useCached != null && gtfsBundle.useCached == null)
                gtfsBundle.useCached = useCached;
            GtfsMutableRelationalDao dao = new GtfsRelationalDaoImpl();
            GtfsContext context = GtfsLibrary.createContext(gtfsBundle.getFeedId(), dao, service);
            GTFSPatternHopFactory hf = new GTFSPatternHopFactory(context);
            hf.setStopContext(stopContext);
            hf.setFareServiceFactory(_fareServiceFactory);
            hf.setMaxStopToShapeSnapDistance(gtfsBundle.getMaxStopToShapeSnapDistance());
            loadBundle(gtfsBundle, graph, dao);
            CalendarServiceDataFactoryImpl csfactory = new CalendarServiceDataFactoryImpl();
            csfactory.setGtfsDao(dao);
            CalendarServiceData data = csfactory.createData();
            service.addData(data, dao);
            hf.subwayAccessTime = gtfsBundle.subwayAccessTime;
            hf.maxInterlineDistance = gtfsBundle.maxInterlineDistance;
            hf.run(graph);
            if (gtfsBundle.doesTransfersTxtDefineStationPaths()) {
                hf.createTransfersTxtTransfers();
            }
            if (gtfsBundle.linkStopsToParentStations) {
                hf.linkStopsToParentStations(graph);
            }
            if (gtfsBundle.parentStationTransfers) {
                hf.createParentStationTransfers();
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    // We need to save the calendar service data so we can use it later
    CalendarServiceData data = service.getData();
    graph.putService(CalendarServiceData.class, data);
    graph.updateTransitFeedValidity(data);
    graph.hasTransit = true;
    graph.calculateTransitCenter();
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) CalendarServiceData(org.onebusaway.gtfs.model.calendar.CalendarServiceData) GtfsBundle(org.opentripplanner.graph_builder.model.GtfsBundle) GtfsContext(org.opentripplanner.gtfs.GtfsContext) GtfsStopContext(org.opentripplanner.routing.edgetype.factory.GtfsStopContext) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) IOException(java.io.IOException) CalendarServiceDataFactoryImpl(org.opentripplanner.calendar.impl.CalendarServiceDataFactoryImpl) MultiCalendarServiceImpl(org.opentripplanner.calendar.impl.MultiCalendarServiceImpl)

Example 17 with GtfsMutableRelationalDao

use of org.onebusaway.gtfs.services.GtfsMutableRelationalDao in project onebusaway-gtfs-modules by OneBusAway.

the class AbstractIdentifiableSingleEntityMergeStrategy method pickBestDuplicateDetectionStrategy.

@Override
protected EDuplicateDetectionStrategy pickBestDuplicateDetectionStrategy(GtfsMergeContext context) {
    /**
     * If there are currently no elements to be duplicated, then return the NONE
     * strategy.
     */
    GtfsRelationalDao source = context.getSource();
    GtfsMutableRelationalDao target = context.getTarget();
    if (target.getAllEntitiesForType(_entityType).isEmpty() || source.getAllEntitiesForType(_entityType).isEmpty()) {
        return EDuplicateDetectionStrategy.NONE;
    }
    if (hasLikelyIdentifierOverlap(context)) {
        return EDuplicateDetectionStrategy.IDENTITY;
    } else if (hasLikelyFuzzyOverlap(context)) {
        return EDuplicateDetectionStrategy.FUZZY;
    } else {
        return EDuplicateDetectionStrategy.NONE;
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao)

Example 18 with GtfsMutableRelationalDao

use of org.onebusaway.gtfs.services.GtfsMutableRelationalDao in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsDatabaseLoaderMain method run.

private void run(String[] args) throws IOException {
    CommandLine cli = parseCommandLineOptions(args);
    args = cli.getArgs();
    if (args.length != 1) {
        printUsage();
        System.exit(-1);
    }
    Configuration config = new Configuration();
    config.setProperty("hibernate.connection.driver_class", cli.getOptionValue(ARG_DRIVER_CLASS));
    config.setProperty("hibernate.connection.url", cli.getOptionValue(ARG_URL));
    if (cli.hasOption(ARG_USERNAME)) {
        config.setProperty("hibernate.connection.username", cli.getOptionValue(ARG_USERNAME));
    }
    if (cli.hasOption(ARG_PASSWORD)) {
        config.setProperty("hibernate.connection.password", cli.getOptionValue(ARG_PASSWORD));
    }
    config.setProperty("hibernate.connection.pool_size", "1");
    config.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.NoCacheProvider");
    config.setProperty("hibernate.hbm2ddl.auto", "update");
    config.addResource("org/onebusaway/gtfs/model/GtfsMapping.hibernate.xml");
    config.addResource("org/onebusaway/gtfs/impl/HibernateGtfsRelationalDaoImpl.hibernate.xml");
    SessionFactory sessionFactory = config.buildSessionFactory();
    HibernateGtfsFactory factory = new HibernateGtfsFactory(sessionFactory);
    GtfsReader reader = new GtfsReader();
    reader.setInputLocation(new File(args[0]));
    GtfsMutableRelationalDao dao = factory.getDao();
    reader.setEntityStore(dao);
    reader.run();
    reader.close();
}
Also used : SessionFactory(org.hibernate.SessionFactory) GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) CommandLine(org.apache.commons.cli.CommandLine) GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader) Configuration(org.hibernate.cfg.Configuration) HibernateGtfsFactory(org.onebusaway.gtfs.services.HibernateGtfsFactory) File(java.io.File)

Example 19 with GtfsMutableRelationalDao

use of org.onebusaway.gtfs.services.GtfsMutableRelationalDao in project onebusaway-gtfs-modules by OneBusAway.

the class AbstractSingleEntityMergeStrategy method save.

/**
   * Saves the specified entity to the merged output feed.
   * 
   * @param context
   * @param entity
   */
protected void save(GtfsMergeContext context, IdentityBean<?> entity) {
    GtfsMutableRelationalDao target = context.getTarget();
    target.saveEntity(entity);
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao)

Example 20 with GtfsMutableRelationalDao

use of org.onebusaway.gtfs.services.GtfsMutableRelationalDao in project onebusaway-gtfs-modules by OneBusAway.

the class ServiceCalendarMergeStrategy method saveElementsForKey.

/**
   * Writes all {@link ServiceCalendar} and {@link ServiceCalendarDate} entities
   * with the specified {@code service_id} to the merged output feed.
   */
@Override
protected void saveElementsForKey(GtfsMergeContext context, AgencyAndId serviceId) {
    GtfsRelationalDao source = context.getSource();
    GtfsMutableRelationalDao target = context.getTarget();
    ServiceCalendar calendar = source.getCalendarForServiceId(serviceId);
    if (calendar != null) {
        calendar.setId(0);
        target.saveEntity(calendar);
    }
    for (ServiceCalendarDate calendarDate : source.getCalendarDatesForServiceId(serviceId)) {
        calendarDate.setId(0);
        target.saveEntity(calendarDate);
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar)

Aggregations

GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)29 Test (org.junit.Test)16 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)15 Trip (org.onebusaway.gtfs.model.Trip)9 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)7 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)7 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)5 GtfsReader (org.onebusaway.gtfs.serialization.GtfsReader)5 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)4 Stop (org.onebusaway.gtfs.model.Stop)4 MockGtfs (org.onebusaway.gtfs.services.MockGtfs)4 CalendarService (org.onebusaway.gtfs.services.calendar.CalendarService)4 TransformContext (org.onebusaway.gtfs_transformer.services.TransformContext)4 Collection (java.util.Collection)3 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)3 StopTime (org.onebusaway.gtfs.model.StopTime)3 HibernateGtfsFactory (org.onebusaway.gtfs.services.HibernateGtfsFactory)3 TypedEntityMatch (org.onebusaway.gtfs_transformer.match.TypedEntityMatch)3 TrimOperation (org.onebusaway.gtfs_transformer.updates.TrimTripTransformStrategy.TrimOperation)3 File (java.io.File)2