use of org.onebusaway.gtfs.serialization.GtfsReader 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.serialization.GtfsReader in project onebusaway-gtfs-modules by OneBusAway.
the class HibernateGtfsRelationalDaoImplCaltrainTest method setup.
@BeforeClass
public static void setup() throws IOException {
Configuration config = new Configuration();
config = config.configure("org/onebusaway/gtfs/hibernate-configuration.xml");
_sessionFactory = config.buildSessionFactory();
_dao = new HibernateGtfsRelationalDaoImpl(_sessionFactory);
GtfsReader reader = new GtfsReader();
reader.setInputLocation(new File("src/test/resources/org/onebusaway/gtfs/caltrain.zip"));
reader.setEntityStore(_dao);
reader.setDefaultAgencyId(_agencyId);
reader.run();
}
use of org.onebusaway.gtfs.serialization.GtfsReader in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsMergerTest method merge.
private GtfsRelationalDao merge() throws IOException {
List<File> paths = new ArrayList<File>();
paths.add(_oldGtfs.getPath());
paths.add(_newGtfs.getPath());
if (_pugetGtfs != null) {
paths.add(_pugetGtfs.getPath());
}
_merger.run(paths, _mergedGtfs.getPath());
GtfsReader reader = new GtfsReader();
GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
reader.setEntityStore(dao);
reader.setInputLocation(_mergedGtfs.getPath());
reader.run();
return dao;
}
use of org.onebusaway.gtfs.serialization.GtfsReader in project onebusaway-gtfs-modules by OneBusAway.
the class ExtensionsTest method testExtensionRead.
@Test
public void testExtensionRead() throws IOException {
MockGtfs gtfs = MockGtfs.create();
gtfs.putMinimal();
gtfs.putStops(2, "label=a,b");
DefaultEntitySchemaFactory factory = GtfsEntitySchemaFactory.createEntitySchemaFactory();
factory.addExtension(Stop.class, StopExtension.class);
GtfsReader reader = new GtfsReader();
reader.setEntitySchemaFactory(factory);
GtfsMutableRelationalDao dao = gtfs.read(reader);
Stop stop = dao.getStopForId(new AgencyAndId("a0", "s0"));
StopExtension extension = stop.getExtension(StopExtension.class);
assertEquals("a", extension.getLabel());
}
use of org.onebusaway.gtfs.serialization.GtfsReader in project onebusaway-gtfs-modules by OneBusAway.
the class ExtensionsTest method testExtensionWrite.
@Test
public void testExtensionWrite() throws IOException {
DefaultEntitySchemaFactory factory = GtfsEntitySchemaFactory.createEntitySchemaFactory();
factory.addExtension(Stop.class, StopExtension.class);
{
MockGtfs gtfs = MockGtfs.create();
gtfs.putMinimal();
gtfs.putStops(2, "label=a,b");
GtfsReader reader = new GtfsReader();
reader.setEntitySchemaFactory(factory);
GtfsMutableRelationalDao dao = gtfs.read(reader);
Stop stop = dao.getStopForId(new AgencyAndId("a0", "s0"));
StopExtension extension = stop.getExtension(StopExtension.class);
assertEquals("a", extension.getLabel());
GtfsWriter writer = new GtfsWriter();
writer.setEntitySchemaFactory(factory);
writer.setOutputLocation(_tmpDirectory);
writer.run(dao);
writer.close();
}
{
GtfsReader reader2 = new GtfsReader();
reader2.setEntitySchemaFactory(factory);
reader2.setInputLocation(_tmpDirectory);
GtfsRelationalDaoImpl dao2 = new GtfsRelationalDaoImpl();
reader2.setDefaultAgencyId("a0");
reader2.setEntityStore(dao2);
reader2.readEntities(Stop.class);
Stop stop2 = dao2.getStopForId(new AgencyAndId("a0", "s0"));
StopExtension extension2 = stop2.getExtension(StopExtension.class);
assertEquals("a", extension2.getLabel());
}
}
Aggregations