Package com.tinkerpop.blueprints.impls.neo4j2

Examples of com.tinkerpop.blueprints.impls.neo4j2.Neo4j2Graph


        batch.flushIndices();
        batch.shutdown();

        // native neo4j graph load

        Neo4j2Graph graph = new Neo4j2Graph(directory);
        graph.autoStartTransaction(true);
        Iterator<Vertex> itty = graph.getIndex("testIdx", Vertex.class).query("name", "*rko").iterator();
        int counter = 0;
        while (itty.hasNext()) {
            counter++;
            assertEquals(itty.next().getProperty("name"), "marko");
        }
        assertEquals(counter, 1);

        itty = graph.getIndex("testIdx", Vertex.class).query("name", "MaRkO").iterator();
        counter = 0;
        while (itty.hasNext()) {
            counter++;
            assertEquals(itty.next().getProperty("name"), "marko");
        }
        assertEquals(counter, 1);

        graph.shutdown();
    }
View Full Code Here


        }
        batch.shutdown();

        // native neo4j graph load

        final Neo4j2Graph graph = new Neo4j2Graph(directory);
        graph.autoStartTransaction(true);
        assertEquals(count(graph.getVertices()), 10);

        assertEquals(count(graph.getEdges()), 9);
        for (final Edge edge : graph.getEdges()) {
            long idA = (Long) edge.getVertex(Direction.OUT).getId();
            long idB = (Long) edge.getVertex(Direction.IN).getId();
            assertEquals(idA + 1, idB);
            assertEquals(edge.getLabel(), idA + "-" + idB);
        }

        assertNotNull(graph.getVertex(1L));
        assertNull(graph.getVertex(100L));
        assertNull(graph.getEdge(100L));
        graph.shutdown();
    }
View Full Code Here

        assertNull(batch.getVertex(200000L));
        batch.shutdown();

        // native neo4j graph load

        final Neo4j2Graph graph = new Neo4j2Graph(directory);
        graph.autoStartTransaction(true);
        assertEquals(count(graph.getVertices()), ids.size());
        for (final Long id : ids) {
            assertNotNull(graph.getVertex(id));
            assertEquals(graph.getVertex(id).getProperty("theKey"), id);
            assertEquals(graph.getVertex(id).getPropertyKeys().size(), 1);
        }
        assertNull(graph.getVertex(1L));
        assertNull(graph.getVertex(2L));
        assertNull(graph.getVertex(200000L));
        graph.shutdown();
    }
View Full Code Here

        assertNull(batch.getVertex(200000L));
        batch.shutdown();

        // native neo4j graph load

        final Neo4j2Graph graph = new Neo4j2Graph(directory);
        graph.autoStartTransaction(true);
        assertEquals(count(graph.getVertices()), ids.size());
        assertNotNull(graph.getVertex(100l));
        assertNotNull(graph.getVertex(5l));
        assertNotNull(graph.getVertex(10l));
        assertNotNull(graph.getVertex(4l));
        assertNotNull(graph.getVertex(10000));

        graph.shutdown();

    }
View Full Code Here

        batch.flushIndices();
        batch.shutdown();

        // native neo4j graph load

        final Neo4j2Graph graph = new Neo4j2Graph(directory);
        graph.autoStartTransaction(true);

        assertEquals(count(graph.getIndices()), 1);

        assertEquals(graph.getIndexedKeys(Vertex.class).size(), 2);
        assertTrue(graph.getIndexedKeys(Vertex.class).contains("name"));
        assertTrue(graph.getIndexedKeys(Vertex.class).contains("age"));
        edgeIndex = graph.getIndex("edgeIdx", Edge.class);
        assertEquals(edgeIndex.getIndexClass(), Edge.class);

        assertEquals(count(graph.getVertices()), 10);

        assertTrue(graph.getVertices("nothing", 0) instanceof PropertyFilteredIterable);
        assertTrue(graph.getVertices("blah", "blop") instanceof PropertyFilteredIterable);
        assertFalse(graph.getVertices("name", "marko") instanceof PropertyFilteredIterable); // key index used
        assertFalse(graph.getVertices("age", 32) instanceof PropertyFilteredIterable); // key indexed used

        for (final Vertex vertex : graph.getVertices()) {
            int age = (Integer) vertex.getProperty("age");
            assertEquals(vertex.getProperty("name"), (age / 10) + "");

            assertTrue(graph.getVertices("nothing", 0).iterator().hasNext());
            assertEquals(count(graph.getVertices("age", age)), 1);
            assertEquals(graph.getVertices("age", age).iterator().next(), vertex);
            assertEquals(count(graph.getVertices("name", (age / 10) + "")), 1);
            assertEquals(graph.getVertices("name", (age / 10) + "").iterator().next(), vertex);
            assertEquals(vertex.getPropertyKeys().size(), 3);
            vertex.setProperty("NEW", age);
            assertEquals(vertex.getPropertyKeys().size(), 4);
        }

        for (final Vertex vertex : graph.getVertices()) {
            int age = (Integer) vertex.getProperty("age");
            assertEquals(vertex.getProperty("NEW"), age);
            assertEquals(vertex.getPropertyKeys().size(), 4);
            vertex.removeProperty("NEW");
        }

        for (final Vertex vertex : graph.getVertices()) {
            assertNull(vertex.getProperty("NEW"));
            assertEquals(vertex.getPropertyKeys().size(), 3);
        }

        assertEquals(count(graph.getEdges()), 9);
        assertEquals(count(edgeIndex.get("full", "blah")), 9);
        Set<Edge> edges = new HashSet<Edge>();
        for (Edge edge : edgeIndex.get("full", "blah")) {
            edges.add(edge);
        }
        assertEquals(edges.size(), 9);
        for (final Edge edge : graph.getEdges()) {
            long idA = (Long) edge.getVertex(Direction.OUT).getId();
            long idB = (Long) edge.getVertex(Direction.IN).getId();
            assertEquals(idA + 1, idB);
            assertEquals(edge.getLabel(), idA + "-" + idB);
            assertEquals(edge.getPropertyKeys().size(), 1);
            assertEquals(edge.getProperty("weight"), 0.5f);

            assertEquals(edgeIndex.count("weight", 0.5f), 0);
            assertEquals(edgeIndex.count("unique", idA + "-" + idB), 1);
            assertEquals(edgeIndex.get("unique", idA + "-" + idB).iterator().next(), edge);
            assertTrue(edges.contains(edge));
        }

        graph.shutdown();
    }
