Package org.neo4j.graphdb

Examples of org.neo4j.graphdb.GraphDatabaseService


      System.out.println("No database["+dbPath+"] or osm["+osmPath+"] - cannot run test");
    }
  }
 
  private void importShapefileDatabase(String shpPath, String dbPath, String layerName) throws ShapefileException, FileNotFoundException, IOException {
    GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(dbPath).setConfig(Neo4jTestCase.LARGE_CONFIG ).newGraphDatabase();
        ShapefileImporter importer = new ShapefileImporter(graphDb, new ConsoleListener(), 10000, true);
        importer.setFilterEnvelope(makeFilterEnvelope());
        importer.importFile(shpPath, layerName, Charset.forName("UTF-8"));
        graphDb.shutdown();
  }
View Full Code Here


      for (int i = 0; i < 3; i++) {
        System.gc();
        Thread.sleep(1000);
      }
    }
    GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(dbPath).setConfig(Neo4jTestCase.LARGE_CONFIG ).newGraphDatabase();
    importer.reIndex(graphDb, 10000, false, false);
    TestOSMImport.checkOSMLayer(graphDb, layerName);
    graphDb.shutdown();
  }
View Full Code Here

      return name + "\t" + duration;
    }
  }

  private void runTestPointSetGeoptimaIntersection(String tracePath, String dbPath, String layerName, boolean testMultiPoint) throws ParseException, IOException, XMLStreamException {
    GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(dbPath).setConfig( Neo4jTestCase.NORMAL_CONFIG ).newGraphDatabase();
    SpatialDatabaseService spatial = new SpatialDatabaseService(graphDb);
        System.out.println("Opened database with node count=" + ((GraphDatabaseAPI) graphDb).getDependencyResolver().resolveDependency(NodeManager.class).getNumberOfIdsInUse(Node.class));
    System.out.println("Searching for '"+layerName+"' in "+spatial.getLayerNames().length+" layers:");
    for(String name:spatial.getLayerNames()){
      System.out.println("\t"+name);
    }
    //OSMLayer layer = (OSMLayer) spatial.getOrCreateLayer(layerName, OSMGeometryEncoder.class, OSMLayer.class);
    Layer layer = spatial.getLayer(layerName);
    assertNotNull("Layer index should not be null", layer.getIndex());
    assertNotNull("Layer index envelope should not be null", layer.getIndex().getBoundingBox());
    Envelope bbox = Utilities.fromNeo4jToJts(layer.getIndex().getBoundingBox());
    TestOSMImport.debugEnvelope(bbox, layerName, Constants.PROP_BBOX);
    TestOSMImport.checkIndexAndFeatureCount(layer);

    HashMap<String,Performance> performances = new LinkedHashMap<String,Performance>();

    // Import the sample data of points on a path (drive test)
    ArrayList<Coordinate> coordinates = new ArrayList<Coordinate>();
    BufferedReader locations = new BufferedReader(new FileReader(tracePath));
    String line;
    Performance performance = new Performance("import");
    while ((line = locations.readLine()) != null) {
      String[] fields = line.split("\\s");
      if(fields.length>1) {
        double latitude = Double.parseDouble(fields[0]);
        double longitude = Double.parseDouble(fields[1]);
        coordinates.add(new Coordinate(longitude,latitude));
      }
    }
    locations.close();
    performance.stop(coordinates.size());
    performances.put(performance.name,performance);

    // Slow Test, iterating over all Point objects
    double distanceInKm = 0.01;
    HashSet<Node> results = new HashSet<Node>();
    System.out.println("Searching for geometries near "+coordinates.size()+" locations: " + coordinates.get(0) + " ... "
        + coordinates.get(coordinates.size() - 1));
    performance = new Performance("search points");
    try (Transaction tx = graphDb.beginTx()) {
      for (Coordinate coordinate : coordinates) {
        List<Node> res = GeoPipeline.startNearestNeighborLatLonSearch(layer, coordinate, distanceInKm)
            .sort("OrthodromicDistance").toNodeList();
        results.addAll(res);
      }
      printResults(results);
      performance.stop(results);
      tx.success();
    }
    performances.put(performance.name,performance);
    System.out.println("Point search took "+performance.duration()+" seconds to find "+results.size()+" results");

    // Faster tests with LineString and MultiPoint
    GeometryFactory geometryFactory = new GeometryFactory();
    CoordinateArraySequence cseq = new CoordinateArraySequence(coordinates.toArray(new Coordinate[0]));
    HashMap<String,Geometry> testGeoms = new LinkedHashMap<String,Geometry>();
    testGeoms.put("LineString", geometryFactory.createLineString(cseq));
    testGeoms.put("LineString.buffer(0.001)",   testGeoms.get("LineString").buffer(0.001));
    testGeoms.put("LineString.buffer(0.0001)",  testGeoms.get("LineString").buffer(0.0001));
    testGeoms.put("LineString.buffer(0.00001)",  testGeoms.get("LineString").buffer(0.00001));
    testGeoms.put("Simplified.LS.buffer(0.0001)",  TopologyPreservingSimplifier.simplify(testGeoms.get("LineString").buffer(0.0001),0.00005));
    if (testMultiPoint) {
      testGeoms.put("MultiPoint", geometryFactory.createMultiPoint(cseq));
      testGeoms.put("MultiPoint.buffer(0.001)",   testGeoms.get("MultiPoint").buffer(0.001));
      testGeoms.put("MultiPoint.buffer(0.0001)",  testGeoms.get("MultiPoint").buffer(0.0001));
      testGeoms.put("MultiPoint.buffer(0.00001)",  testGeoms.get("MultiPoint").buffer(0.00001));
      testGeoms.put("Simplified.MP.buffer(0.0001)",  TopologyPreservingSimplifier.simplify(testGeoms.get("MultiPoint").buffer(0.0001),0.00005));
    }
    for (Entry<String, Geometry> entry: testGeoms.entrySet()) {
      String gname = entry.getKey();
      Geometry geometry = entry.getValue();
      System.out.println("Searching for geometries near Geometry: " + gname);
      performance = new Performance(gname);
      try (Transaction tx = graphDb.beginTx()) {
        List<Node> res = runSearch(GeoPipeline.startIntersectSearch(layer, geometry), true);
        performance.stop(res);
        performances.put(performance.name,performance);
        System.out.println("Geometry search took " + performance.duration() + " seconds to find " + res.size() + " results");
        tx.success();
      }
    }

    // Print summary of results
    System.out.println("\nActivity\tDuration\tResults\tOverlap");
    for(Performance perf: performances.values()) {
      System.out.println(perf.name + "\t" + perf.duration() + "\t" + perf.count + "\t" + perf.overlaps(results));
    }

    // Finished
    graphDb.shutdown();
  }
