Package com.eugeneborshch.routecalculator.load

Source Code of com.eugeneborshch.routecalculator.load.OsmImporter

package com.eugeneborshch.routecalculator.load;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Transaction;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;

import java.io.IOException;

/**
* Imports OSM data in Neo4j database.
* <p/>
* It only process information required for routing calculation(i.e. without user, timestamp, changelist,area... information.)
* User: Eugene Borshch
*/
public class OsmImporter {

    private GraphDatabaseService graphDb;

    public OsmImporter(GraphDatabaseService graphDb) {
        this.graphDb = graphDb;
    }


    public void importXML(String xml) {

        Transaction tx = graphDb.beginTx();

        try {

            XMLReader xmlReader = XMLReaderFactory.createXMLReader();
            xmlReader.setContentHandler(new MainOSMHandler(xmlReader, graphDb));
            xmlReader.parse(xml);

            // Hallelujah
            tx.success();

        } catch (SAXException e) {
            System.err.println(e);
            tx.failure();
        } catch (IOException e) {
            System.err.println(e);
            tx.failure();
        } finally {
            tx.finish();
        }
    }


}
TOP

Related Classes of com.eugeneborshch.routecalculator.load.OsmImporter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.