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();
}
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;
}
}
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();
}
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);
}
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);
}
}
Aggregations