use of org.onebusaway.gtfs.services.HibernateGtfsFactory in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsHibernateReaderExampleMain method main.
public static void main(String[] args) throws IOException {
if (!(args.length == 1 || args.length == 2)) {
System.err.println("usage: gtfsPath [hibernate-config.xml]");
System.exit(-1);
}
String resource = "classpath:org/onebusaway/gtfs/examples/hibernate-configuration-examples.xml";
if (args.length == 2)
resource = args[1];
HibernateGtfsFactory factory = createHibernateGtfsFactory(resource);
GtfsReader reader = new GtfsReader();
reader.setInputLocation(new File(args[0]));
GtfsMutableRelationalDao dao = factory.getDao();
reader.setEntityStore(dao);
reader.run();
Collection<Stop> stops = dao.getAllStops();
for (Stop stop : stops) System.out.println(stop.getName());
CalendarService calendarService = factory.getCalendarService();
Set<AgencyAndId> serviceIds = calendarService.getServiceIds();
for (AgencyAndId serviceId : serviceIds) {
Set<ServiceDate> dates = calendarService.getServiceDatesForServiceId(serviceId);
ServiceDate from = null;
ServiceDate to = null;
for (ServiceDate date : dates) {
from = min(from, date);
to = max(to, date);
}
System.out.println("serviceId=" + serviceId + " from=" + from + " to=" + to);
}
}
use of org.onebusaway.gtfs.services.HibernateGtfsFactory 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.HibernateGtfsFactory in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsHibernateReaderExampleMain method createHibernateGtfsFactory.
private static HibernateGtfsFactory createHibernateGtfsFactory(String resource) {
Configuration config = new Configuration();
if (resource.startsWith(KEY_CLASSPATH)) {
resource = resource.substring(KEY_CLASSPATH.length());
config = config.configure(resource);
} else if (resource.startsWith(KEY_FILE)) {
resource = resource.substring(KEY_FILE.length());
config = config.configure(new File(resource));
} else {
config = config.configure(new File(resource));
}
SessionFactory sessionFactory = config.buildSessionFactory();
return new HibernateGtfsFactory(sessionFactory);
}
Aggregations