View Full Code Here

        batch.shutdown();

        // native neo4j graph load

        Neo4j2Graph graph = new Neo4j2Graph(directory);
        graph.autoStartTransaction(true);
        assertEquals(count(graph.getVertices()), 10);
        for (final Long id : vertexIds) {
            Vertex vertex = graph.getVertex(id);
            assertNull(vertex.getProperty("a"));
            assertEquals(vertex.getProperty("b"), 3);
            assertEquals(vertex.getProperty("c"), 4);
            assertEquals(vertex.getPropertyKeys().size(), 2);
        }

        for (final Long id : edgeIds) {
            Edge edge = graph.getEdge(id);
            assertNull(edge.getProperty("blah"));
            assertEquals(edge.getPropertyKeys().size(), 1);
            assertEquals(edge.getProperty("weight"), 0.5);
        }
        graph.shutdown();

    }
View Full Code Here

        assertEquals(batch.getVertex(6).getProperty("name"), "peter");
        batch.shutdown();

        // native neo4j graph load

        Neo4j2Graph graph = new Neo4j2Graph(directory);
        graph.autoStartTransaction(true);
        assertEquals(count(graph.getVertices()), 6);
        assertEquals(count(graph.getEdges()), 6);
        assertEquals(count(graph.getVertex("1").getEdges(Direction.OUT)), 3);
        assertEquals(count(graph.getVertex("1").getEdges(Direction.IN)), 0);
        Vertex marko = graph.getVertex("1");
        assertEquals(marko.getProperty("name"), "marko");
        assertEquals(marko.getProperty("age"), 29);
        int counter = 0;

        assertEquals(count(graph.getVertex("4").getEdges(Direction.OUT)), 2);
        assertEquals(count(graph.getVertex("4").getEdges(Direction.IN)), 1);
        Vertex josh = graph.getVertex("4");
        assertEquals(josh.getProperty("name"), "josh");
        assertEquals(josh.getProperty("age"), 32);
        for (Edge e : graph.getVertex("4").getEdges(Direction.OUT)) {
            if (e.getVertex(Direction.IN).getId().equals(3l)) {
                assertEquals(Math.round((Float) e.getProperty("weight")), 0);
                assertEquals(e.getLabel(), "created");
                counter++;
            } else if (e.getVertex(Direction.IN).getId().equals(5l)) {
                assertEquals(Math.round((Float) e.getProperty("weight")), 1);
                assertEquals(e.getLabel(), "created");
                counter++;
            }
        }
        assertEquals(counter, 2);
        graph.shutdown();
    }
View Full Code Here

                }

                return new Neo4j2HaGraph(graphFile, neo4jProperties);

            } else {
                return new Neo4j2Graph(graphFile, neo4jProperties);
            }

        } catch (GraphConfigurationException gce) {
            throw gce;
        } catch (Exception ex) {
View Full Code Here

                if (!neo4jProperties.containsKey("ha.initial_hosts")) {
                    throw new GraphConfigurationException("Check graph configuration. Neo4j HA requires [ha.initial_hosts] <properties> of the configuration");
                }

                return new Neo4j2HaGraph(graphFile, neo4jProperties);

            } else {
                return new Neo4j2Graph(graphFile, neo4jProperties);
            }
View Full Code Here

TOP

Related Classes of com.tinkerpop.blueprints.impls.neo4j2.Neo4j2Graph

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.