Search in sources :

Example 31 with GtfsMutableRelationalDao

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

the class TripMergeStrategy method save.

@Override
protected void save(GtfsMergeContext context, IdentityBean<?> entity) {
    GtfsRelationalDao source = context.getSource();
    GtfsMutableRelationalDao target = context.getTarget();
    Trip trip = (Trip) entity;
    // save them out; when the trip is renamed stop time refs will be lost
    List<StopTime> stopTimes = source.getStopTimesForTrip(trip);
    super.save(context, entity);
    for (StopTime stopTime : stopTimes) {
        stopTime.setId(0);
        stopTime.setTrip(trip);
        target.saveEntity(stopTime);
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 32 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.internal.NoCachingRegionFactory");
    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 33 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 34 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 35 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)57 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)25 Test (org.junit.Test)24 Trip (org.onebusaway.gtfs.model.Trip)22 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)14 Stop (org.onebusaway.gtfs.model.Stop)11 StopTime (org.onebusaway.gtfs.model.StopTime)11 TransformContext (org.onebusaway.gtfs_transformer.services.TransformContext)11 HashMap (java.util.HashMap)10 ArrayList (java.util.ArrayList)9 CalendarService (org.onebusaway.gtfs.services.calendar.CalendarService)9 ExternalServices (org.onebusaway.cloud.api.ExternalServices)8 ExternalServicesBridgeFactory (org.onebusaway.cloud.api.ExternalServicesBridgeFactory)8 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)7 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)7 GtfsTransformStrategy (org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy)7 Route (org.onebusaway.gtfs.model.Route)6 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)6 GtfsReader (org.onebusaway.gtfs.serialization.GtfsReader)5 HashSet (java.util.HashSet)4