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