View Full Code Here

    }
    String database = args[0];
    String exportdir = args[1];
    String stylefile = args[2];
    double zoom = new Double(args[3]);
    GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(database);
    try {
      StyledImageExporter imageExporter = new StyledImageExporter(db);
      imageExporter.setExportDir(exportdir);
      imageExporter.setZoom(zoom);
      imageExporter.setSize(800, 600);
      for (int i = 4; i < args.length; i++) {
        imageExporter.saveLayerImage(args[i], stylefile);
      }

    } catch (Exception e) {
      throw new RuntimeException(e);
    } finally {
      db.shutdown();
    }
  }
View Full Code Here

        assertEquals(0,IteratorUtil.count(result));
    }

    @Test
    public void testWithSeparateTransactions() throws Exception {
        final GraphDatabaseService gdb = new TestGraphDatabaseFactory().newImpermanentDatabase();
        final Thread t = new Thread() {
            @Override
            public void run() {
                final Transaction tx = gdb.beginTx();
                final Index<Node> index = gdb.index().forNodes("Test");
                assertEquals("Test", gdb.index().nodeIndexNames()[0]);
                tx.success();
                tx.close();
            }
        };
        t.start();t.join();
        Transaction tx = gdb.beginTx();
        try {
            final ExecutionResult result = new ExecutionEngine(gdb).execute("start n=node:Test('name:*') return n");
            assertEquals(0,IteratorUtil.count(result));
            assertEquals("Test", gdb.index().nodeIndexNames()[0]);
        } finally {
            tx.success();tx.close();
        }
    }
View Full Code Here

*/
public class IncludeRelationshipsTest {

    @Test
    public void shouldIncludeCorrectRelationships() {
        GraphDatabaseService database = new TestGraphDatabaseFactory().newImpermanentDatabase();

        try (Transaction tx = database.beginTx()) {
            Node n1 = database.createNode();
            Node n2 = database.createNode();
            Relationship r = n1.createRelationshipTo(n2, withName("TEST"));
            r.setProperty("test", "test");

            assertTrue(IncludeRelationships.all().include(r));
            assertTrue(IncludeRelationships.all().with(OUTGOING).include(r, n1));
View Full Code Here

*/
public class IncludeNodesTest {

    @Test
    public void shouldIncludeCorrectRelationships() {
        GraphDatabaseService database = new TestGraphDatabaseFactory().newImpermanentDatabase();

        try (Transaction tx = database.beginTx()) {
            Node n = database.createNode(label("Test"));
            n.setProperty("test", "test");

            assertTrue(IncludeNodes.all().include(n));
            assertTrue(IncludeNodes.all().with("Test").include(n));
            assertFalse(IncludeNodes.all().with(label("Test2")).include(n));
View Full Code Here

        }
    }

    @Test
    public void testRandom() {
        GraphDatabaseService database = new TestGraphDatabaseFactory().newImpermanentDatabase();

        try (Transaction tx = database.beginTx()) {
            database.createNode();
            tx.success();
        }

        try (Transaction tx = database.beginTx()) {
            assertTrue(asList(0L, 1L).contains(random(at(database).getAllNodes()).getId()));
            assertTrue(asList(0L, 1L).contains(random(at(database).getAllNodes()).getId()));
            assertTrue(asList(0L, 1L).contains(random(at(database).getAllNodes()).getId()));
            assertTrue(asList(0L, 1L).contains(random(at(database).getAllNodes()).getId()));
            assertTrue(asList(0L, 1L).contains(random(at(database).getAllNodes()).getId()));
View Full Code Here

* Only for documentation. If you need to change this class, change the code in README.md as well please.
*/
public class JustForDocs {

    private void justForDocs() {
        GraphDatabaseService database = new TestGraphDatabaseFactory().newImpermanentDatabase();
        database.registerTransactionEventHandler(new TransactionEventHandler<Object>() {
            @Override
            public Object beforeCommit(TransactionData data) throws Exception {
                ImprovedTransactionData improvedTransactionData = new LazyTransactionData(data);

                //have fun here with improvedTransactionData!
View Full Code Here

            }
        });
    }

    private void justForDocs2() {
        GraphDatabaseService database = new TestGraphDatabaseFactory().newImpermanentDatabase();
        database.registerTransactionEventHandler(new TransactionEventHandler.Adapter<Object>() {
            @Override
            public Object beforeCommit(TransactionData data) throws Exception {
                InclusionPolicies inclusionPolicies = InclusionPolicies.all()
                        .with(new NodeInclusionPolicy() {
                            @Override
View Full Code Here

TOP

Related Classes of org.neo4j.graphdb.GraphDatabaseService

Copyright © 2018 www.massapicom. 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.